/** * Gets cache info. * * @param string $file * @return array|null */ protected function getCache($file) { if (!$this->options['cache']) { return null; } if (!$this->cache) { $modified = 0; $resources = $this->controllers->getResources(); foreach ($this->aliases as $name => $alias) { $resources['aliases'][] = $name . $alias[0]; } foreach ($resources['controllers'] as $controller) { if (file_exists($controller) && ($time = filemtime($controller)) > $modified) { $modified = $time; } } $this->cache = ['key' => sha1(json_encode($resources)), 'modified' => $modified]; } $file = sprintf($file, $this->options['cache'], $this->cache['key']); $time = file_exists($file) ? filemtime($file) : 0; $fresh = $time >= $this->cache['modified']; return array_merge(compact('fresh', 'file'), $this->cache); }
/** * Finds and registers controllers. * * Override this method if your extension controllers do not follow the conventions: * * - The controller folder is defined in the extensions config * - The naming convention is 'HelloController.php' * * @param ControllerCollection $collection */ public function registerControllers(ControllerCollection $collection) { if (isset($this->config['controllers'])) { $controllers = (array) $this->config['controllers']; foreach ($controllers as $controller) { foreach (glob($this->getPath() . '/' . ltrim($controller, '/')) as $file) { $path = strtolower(sprintf('%s/%s', $this->getName(), basename($file, 'Controller.php'))); $name = '@' . $path; $collection->add($file, compact('path', 'name')); } } } }