示例#1
0
 /**
  * Base init
  */
 private function baseInit()
 {
     // Add Page Title and Page Name (and other Variables defined in Router) to global
     $globalVariables = $this->router->getCurrentRoute()->getData();
     $view = $this->application->getView();
     DataCollection::each($globalVariables, function ($key, $value) use($view) {
         $view->set($key, $value);
     });
     $config = $this->application->getConfig();
     $cache = $this->application->getCache();
     $request = $this->request;
     if ($config->get('app.metaAndTitleFromFile', false)) {
         $metaFilePath = $config->get('app.metaFile');
         $metaPath = $this->appPath . DS . ltrim($metaFilePath, "/");
         if (is_readable($metaPath)) {
             $metaContent = (include $metaPath);
             $metas = isset($metaContent[$request->getPath()]) ? $metaContent[$request->getPath()] : '';
         } else {
             trigger_error(htmlentities("{$config->get('app.mataFile')} file not found or is not readable"), E_USER_WARNING);
         }
         if (!empty($metas)) {
             if (isset($metas['pageTitle'])) {
                 $view->set('pageTitle', $metas['pageTitle']);
                 unset($metas['pageTitle']);
             }
             $view->set('metas', $metas);
         }
     }
     $view->set('domainName', $config->get('app.websiteUrl', ''));
     $view->set('domain', $config->get('app.domain', ''));
     if ($cache->exists('csrf-token')) {
         $view->set('csrfToken', $cache->get('csrf-token'));
     } elseif (isset($_SESSION['csrf-token'])) {
         $view->set('csrfToken', $_SESSION['csrf-token']);
     }
 }
示例#2
0
 public function set($key, $value)
 {
     parent::set($key, $value);
     parent::set('__meta.lastModified', time());
 }
示例#3
0
 /**
  * Find matching Route from Route(s)
  *
  * @param array $routes
  * @param RequestInterface $request
  * @return mixed|null
  * @throws PageNotFoundException
  */
 protected function findRoute(array $routes, RequestInterface $request)
 {
     $path = $request->getPath();
     if (isset($routes[$path])) {
         $route = $routes[$path];
     } else {
         $route = DataCollection::find($routes, function ($key, $value) use($request) {
             return $value->isMatch($request);
         });
     }
     if (!$route instanceof Route) {
         throw new PageNotFoundException();
     } else {
         $this->dispatch('core.router.matched', $this);
     }
     return $route;
 }