Browse Source

[ZF-2105] Zend_Filter:

- better naming of Zend_Filter::get() to Zend_Filter::staticFilter

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17073 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 years ago
parent
commit
4de40c6907

+ 26 - 0
documentation/manual/en/module_specs/Zend_Filter-Migration.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect1 id="zend.filter.migration">
+    <title>Migrating from Previous Versions</title>
+
+    <para>
+        This chapter documents primarily backwards compatibility breaks made in
+        <classname>Zend_Filter</classname>, and should serve to aid in migration from previous
+        versions.
+    </para>
+
+    <sect2 id="zend.filter.migration.zf2105">
+        <title>Migrating from versions prior to 1.9</title>
+
+        <para>
+            Prior to the 1.9 release, <classname>Zend_Filter</classname> allowed
+            the usage of the static <methodname>get()</methodname> method. As with
+            release 1.9 this method has been renamed to
+            <methodname>filterStatic()</methodname> to be more descriptive. The
+            old <methodname>get()</methodname> method is marked as depreciated.
+        </para>
+    </sect2>
+</sect1>
+<!--
+vim:se ts=4 sw=4 et:
+-->

+ 9 - 9
documentation/manual/en/module_specs/Zend_Filter.xml

@@ -80,7 +80,7 @@ echo $htmlEntities->filter('"'); // &quot;
         <para>
             If it is inconvenient to load a given filter class and create an
             instance of the filter, you can use the static method
-            <classname>Zend_Filter::get()</classname> as an alternative invocation style.
+            <classname>Zend_Filter::filterStatic()</classname> as an alternative invocation style.
             The first argument of this method is a data input value, that you
             would pass to the <code>filter()</code> method. The second
             argument is a string, which corresponds to the basename of the
@@ -90,7 +90,7 @@ echo $htmlEntities->filter('"'); // &quot;
             input.
 
             <programlisting language="php"><![CDATA[
-echo Zend_Filter::get('&', 'HtmlEntities');
+echo Zend_Filter::filterStatic('&', 'HtmlEntities');
 ]]></programlisting>
 
         </para>
@@ -100,7 +100,7 @@ echo Zend_Filter::get('&', 'HtmlEntities');
             are needed for the filter class.
 
             <programlisting language="php"><![CDATA[
-echo Zend_Filter::get('"', 'HtmlEntities', array(ENT_QUOTES));
+echo Zend_Filter::filterStatic('"', 'HtmlEntities', array(ENT_QUOTES));
 ]]></programlisting>
 
         </para>
@@ -125,12 +125,12 @@ echo Zend_Filter::get('"', 'HtmlEntities', array(ENT_QUOTES));
 
             <para>
                 When working with self defined filters you can give a forth parameter
