Exemplo n.º 1
0
 public function getConfig($searched_action = null)
 {
     if ($searched_action === true) {
         $searched_action = fx::util()->camelToUnderscore($this->action);
     }
     if (!is_null($this->_config_cache)) {
         return $searched_action ? $this->_config_cache['actions'][$searched_action] : $this->_config_cache;
     }
     $sources = $this->getConfigSources();
     $actions = $this->getRealActions();
     $blocks = array();
     $meta = array();
     $my_name = $this->getControllerName();
     foreach ($sources as $src) {
         $src_hash = md5($src);
         $is_own = $my_name && fx::getComponentFullNameByPath(fx::path()->http($src)) === $my_name;
         $src = (include $src);
         if (!isset($src['actions'])) {
             continue;
         }
         $src_actions = $this->prepareActionConfig($src['actions']);
         foreach ($src_actions as $k => $props) {
             $action_codes = preg_split("~\\s*,\\s*~", $k);
             foreach ($action_codes as $ak) {
                 $inherit_vertical = preg_match("~^\\*~", $ak);
                 // parent blocks without vertical inheritance does not use
                 if (!$is_own && !$inherit_vertical) {
                     continue;
                 }
                 $inherit_horizontal = preg_match("~\\*\$~", $ak);
                 $action_code = trim($ak, '*');
                 foreach (array('install', 'delete', 'save') as $cb_name) {
                     if (isset($props[$cb_name])) {
                         if (!is_array($props[$cb_name]) || is_callable($props[$cb_name])) {
                             $props[$cb_name] = array($src_hash => $props[$cb_name]);
                         }
                     }
                 }
                 $blocks[] = $props;
                 $meta[] = array($inherit_horizontal, $action_code);
                 if (!isset($actions[$action_code])) {
                     $actions[$action_code] = array();
                 }
             }
         }
     }
     foreach ($blocks as $bn => $block) {
         list($inherit, $bk) = $meta[$bn];
         foreach ($actions as $ak => &$action_props) {
             if ($ak === $bk || $inherit && ($bk === '.' || substr($ak, 0, strlen($bk)) === $bk)) {
                 $action_props = array_replace_recursive($action_props, $block);
                 if (isset($action_props['settings'])) {
                     foreach ($action_props['settings'] as $s_key => $s) {
                         if (is_array($s) && !isset($s['name'])) {
                             $action_props['settings'][$s_key]['name'] = $s_key;
                         }
                     }
                 }
             }
         }
     }
     foreach ($actions as $action => &$action_props) {
         $action_name = fx::util()->underscoreToCamel($action);
         $settings_method = 'settings' . $action_name;
         if (method_exists($this, $settings_method)) {
             $action_props['settings'] = call_user_func(array($this, $settings_method), isset($action_props['settings']) ? $action_props['settings'] : array());
         }
         $config_method = 'config' . $action_name;
         if (method_exists($this, $config_method)) {
             $action_props = call_user_func(array($this, $config_method), $action_props);
         }
     }
     unset($actions['.']);
     $this->_config_cache = array('actions' => $actions);
     return $searched_action ? $actions[$searched_action] : $this->_config_cache;
 }