Source for file Filter.class.php

Documentation is available at Filter.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Filter
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Filter Class
  22.  * 
  23.  * This class is responsible for loading the appropriate Filter object.  The name
  24.  * given must be a Gumbo_Interface_Filter, otherwise the returned value will be
  25.  * the Blank Filter.  The Blank Filter simply returns the data given.  If the
  26.  * name given is not a class, the Factory will attempt to search for a Gumbo_Filter_*
  27.  * class.  Since the Factory will always return a Filter object, it can used as:
  28.  * <pre>
  29.  * $data = $fact->factory ("Tags", ... )->run ($data);
  30.  * </pre>
  31.  *
  32.  * @category Gumbo
  33.  * @package Filter
  34.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  35.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  36.  * @author Michael Luster <mluster79@yahoo.com>
  37.  * @link http://sourceforge.net/projects/phpgumbo
  38.  * @desc Filter Class
  39.  * @version 0.0.1
  40.  */
  41.  
  42. gumbo_load ("Factory");
  43. gumbo_load ("Filter_Blank");
  44.  
  45. class Gumbo_Filter extends Gumbo_Factory {
  46.     
  47.     /** ACTION METHODS **/
  48.     /**
  49.      * Returns an instantiated object (accepts Constructor arguments)
  50.      * @param string $name name of Class or key string
  51.      * @param mixed $args additional arguments
  52.      * @return Gumbo_Interface_Filter 
  53.      * @throws Gumbo_Exception
  54.      * @uses Gumbo_Filter_Blank
  55.      */
  56.     public function factory ($name=null$args=null{
  57.         try {
  58.             // prepend Gumbo_Filter_ if class does not exist
  59.             if (is_string ($name&& !class_exists ($namefalse)) {
  60.                 $name "Gumbo_Filter_" ucfirst (str_replace ("Gumbo_Filter_"""$name));
  61.             }
  62.             
  63.             $args array ();
  64.             $args [$name;
  65.             foreach (func_get_args (as $key=>$val{
  66.                 if ($key == 0continue}
  67.                 $args [$val;
  68.             }
  69.             
  70.             $obj call_user_func_array (array ("parent""factory")$args);
  71.             
  72.             if (!($obj instanceof Gumbo_Interface_Filter)) {
  73.                 throw new Gumbo_Exception ("Invalid Filter: " get_class ($obj));
  74.             }
  75.             
  76.             return $obj;
  77.         catch (Gumbo_Exception $e{
  78.             $e->setFunction (__METHOD__);
  79.             gumbo_trigger ($e);
  80.         }
  81.         return new Gumbo_Filter_Blank ();
  82.     }
  83.     
  84. }
  85.  
  86. ?>