-                to <methodname>Zend_Filter::get()</methodname> which is the namespace
+                to <methodname>Zend_Filter::filterStatic()</methodname> which is the namespace
                 where your filter can be found.
             </para>
 
             <programlisting language="php"><![CDATA[
-echo Zend_Filter::get(
+echo Zend_Filter::filterStatic(
     '"',
     'MyFilter',
     array($parameters),
@@ -141,14 +141,14 @@ echo Zend_Filter::get(
             <para>
                 <classname>Zend_Filter</classname> allows also to set namespaces as default.
                 This means that you can set them once in your bootstrap and have not to give
-                them again for each call of <methodname>Zend_Filter::get()</methodname>. The
-                following code snippet is identical to the above one.
+                them again for each call of <methodname>Zend_Filter::filterStatic()</methodname>.
+                The following code snippet is identical to the above one.
             </para>
 
             <programlisting language="php"><![CDATA[
 Zend_Filter::setDefaultNamespaces(array('FirstNamespace', 'SecondNamespace'));
-echo Zend_Filter::get('"', 'MyFilter', array($parameters));
-echo Zend_Filter::get('"', 'OtherFilter', array($parameters));
+echo Zend_Filter::filterStatic('"', 'MyFilter', array($parameters));
+echo Zend_Filter::filterStatic('"', 'OtherFilter', array($parameters));
 ]]></programlisting>
 
             <para>

+ 22 - 2
library/Zend/Filter.php

@@ -126,6 +126,27 @@ class Zend_Filter implements Zend_Filter_Interface
     }
 
     /**
+     * @deprecated
+     * @see Zend_Filter::filterStatic()
+     *
+     * @param  mixed        $value
+     * @param  string       $classBaseName
+     * @param  array        $args          OPTIONAL
+     * @param  array|string $namespaces    OPTIONAL
+     * @return mixed
+     * @throws Zend_Filter_Exception
+     */
+    public static function get($value, $classBaseName, array $args = array(), $namespaces = array())
+    {
+        trigger_error(
+            'Zend_Filter::get() is deprecated as of 1.9.0; please update your code to utilize Zend_Filter::filterStatic()',
+            E_USER_NOTICE
+        );
+
+        return self::filterStatic($value, $classBaseName, $args, $namespaces);
+    }
+
+    /**
      * Returns a value filtered through a specified filter class, without requiring separate
      * instantiation of the filter object.
      *
@@ -142,7 +163,7 @@ class Zend_Filter implements Zend_Filter_Interface
      * @return mixed
      * @throws Zend_Filter_Exception
      */
-    public static function get($value, $classBaseName, array $args = array(), $namespaces = array())
+    public static function filterStatic($value, $classBaseName, array $args = array(), $namespaces = array())
     {
         require_once 'Zend/Loader.php';
         $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Filter'));
@@ -150,7 +171,6 @@ class Zend_Filter implements Zend_Filter_Interface
             $className = $namespace . '_' . ucfirst($classBaseName);
             if (!class_exists($className)) {
                 try {
-                    require_once 'Zend/Loader.php';
                     Zend_Loader::loadClass($className);
                 } catch (Zend_Exception $ze) {
                     continue;

+ 30 - 4
tests/Zend/FilterTest.php

@@ -101,7 +101,7 @@ class Zend_FilterTest extends PHPUnit_Framework_TestCase
      */
     public function testStaticFactory()
     {
-        $filteredValue = Zend_Filter::get('1a2b3c4d', 'Digits');
+        $filteredValue = Zend_Filter::filterStatic('1a2b3c4d', 'Digits');
         $this->assertEquals('1234', $filteredValue);
     }
 
@@ -112,13 +112,13 @@ class Zend_FilterTest extends PHPUnit_Framework_TestCase
     public function testStaticFactoryWithConstructorArguments()
     {
         // Test HtmlEntities with one ctor argument.
-        $filteredValue = Zend_Filter::get('"O\'Reilly"', 'HtmlEntities', array(array('quotestyle' => ENT_COMPAT)));
+        $filteredValue = Zend_Filter::filterStatic('"O\'Reilly"', 'HtmlEntities', array(array('quotestyle' => ENT_COMPAT)));
         $this->assertEquals('&quot;O\'Reilly&quot;', $filteredValue);
 
         // Test HtmlEntities with a different ctor argument,
         // and make sure it gives the correct response
         // so we know it passed the arg to the ctor.
-        $filteredValue = Zend_Filter::get('"O\'Reilly"', 'HtmlEntities', array(array('quotestyle' => ENT_QUOTES)));
+        $filteredValue = Zend_Filter::filterStatic('"O\'Reilly"', 'HtmlEntities', array(array('quotestyle' => ENT_QUOTES)));
         $this->assertEquals('&quot;O&#039;Reilly&quot;', $filteredValue);
     }
 
@@ -135,7 +135,7 @@ class Zend_FilterTest extends PHPUnit_Framework_TestCase
     {
         set_error_handler(array($this, 'handleNotFoundError'), E_WARNING);
         try {
-            Zend_Filter::get('1234', 'UnknownFilter');
+            Zend_Filter::filterStatic('1234', 'UnknownFilter');
         } catch (Zend_Filter_Exception $e) {
         }
         restore_error_handler();
@@ -190,6 +190,32 @@ class Zend_FilterTest extends PHPUnit_Framework_TestCase
 
         Zend_Filter::setDefaultNamespaces(array());
     }
+
+    /**
+     * ZF-2105
+     */
+    public function testUsageOfOldStaticFactory()
+    {
+        set_error_handler(array($this, 'errorHandlerIgnore'));
+        $filteredValue = Zend_Filter::get('1a2b3c4d', 'Digits');
+        $this->assertEquals('1234', $filteredValue);
+        restore_error_handler();
+    }
+
+    /**
+     * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
+     *
+     * @param  integer $errno
+     * @param  string  $errstr
+     * @param  string  $errfile
+     * @param  integer $errline
+     * @param  array   $errcontext
+     * @return void
+     */
+    public function errorHandlerIgnore($errno, $errstr, $errfile, $errline, array $errcontext)
+    {
+        $this->_errorOccurred = true;
+    }
 }