Browse Source

[ZF-9202] Zend_Filter:

- change options handling to allow extension (thnx Ramon for tests)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21085 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 năm trước cách đây
mục cha
commit
cdd2f64686
2 tập tin đã thay đổi với 25 bổ sung2 xóa
  1. 7 2
      library/Zend/Filter/PregReplace.php
  2. 18 0
      tests/Zend/Filter/PregReplaceTest.php

+ 7 - 2
library/Zend/Filter/PregReplace.php

@@ -89,11 +89,16 @@ class Zend_Filter_PregReplace implements Zend_Filter_Interface
         if ($options instanceof Zend_Config) {
             $options = $options->toArray();
         } else if (!is_array($options)) {
-            $options       = func_get_args();
-            $temp['match'] = array_shift($options);
+            $options = func_get_args();
+            $temp    = array();
+            if (!empty($options)) {
+                $temp['match'] = array_shift($options);
+            }
+
             if (!empty($options)) {
                 $temp['replace'] = array_shift($options);
             }
+
             $options = $temp;
         }
 

+ 18 - 0
tests/Zend/Filter/PregReplaceTest.php

@@ -130,6 +130,24 @@ class Zend_Filter_PregReplaceTest extends PHPUnit_Framework_TestCase
         } catch (Exception $e) {
         }
     }
+
+    /**
+      * @group ZF-9202
+      */
+    public function testExtendsPregReplace()
+    {
+        $startMatchPattern = '~(>){3,}~i';
+        $filter = new XPregReplace();
+        $this->assertEquals($startMatchPattern, $filter->getMatchPattern());
+    }
+}
+
+/**
+ * @group ZF-9202
+ */
+class XPregReplace extends Zend_Filter_PregReplace
+{
+    protected $_matchPattern = '~(>){3,}~i';
 }
 
 // Call Zend_Filter_PregReplaceTest::main() if this source file is executed directly.