[Solar-svn] Revision 2638

pmjones at solarphp.com pmjones at solarphp.com
Fri Jul 27 16:13:55 CDT 2007


Branch: Solar_Filter: [ADD] Now uses a class stack for filters, like Solar_View does with Helper classes.


Modified: branches/orm/Solar/Filter.php
===================================================================
--- branches/orm/Solar/Filter.php	2007-07-27 20:54:54 UTC (rev 2637)
+++ branches/orm/Solar/Filter.php	2007-07-27 21:13:55 UTC (rev 2638)
@@ -1,7 +1,7 @@
 <?php
 /**
  * 
- * Methods for validating and sanitizing user input.
+ * Handler for validating and sanitizing user input.
  * 
  * @category Solar
  * 
@@ -19,8 +19,10 @@
 
 /**
  * 
- * Methods for validating and sanitizing user input.
+ * Handler for validating and sanitizing user input.
  * 
+ * Includes one-off filtering as well as filter chains for flat data arrays.
+ * 
  * @category Solar
  * 
  * @package Solar_Filter
@@ -145,36 +147,32 @@
      */
     protected $_require = true;
     
-    protected $_stack;
-    
     /**
      * 
-     * Sets the value of the 'require' flag.
+     * Class stack for finding filters.
      * 
-     * @param bool $flag Turn 'require' on (true) or off (false).
+     * @var Solar_Class_Stack
      * 
-     * @return void
-     * 
-     * @see $_require
-     * 
      */
-    public function setRequire($flag)
-    {
-        $this->_require = (bool) $flag;
-    }
+    protected $_stack;
     
     /**
      * 
-     * Returns the value of the 'require' flag.
+     * Constructor.
      * 
-     * @return bool
+     * @param array $config User-provided configuration values.
      * 
-     * @see $_require
-     * 
      */
-    public function getRequire()
+    public function __construct($config = null)
     {
-        return $this->_require;
+        parent::__construct($config);
+        
+        // build the filter class stack
+        $this->_stack = Solar::factory('Solar_Class_Stack');
+        $this->setFilterClass();
+        
+        // extended setup
+        $this->_setup();
     }
     
     /**
@@ -200,6 +198,55 @@
     
     /**
      * 
+     * Reset the filter class stack.
+     * 
+     * @param string|array $list The classes to set for the stack.
+     * 
+     * @return void
+     * 
+     * @see Solar_Class_Stack::set()
+     * 
+     * @see Solar_Class_Stack::add()
+     * 
+     */
+    public function setFilterClass($list = null)
+    {
+        $this->_stack->set('Solar_Filter');
+        $this->_stack->add($list);
+    }
+    
+    /**
+     * 
+     * Add to the filter class stack.
+     * 
+     * @param string|array $list The classes to add to the stack.
+     * 
+     * @return void
+     * 
+     * @see Solar_Class_Stack::add()
+     * 
+     */
+    public function addFilterClass($list)
+    {
+        $this->_stack->add($list);
+    }
+    
+    /**
+     * 
+     * Returns the filter class stack.
+     * 
+     * @return array The stack of filter classes.
+     * 
+     * @see Solar_Class_Stack::get()
+     * 
+     */
+    public function getFilterClass()
+    {
+        return $this->_stack->get();
+    }
+    
+    /**
+     * 
      * Gets the stored filter object by method name.
      * 
      * Creates the filter object if it does not already exist.
@@ -229,13 +276,44 @@
      */
     public function newFilter($method)
     {
-        $class = "Solar_Filter_" . ucfirst($method);
+        $method[0] = strtolower($method[0]);
+        $class = $this->_stack->load($method);
         $obj = Solar::factory($class, array('filter' => $this));
         return $obj;
     }
     
     /**
      * 
+     * Sets the value of the 'require' flag.
+     * 
+     * @param bool $flag Turn 'require' on (true) or off (false).
+     * 
+     * @return void
+     * 
+     * @see $_require
+     * 
+     */
+    public function setRequire($flag)
+    {
+        $this->_require = (bool) $flag;
+    }
+    
+    /**
+     * 
+     * Returns the value of the 'require' flag.
+     * 
+     * @return bool
+     * 
+     * @see $_require
+     * 
+     */
+    public function getRequire()
+    {
+        return $this->_require;
+    }
+    
+    /**
+     * 
      * Sets the object used for getting locale() translations during
      * [[applyChain()]].
      * 
@@ -545,4 +623,15 @@
         // done
         return $msg;
     }
+    
+    /**
+     * 
+     * Allows specialized setup for extended classes.
+     * 
+     * @return void
+     * 
+     */
+    protected function _setup()
+    {
+    }
 }




More information about the Solar-svn mailing list