contributte / planette-site

💀 [DISCONTINUED] All the roads go through the Planette
https://planette.vercel.app
MIT License
9 stars 3 forks source link

2014-10-28: komplikovanejsi-router-factory #16

Open paveljanda opened 7 years ago

paveljanda commented 7 years ago
<?php

namespace App;

use Nette,
        Nette\Application\Routers\RouteList,
        Nette\Application\Routers\Route,
        Nette\Application\Routers\SimpleRouter;

/**
 * Router factory.
 */
class RouterFactory
{

        /**
         * @return \Nette\Application\IRouter
         */
        public function createRouter()
        {
                $router = new RouteList();
                $router[] = new Route('autocomplete[/<do>]', function($id){

                });
                $router[] = new Route('login ? cmd=<action>', 'Sign:in');
                $router[] = new Route('<? [0-9]{4}>/<presenter>/<action>', [
                        NULL => [
                                Route::FILTER_IN => function($params) {
                                        dump($params);
                                        return $params;
                                },
                                Route::FILTER_OUT => function($params) {
                                        dump($params);
                                        return $params;
                                },
                        ],
                        'presenter' => [
                                Route::VALUE => 'Homepage',
                        ],
                        'action' => [
                                Route::VALUE => 'default',
                                Route::FILTER_IN => function($val){
                                        return $val . '123';
                                },
                                Route::FILTER_OUT => function($val){
                                        return substr($val, 0, -3);
                                },
                                Route::FILTER_STRICT => TRUE,

                        ],
                ]);

                //$router[] = new Route('<slug .+>', 'Homepage:default');
                //$router[] = new Route('<presenter>/<action>[/<id \d+>]', 'Homepage:default');
                return $router;
        }

}
paveljanda commented 7 years ago

author: chemix