Ejemplo n.º 1
0
 private function getCollection()
 {
     $collection = new RouteCollection();
     $collection->add('page', RouteFactory::createHttpGet('/page/{slug}')->handleWith(function ($slug) {
         return sprintf('Page: %s', $slug);
     }));
     return $collection;
 }
Ejemplo n.º 2
0
 public function testKernel()
 {
     $collection = new RouteCollection();
     $collection->add('home', RouteFactory::createHttpGet('/', function () {
         return new Response('Hello world');
     }));
     $kernel = $this->buildKernel(Request::create('/'), $collection);
     $kernel->boot();
     $this->assertEquals('Hello world', $this->responseEvent->getResponse()->getContent());
 }
 public function testBasicRouteRegex()
 {
     $collection = new RouteCollection();
     $collection->add('category', new Route('/category/{name}'));
     $collection->add('page', Route::create('/page/{page}.{ext}')->setRequirement('ext', 'htm|html')->setRequirement('page', '[a-z]+'));
     $collection->add('profile', Route::create('/profile/{username}')->setDefault('username', 'me'));
     $collection->add('read', RouteFactory::createHttpGet('/read/{slug}')->setRequirement('slug', '[a-z\\-]+'));
     $this->assertTrue((bool) preg_match($collection->get('category')->getRegex()->getRegexPattern(), '/category/music'));
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.html'));
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.htm'));
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index05.html') === false);
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.php') === false);
     $this->assertTrue((bool) preg_match($collection->get('profile')->getRegex()->getRegexPattern(), '/profile') === true);
     $this->assertTrue((bool) preg_match($collection->get('profile')->getRegex()->getRegexPattern(), '/profile/danu') === true);
     $this->assertTrue((bool) preg_match($collection->get('read')->getRegex()->getRegexPattern(), '/read/welcome-to-the-jungle') === true);
     $this->assertTrue((bool) preg_match($collection->get('read')->getRegex()->getRegexPattern(), '/read/WELCOME-TO-THE') === false);
 }
 private function getCollection()
 {
     $collection = new RouteCollection();
     $collection->add('default', RouteFactory::createHttpGet('/'))->end()->add('admin', RouteFactory::createHttpGet('/'))->setDomain('admin.localhost')->end()->add('account', RouteFactory::createHttpGet('/account'))->secureOnly()->end()->add('page', RouteFactory::createHttpGet('/page/{slug}/{id}'))->setRequirement('slug', '[a-z\\-]+')->setRequirement('id', '\\d+')->setDefault('id', 1)->end();
     return $collection;
 }
 private function getProfileRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('profile', RouteFactory::createHttpGet('/profile', function () {
         return new Response('Hello world');
     })->setBag(new ParameterBag('middlewares', array('auth'))));
     return $collection;
 }