KumbiaPHP beta2-dev
Framework PHP en español
filter.php
Ir a la documentación de este archivo.
00001 <?php
00026 require_once CORE_PATH . 'libs/filter/filter_interface.php';
00027  
00036 class Filter
00037 {
00046     public static function get ($s, $filter, $options=array())
00047     {
00048                 if(is_string($options)) {
00049                         $filters = func_get_args();
00050             unset($filters[0]);
00051             
00052             $options = array();
00053                         foreach($filters as $f) {
00054                 $filter_class = Util::camelcase($f).'Filter';
00055                 if(!class_exists($filter_class, false)) {
00056                     self::_load_filter($f);
00057                 }
00058                 
00059                 $s = call_user_func(array($filter_class, 'execute'), $s, $options);
00060             }
00061                 } else {
00062             $filter_class = Util::camelcase($filter).'Filter';
00063             if(!class_exists($filter_class, false)) {
00064                 self::_load_filter($filter);
00065             }
00066             $s = call_user_func(array($filter_class, 'execute'), $s, $options);
00067                 }
00068         
00069         return $s;
00070     }
00071     
00080     public static function get_array($array, $filter, $options=array()) 
00081     {
00082         $args = func_get_args();
00083 
00084         foreach($array as $k => $v) {
00085             $args[0] = $v;
00086             $array[$k] = call_user_func_array(array('self', 'get'), $args);
00087         }
00088         
00089         return $array;
00090     }
00091     
00099     public static function get_object($object, $filter, $options=array())
00100     {
00101         $args = func_get_args();
00102 
00103         foreach($object as $k => $v) {
00104             $args[0] = $v;
00105             $object->$k = call_user_func_array(array('self', 'get'), $args);
00106         }
00107         
00108         return $object;
00109     }
00116         protected static function _load_filter($filter)
00117         {
00118                 $file = APP_PATH . "extensions/filters/{$filter}_filter.php";
00119                 if(!is_file($file)) {
00120                         $file = CORE_PATH . "libs/filter/base_filter/{$filter}_filter.php";
00121                         if(!is_file($file)) {
00122                                 throw new KumbiaException("Filtro $filter no encontrado");
00123                         }
00124                 }
00125         
00126         include $file;
00127         }
00128 }
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Enumeraciones