HosipLan

Untitled

Jun 6th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Nette,
  6.     Nette\Application\Routers\RouteList,
  7.     Nette\Application\Routers\Route;
  8. use Nette\Utils\Strings;
  9.  
  10.  
  11.  
  12. /**
  13.  * Router factory.
  14.  */
  15. class RouterFactory
  16. {
  17.  
  18.     /**
  19.      * @var bool
  20.      */
  21.     private $productionMode;
  22.  
  23.  
  24.  
  25.     public function __construct($productionMode)
  26.     {
  27.         $this->productionMode = (bool) $productionMode;
  28.     }
  29.  
  30.  
  31.  
  32.     /**
  33.      * @return \Nette\Application\IRouter
  34.      */
  35.     public function createRouter()
  36.     {
  37.         $router = new RouteList();
  38.         $flags = Route::SECURED;
  39. //      $flags = $this->productionMode ? Route::SECURED : 0;
  40.  
  41.         $router[] = new Route('oauth-[!<type=google>]', [
  42.             'module' => 'Forum',
  43.             'presenter' => 'Categories',
  44.             'action' => 'default',
  45.             NULL => array(
  46.                 Route::FILTER_IN => function (array $params) {
  47.                     $params['do'] = 'login-' . $params['type'] . '-response';
  48.                     unset($params['type']);
  49.  
  50.                     return $params;
  51.                 },
  52.                 Route::FILTER_OUT => function (array $params) {
  53.                     if (empty($params['do']) || !preg_match('~^login\\-([^-]+)\\-response$~', $params['do'], $m)) {
  54.                         return NULL;
  55.                     }
  56.  
  57.                     $params['type'] = Strings::lower($m[1]);
  58.                     unset($params['do']);
  59.  
  60.                     return $params;
  61.                 },
  62.             ),
  63.         ], $flags);
  64.  
  65.         $router[] = new Route('login/<action=in>', ['presenter' => 'Sign'], $flags);
  66.         $router[] = new Route('p<permalinkId [0-9]+>', ['module' => 'Forum', 'presenter' => 'Question', 'action' => 'default'], $flags);
  67.         $router[] = new Route('<presenter=Categories>/<action=default>?page=<threads-vp-page>', ['module' => 'Forum'], $flags);
  68.  
  69.         return $router;
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment