private function getCollection()
 {
     $collection = new RouteCollection();
     $collection->add('page', RouteFactory::createHttpGet('/page/{slug}')->handleWith(function ($slug) {
         return sprintf('Page: %s', $slug);
     }));
     return $collection;
 }
 public function testControllerWithArguments()
 {
     $collection = new RouteCollection();
     $collection->add('detail', (new Route('/detail/{id}/{slug}'))->setRequirement('id', '\\d+')->setRequirement('slug', '[a-z\\-]+')->handleWith('app.controller.default:detail'));
     $request = Request::create('/detail/5/hello-world', Request::HTTP_METHOD_POST);
     $kernel = $this->buildKernel($request, $collection);
     $kernel->boot();
     $this->assertSame('POST: hello-world-5', $this->responseEvent->getResponse()->getContent());
 }
예제 #3
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());
 }
예제 #4
0
 /**
  * Generate route request by route name.
  *
  * @param string $name
  * @param array  $parameters
  *
  * @return RequestContext
  */
 public function generateRoute($name, array $parameters = array())
 {
     $route = $this->collection->get($name);
     if (null === $route) {
         throw new InvalidArgumentException(sprintf('Route with name "%s" not found.', $name));
     }
     $request = RequestContext::createFromRoute($route, $parameters);
     if (false === $this->isMatch($route, $request)) {
         throw new InvalidArgumentException(sprintf('Failed generate route with name "%s", mismatch rules.', $name));
     }
     return $request;
 }
 public function testNestedRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('home', new Route('/'));
     $collection2 = new RouteCollection('/admin');
     $collection2->add('dashboard', new Route('/dashboard'));
     $collection3 = new RouteCollection('/dashboard');
     $collection3->add('dashboard-monitoring', (new Route('/monitoring'))->secureOnly());
     $collection2->addCollection($collection3);
     $collection->addCollection($collection2);
     $this->assertArrayHasKey('dashboard', $collection->all());
     $this->assertTrue($collection->get('dashboard')->getPath() === '/admin/dashboard');
     $this->assertTrue($collection->get('dashboard-monitoring')->getPath() === '/admin/dashboard/monitoring');
     $this->assertTrue($collection->get('dashboard-monitoring')->getSchema()->has('http') === false);
     $this->assertTrue($collection->get('dashboard-monitoring')->getSchema()->has('https'));
 }
 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;
 }
 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 getProfileRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('profile', RouteFactory::createHttpGet('/profile', function () {
         return new Response('Hello world');
     })->setBag(new ParameterBag('middlewares', array('auth'))));
     return $collection;
 }
 /**
  * Add a route collection by append all routes on that collection.
  *
  * @param RouteCollection $collection
  *
  * @return static
  */
 public function addCollection(RouteCollection $collection)
 {
     foreach ($collection->all() as $name => $route) {
         $this->add($name, $route);
     }
     return $this;
 }