示例#1
0
文件: Model.php 项目: Naatan/CrossORM
 private function prepare_fields()
 {
     $this->fields = Helpers::objectify($this->fields);
     $dynamic_methods = array_merge($this->_dynamic_methods, $this->dynamic_methods);
     foreach ($this->fields as $field => $data) {
         foreach ($dynamic_methods as $method => $hook) {
             $method = str_replace('%field%', $field, $method);
             $this->_method_hooks[$method] = (object) array('field' => $field, 'args' => $hook);
         }
     }
 }
示例#2
0
文件: ACL.php 项目: Naatan/CrossORM
 /**
  * Convert an flattened array to a properly structured object
  *
  * @param   array|string            $array
  * @return  object
  */
 private static function _objectify_strings($array)
 {
     $result = array();
     if (!is_array($array)) {
         $array = array($array);
     }
     foreach ($array as $string) {
         $bits = explode('.', $string);
         $schema = '';
         $parent =& $result;
         for ($x = 0; $x < count($bits); $x++) {
             $bit = $bits[$x];
             switch ($schema) {
                 case 'string':
                     $parent[] = $bit;
                     $bit = count($parent) - 1;
                     break;
                 case 'array':
                     $parent = array_merge_recursive($parent, array($bit => array()));
                     break;
                 default:
                     $parent[$bit] = array();
                     break;
             }
             $schema = '';
             if (isset(static::$_schemas[$x + 1]) and isset(static::$_schemas[$x + 1][$bit])) {
                 $schema = static::$_schemas[$x + 1][$bit];
             }
             if (isset($parent[$bit]) and is_array($parent[$bit])) {
                 $parent =& $parent[$bit];
             }
         }
     }
     return Helpers::objectify($result);
 }