예제 #1
0
 /**
  * @param $job
  * @param $collection
  * @return callable
  */
 private function getClosure($job, RouteCollection $collection)
 {
     $collection->addRoutes(['/' => ['use' => $job['controller'], 'ajax' => isset($job['ajax']) && $job['ajax'] ? true : false]], ['path' => ROOT . '/Views', 'namespace' => '']);
     $router = new Router($collection);
     $router->setUrl('/');
     $router->match();
     return function () use($router) {
         $router->callTarget();
         $router->response->sendContent();
     };
 }
예제 #2
0
 /**
  * @param $class
  * @return Route|RouteCollection|Router|mixed
  */
 private function getClass($class)
 {
     switch ($class) {
         case 'JetFire\\Routing\\Route':
             return $this->router->route;
         case 'JetFire\\Routing\\Router':
             return $this->router;
         case 'JetFire\\Routing\\RouteCollection':
             return $this->router->collection;
         default:
             return call_user_func_array($this->router->getConfig()['di'], [$class]);
     }
 }
예제 #3
0
 /**
  * @param $template
  */
 public function setTemplateCallback($template)
 {
     $ext = explode('.', $template['engines'][$template['use']]['extension']);
     $ext = end($ext);
     $this->router->setConfig(['templateCallback' => [$ext => function (Route $route) use($template) {
         $this->app->addRule($template['view'], ['shared' => true]);
         $view = $this->app->get($template['view']);
         $dir = $route->getTarget('view_dir') == '' ? substr($route->getTarget('template'), 0, strrpos($route->getTarget('template'), '/')) : $route->getTarget('view_dir');
         $view->setPath($dir);
         $view->setExtension($template['engines'][$template['use']]['extension']);
         $view->setTemplate(str_replace($dir, '', $route->getTarget('template')));
         $data = isset($route->getTarget()['data']) ? $route->getTarget('data') : [];
         $flash = $this->app->get('session')->getSession()->allFlash();
         foreach ($flash as $key => $content) {
             $data[$key] = $content;
         }
         $view->addData(isset($route->getParams()['data']) ? array_merge($route->getParams()['data'], $data) : $data);
         return $this->app->get('template')->getTemplate()->render($view);
     }]]);
 }
예제 #4
0
 public function testGetResponseMethod()
 {
     $collection = new RouteCollection();
     $collection->addRoutes(ROOT . '/Config/routes.php', ['view_dir' => ROOT . '/Views', 'ctrl_namespace' => 'JetFire\\Routing\\App\\Controllers']);
     $router = new Router($collection);
     $router->addMatcher(new ArrayMatcher($router));
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $router->setUrl('/search');
     $this->assertFalse($router->match());
     $this->assertEquals(405, $router->response->getStatusCode());
 }