コード例 #1
0
ファイル: RouterCached.php プロジェクト: s3b4stian/framework
 /**
  * Evaluate request uri
  *
  * @param string $requestUri Request uri
  * @param string $requestMethod Request method
  */
 public function validate(string $requestUri, string $requestMethod) : bool
 {
     //check if route is already cached
     if (($cachedRoute = $this->cache->get($requestUri)) !== false) {
         //get cached route
         $this->route = $cachedRoute;
         return true;
     }
     //if route not cached, validate, if valid cache it
     if (parent::validate($requestUri, $requestMethod)) {
     }
     //cache validated route
     $this->cache->set($requestUri, $this->route);
     return true;
     return false;
 }
コード例 #2
0
 public function testModelDetach()
 {
     $router = new Router($this->routes, array('basePath' => '/', 'badRoute' => 'E404', 'rewriteMode' => true));
     //evaluate request uri
     $router->validate('/Foo/data500/modifyDataFromParam', 'GET');
     $route = $router->getRoute();
     $routeAction = $route->getAction();
     $routeParam = $route->getParam();
     $model = new FOOModel();
     $view = new FOOView($model, new FOOTemplate());
     $controller = new FOOController($model);
     $model->attach($view);
     $model->detach($view);
     call_user_func_array(array($controller, $routeAction), $routeParam);
     $model->notify();
     $routeAction = $routeAction !== null ? $routeAction : 'index';
     call_user_func(array($view, $routeAction));
     ob_start();
     $view->render();
     $test = json_decode(ob_get_contents());
     ob_end_clean();
     $this->assertInstanceOf(stdClass::class, $test);
     $this->assertEquals(false, isset($test->data));
 }
コード例 #3
0
ファイル: index.php プロジェクト: s3b4stian/app
//$sessionHandler = $DIResolver->resolve('\Linna\Session\MemcachedSessionHandler');
//create session object
$session = new Session($options['session']);
//set session handler
//optional if not set, app will use php session standard storage
$session->setSessionHandler($sessionHandler);
//start session
$session->start();
//store session instance
$DIResolver->cacheUnResolvable('\\Linna\\Session\\Session', $session);
/**
 * Router Section
 *
 */
//start router
$router = new Router($appRoutes, $options['router']);
//evaluate request uri and method
$router->validate($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
//get route
$route = $router->getRoute();
//get model linked to route
$routeModel = '\\App\\Models\\' . $route->getModel();
//get view linked to route
$routeView = '\\App\\Views\\' . $route->getView();
//get controller linked to route
$routeController = '\\App\\Controllers\\' . $route->getController();
//resolve model
$model = $DIResolver->resolve($routeModel);
//resolve view
$view = $DIResolver->resolve($routeView);
//resolve controller
コード例 #4
0
ファイル: RouterTest.php プロジェクト: s3b4stian/framework
 public function testRewriteModeOff()
 {
     //start router
     $router = new Router($this->routes, array('basePath' => '/', 'badRoute' => 'E404', 'rewriteMode' => false));
     //evaluate request uri
     $router->validate('/index.php?//user/5/enable', 'GET');
     //get route
     $route = $router->getRoute();
     $this->assertInstanceOf(Route::class, $route);
     $this->assertEquals('UserModel', $route->getModel());
     $this->assertEquals('UserView', $route->getView());
     $this->assertEquals('UserController', $route->getController());
     $this->assertEquals('enable', $route->getAction());
     $this->assertEquals(array('id' => '5'), $route->getParam());
 }