/** * Add a command * * Disable the tabbar only for singular views that are editable. * * @param string The command name * @param mixed Parameters to be passed to the command * @return Library\ControllerToolbarCommand */ public function addCommand($name, $config = array()) { $command = parent::addCommand($name, $config); $controller = $this->getController(); if ($controller->isEditable() && Library\StringInflector::isSingular($controller->getView()->getName())) { $command->disabled = true; } return $command; }
/** * Loads the routes for a specific component * * @param Library\ObjectIdentifier $identifier * @param $path * @throws */ protected function loadComponentRoutes(Library\ObjectIdentifier $identifier, $path) { $component = $identifier->package; //Skip core components if (in_array($component, array('application', 'router'))) { return; } //If a router already exists, skip if (file_exists($path . '/router.php')) { return; } //Check for routes php or json if ($files = glob($path . '/routes.php', GLOB_BRACE)) { foreach ($files as $file) { $routes = (include_once $file); if ($routes) { foreach ($routes as $route => $options) { //Setup options if (!is_array($options)) { parse_str($options, $params); $options = array(); } else { if (isset($options['params'])) { $params = $options['params']; unset($options['params']); } else { $params = $options; } } //Set the component by default if (!isset($params['component'])) { $params['component'] = $component; } //Connect the route self::connect($route, $params, $options); } } } } else { if ($this->_auto_create_routes) { //Ensure component is dispatchable if (!$this->isComponentDispatchable($identifier)) { return; } /** * Register some default routes. * 1 of 2+ routes are registered: * component/views <- plural views * component/view/id <- singular views * * Model states are used to generate the component/view/X routes **/ $views = glob($path . '/view/*', GLOB_ONLYDIR); if (empty($views)) { return; } //Connect the base component route $this->connect($component); //Connect views foreach ($views as &$view_path) { $view = basename($view_path); $singular = Library\StringInflector::isSingular($view); $states = $singular ? $this->getComponentViewStates($identifier, $view) : array(); //If view is the name of component, just add /component if ($view == $component) { $this->connect($component, array('component' => $component, 'view' => $view)); } else { //Singular views have identifiers if ($singular) { foreach ($states as $name => $regex) { $this->connect($component . '/' . $view . '/{:' . $name . ':' . $regex . '}', array('component' => $component, 'view' => $view, $name => null)); } } else { $this->connect($component . '/' . $view, array('component' => $component, 'view' => $view)); } } $layouts = glob($view_path . '/templates/*.php'); foreach ($layouts as $layout) { $layout = explode('.', substr(basename($layout), 0, -4)); //Layouts must have a format if (count($layout) < 2) { continue; } array_pop($layout); $layout = implode('.', $layout); //Ignore partials and default if ($layout != 'default' && !preg_match('#^_#', $layout) && !preg_match('#^default_#', $layout) && !preg_match('#^form_#', $layout)) { if ($singular) { foreach ($states as $name => $regex) { $this->connect($component . '/' . $view . '/{:' . $name . ':' . $regex . '}/' . $layout, array('component' => $component, 'view' => $view, $name => null, 'layout' => $layout)); } $this->connect($component . '/' . $view . '/' . $layout, array('component' => $component, 'view' => $view, 'layout' => $layout)); } else { $this->connect($component . '/' . $view . '/' . $layout, array('component' => $component, 'view' => $view, 'layout' => $layout)); } } } } } } }