Пример #1
0
 /**
  * @param string $dir
  * @param bool $rebuild
  * @throws \Exception
  */
 private function __construct($dir, $rebuild)
 {
     $this->m_filters = [];
     $this->m_path = str_replace("\\", '', $dir);
     $key = 'templates_' . str_replace(['-', '/', ' '], '_', preg_replace('`[^a-zA-Z0-9_\\-/ ]+`', '', $this->m_path));
     $this->m_templates = Cache::load($key, function () use($dir) {
         return TemplateGenerator::generate($dir);
     }, $rebuild);
     $this->register('iteration', [self::class, '_filter_iteration']);
     $this->register('cycle', [self::class, '_filter_cycle']);
     $this->register('first', [self::class, '_filter_first']);
 }
Пример #2
0
 /**
  * @param bool $rebuild
  * @return RouteMap
  */
 public static function instance($rebuild = false)
 {
     return Cache::load('routes', function () {
         $lookup = [];
         // todo: add support for optional centralized routes
         foreach (Directory::search(BRAMBLE_DIR . '/Controllers', Directory::R_PHP, [Directory::R_HIDDEN]) as $file) {
             $controller_name = sprintf('%s\\%s', BRAMBLE_NS, substr(substr($file, strlen(BRAMBLE_DIR) + 1), 0, -4));
             $reflection_class = new \ReflectionClass($controller_name);
             if (!$reflection_class->isAbstract()) {
                 $controller = new $controller_name(Request::get());
                 if (!$controller instanceof Controller) {
                     throw new \Exception('Only controllers are allowed in this directory');
                 }
                 foreach ($controller->routes() as $route) {
                     $route->defaults(['controller' => $controller_name]);
                     $route->compile($lookup);
                 }
             }
         }
         return new self($lookup);
     }, $rebuild);
 }
Пример #3
0
 public function action__clean()
 {
     Cache::clear();
     return NULL;
 }
Пример #4
0
 public static function cache($name, $options)
 {
     Cache::init($name, $options);
 }