/** * @param $plugins * @param $options * * @throws \makallio85\YamlRoute\Exception\PluginException */ public function load($plugins, $options) { $routes = isset($options['routes']) && $options['routes'] === true ? true : false; $options['routes'] = false; CakePlugin::load($plugins, $options); if ($routes) { if (!is_array($plugins)) { $plugins = [$plugins]; } foreach ($plugins as $plugin) { if ($this->isLoaded($plugin)) { throw new Exception\PluginException("Plugin {$plugin} is loaded already and should not be loaded twice."); } $path = Configure::read('plugins')[$plugin] . DS . 'config' . DS . 'routes.yml'; if (!file_exists($path)) { throw new Exception\PluginException("Yaml route configuration file not found in path {$path}."); } $route = Yaml::parse(file_get_contents($path)); $data = ['name' => $plugin, 'route' => $route, 'file' => $path]; $this->_addLoaded($plugin, $data); $data['route'] = $this->_loadRouteConfigs($route); Validator::run($data); $this->_updateLoaded($plugin, $data); } } }
/** * Load project routes.yml file * * @throws \makallio85\YamlRoute\Exception\ValidatorException */ private function _loadProjectConfig() { if ($this->_projectFilePath === null) { $this->setProjectFilePath(ROOT . DS . 'config' . DS . 'routes.yml'); } $path = $this->_getProjectFilePath(); if (!file_exists($path)) { throw new GeneratorException("Project route configuration file not found in path '{$path}'!"); } $route = Yaml::parse(file_get_contents($path)); $route = $this->_loadRouteConfigs($route); $data = ['name' => 'Project', 'route' => $route, 'file' => $path]; Validator::run($data); $this->_addRouteConfig($data); }
/** * @expectedException \makallio85\YamlRoute\Exception\ValidatorException */ public function testEmptyRoute() { Validator::run(['file' => 'foo.bar']); }