Route PHP Class Code Examples

This page contains top rated real world PHP examples of class Route extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: offer.php Project: kidaa30/Swevers
0
 public function __construct()
 {
     $index = new Route('(te-koop|te-huur)', 'index');
     $detail = new Route('%s/%d', 'detail');
     $index->add_route($detail);
     $this->add_route($index);
 }
Example #2
Show file File: RouteTest.php Project: nilamdoc/KYCGlobal
0
 public function testContinuationRoute()
 {
     $route = new Route();
     $this->assertFalse($route->canContinue());
     $route = new Route(array('continue' => true));
     $this->assertTrue($route->canContinue());
     $route = new Route(array('template' => '/admin/{:args}', 'continue' => true, 'params' => array('admin' => true)));
     $result = $route->match(array('admin' => true, 'args' => ''));
     $this->assertEqual('/admin/{:args}', $result);
 }
Example #3
Show file File: RouteCollectionTest.php Project: sudevva/parser2
0
 public function testCollection()
 {
     $my = new RouteCollection();
     $route = new Route(array("path" => "/abstract", "class" => "index"));
     $my->addRoute(new Route(array("path" => "/abstract", "class" => "index")));
     $this->assertEquals(null, $my->findRouteBy("", "path"));
     $this->assertEquals($route, $my->findRouteBy("/abstract", "path"));
     $this->assertEquals(array($route), $my->getAll());
     $route = new Route(array("path" => "/abstract/class", "class" => "index"));
     $this->assertEquals($my, $my->mergeCollection((new RouteCollection())->addRoute($route)));
     $this->assertEquals($route, $my->findRouteBy("/abstract/class", "path"));
 }
Example #4
Show file File: RouteMatchingTest.php Project: ultra-lite/router
0
 /**
  * @dataProvider provideRoutesToTest
  */
 public function testRoutesMatch(string $routeRequestedExpression, string $expectedResultPathExpression)
 {
     $router = new Router();
     $expectedResult = new Route($expectedResultPathExpression);
     $routeRequested = new RequestedRoute($routeRequestedExpression);
     foreach ($this->routesAvailable as $availableRoute) {
         $route = new Route($availableRoute);
         $router->addRoute($route);
     }
     $route = $router->getRouteForRequest($routeRequested);
     \PHPUnit_Framework_Assert::assertTrue($route->equals($expectedResult));
 }
Example #5
Show file File: RouteCollectionTest.php Project: Ener-Getick/symfony
0
 public function testSetMethods()
 {
     $collection = new RouteCollection();
     $routea = new Route('/a', array(), array(), array(), '', array(), array('GET', 'POST'));
     $routeb = new Route('/b');
     $collection->add('a', $routea);
     $collection->add('b', $routeb);
     $collection->setMethods('PUT');
     $this->assertEquals(array('PUT'), $routea->getMethods());
     $this->assertEquals(array('PUT'), $routeb->getMethods());
 }
Example #6
Show file File: RouteCollectionTest.php Project: abouthalf/archies-recipes
0
 public function testSetHost()
 {
     $collection = new RouteCollection();
     $routea = new Route('/a');
     $routeb = new Route('/b', array(), array(), array(), '{locale}.example.net');
     $collection->add('a', $routea);
     $collection->add('b', $routeb);
     $collection->setHost('{locale}.example.com');
     $this->assertEquals('{locale}.example.com', $routea->getHost());
     $this->assertEquals('{locale}.example.com', $routeb->getHost());
 }
Example #7
Show file File: RouteCollectionTest.php Project: Slayug/castor
0
 /**
  * Test the add() and routes() method.
  *
  * @return void
  */
 public function testAddingRoutes()
 {
     $one = new Route('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
     $two = new Route('/', ['controller' => 'Dashboards', 'action' => 'display']);
     $this->collection->add($one);
     $this->collection->add($two);
     $routes = $this->collection->routes();
     $this->assertCount(2, $routes);
     $this->assertSame($one, $routes[0]);
     $this->assertSame($two, $routes[1]);
 }
Example #8
Show file File: RouteCollectionTest.php Project: hhamon/lpdim2016
0
 public function testGetRouteName()
 {
     $r1 = new Route('/r1');
     $r2 = new Route('/r2');
     $routes = new RouteCollection();
     $routes->add('r1', $r1);
     $routes->add('r2', $r2);
     $this->assertSame('r1', $routes->getName($r1));
     $this->assertSame('r2', $routes->getName($r2));
 }
Example #9
Show file File: DefaultAccessCheckTest.php Project: ddrozdik/dmaps
0
 /**
  * Test the access method.
  */
 public function testAccess()
 {
     $request = new Request(array());
     $route = new Route('/test-route', array(), array('_access' => 'NULL'));
     $this->assertEquals(AccessResult::neutral(), $this->accessChecker->access($route, $request, $this->account));
     $route = new Route('/test-route', array(), array('_access' => 'FALSE'));
     $this->assertEquals(AccessResult::forbidden(), $this->accessChecker->access($route, $request, $this->account));
     $route = new Route('/test-route', array(), array('_access' => 'TRUE'));
     $this->assertEquals(AccessResult::allowed(), $this->accessChecker->access($route, $request, $this->account));
 }
Example #10
Show file File: RequestTest.php Project: EhteshamMehmood/BlogMVC
0
 /**
  * Ensure that parameters can be read
  *
  * @test
  */
 public function test_param()
 {
     $route = new Route('(<controller>(/<action>(/<id>)))');
     $uri = 'foo/bar/id';
     $request = Request::factory($uri, NULL, TRUE, array($route));
     // We need to execute the request before it has matched a route
     try {
         $request->execute();
     } catch (Exception $e) {
     }
     $this->assertArrayHasKey('id', $request->param());
     $this->assertArrayNotHasKey('foo', $request->param());
     $this->assertEquals($request->uri(), $uri);
     // Ensure the params do not contain contamination from controller, action, route, uri etc etc
     $params = $request->param();
     // Test for illegal components
     $this->assertArrayNotHasKey('controller', $params);
     $this->assertArrayNotHasKey('action', $params);
     $this->assertArrayNotHasKey('directory', $params);
     $this->assertArrayNotHasKey('uri', $params);
     $this->assertArrayNotHasKey('route', $params);
     $route = new Route('(<uri>)', array('uri' => '.+'));
     $route->defaults(array('controller' => 'foobar', 'action' => 'index'));
     $request = Request::factory('foobar', NULL, TRUE, array($route));
     // We need to execute the request before it has matched a route
     try {
         $request->execute();
     } catch (Exception $e) {
     }
     $this->assertSame('foobar', $request->param('uri'));
 }
Example #11
Show file File: RouterTest.php Project: johann-weiss/MVC
0
 /**
  * Match a plain URL.
  *
  * @access public
  */
 public function testComplexRoutes()
 {
     // Set up the reflection class
     $reflection = new ReflectionMethod('Core\\Router', 'routeTest');
     $reflection->setAccessible(true);
     // Here be variable routes
     // One directory, one variable
     $route = new Core\Route('Foo');
     $route->setRoute('foo/:bar')->setFormat(array('bar' => '\\d+'))->setEndpoint(array('controller' => 'Foo'));
     // Passes
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '1'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '12'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '123'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '123', 'foo'), $route));
     // Fails
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/:bar'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/bar'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/a123'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/1a23'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/12a3'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/a123a'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/12-3'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo/12_3'), $route));
     // Two directories, two variables
     $route = new Core\Route('Foo');
     $route->setRoute('foo/:bar/hello/:world')->setFormat(array('bar' => '\\d+'))->setEndpoint(array('controller' => 'Foo'));
     // Passes
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'world'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '123', 'hello', 'abc123'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '123', 'hello', 'ab-c12-3'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '123', 'hello', 'ab_c12_3'), $route));
     $this->assertTrue($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'world', 'foo'), $route));
     // Fails
     // Missing parameters
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello'), $route));
     // Wrong basic parameters
     $this->assertFalse($reflection->invoke(new Core\Router(), array('bar', '1', 'hello', 'world'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'bar', 'world'), $route));
     // Wrong number type
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', 'bar', 'hello', 'world'), $route));
     // Incorrect default data types, not matching [\w\-]+
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo"rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo\'rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo<rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo>rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo@rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo!rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo£rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo$rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo%rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo&rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo+rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo.rld'), $route));
     $this->assertFalse($reflection->invoke(new Core\Router(), array('foo', '1', 'hello', 'wo rld'), $route));
 }
Example #12
Show file File: ContentTranslationRouteSubscriber.php Project: neetumorwani/blogging
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
         // Try to get the route from the current collection.
         $link_template = $entity_type->getLinkTemplate('canonical');
         if (strpos($link_template, '/') !== FALSE) {
             $base_path = '/' . $link_template;
         } else {
             if (!($entity_route = $collection->get("entity.{$entity_type_id}.canonical"))) {
                 continue;
             }
             $base_path = $entity_route->getPath();
         }
         // Inherit admin route status from edit route, if exists.
         $is_admin = FALSE;
         $route_name = "entity.{$entity_type_id}.edit_form";
         if ($edit_route = $collection->get($route_name)) {
             $is_admin = (bool) $edit_route->getOption('_admin_route');
         }
         $path = $base_path . '/translations';
         $route = new Route($path, array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::overview', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_overview' => $entity_type_id), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $route_name = "entity.{$entity_type_id}.content_translation_overview";
         $collection->add($route_name, $route);
         $route = new Route($path . '/add/{source}/{target}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::add', 'source' => NULL, 'target' => NULL, '_title' => 'Add', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_manage' => 'create'), array('parameters' => array('source' => array('type' => 'language'), 'target' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_add", $route);
         $route = new Route($path . '/edit/{language}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::edit', 'language' => NULL, '_title' => 'Edit', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'update'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_edit", $route);
         $route = new Route($path . '/delete/{language}', array('_entity_form' => $entity_type_id . '.content_translation_deletion', 'language' => NULL, '_title' => 'Delete', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'delete'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_delete", $route);
     }
 }
Example #13
Show file File: Module.php Project: hatcher-project/hatcher-framework
0
 public function dispatchRequest(ServerRequestInterface $request) : ResponseInterface
 {
     $router = null;
     try {
         /* @var $router Router */
         $router = $this->getDI()->get('router');
         try {
             $match = $router->match($request);
             return $this->getRouteHandler()->handle($match, $request);
         } catch (NotFound $e) {
             if ($router && ($notFoundHandler = $router->getNotFoundHandler())) {
                 $notFoundRoute = new Route();
                 $notFoundRoute->handler($notFoundHandler);
                 return $this->getRouteHandler()->handle($notFoundRoute, $request);
             }
             return new HtmlResponse('Page not found!', 404);
         }
     } catch (\Exception $e) {
         if ($this->application->isDev()) {
             // Whoops will display a nice error message
             throw $e;
         } else {
             if ($router && ($errorHandler = $router->getErrorHandler())) {
                 $errorRoute = new Route();
                 $errorRoute->handler($errorHandler);
                 return $this->getRouteHandler()->handle($errorRoute, $request);
             }
             return new EmptyResponse(500);
         }
     }
 }
Example #14
Show file File: ApiLoader.php Project: lingoda/Sylius
0
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     list($prefix, $resource) = explode('.', $resource);
     $pluralResource = Inflector::pluralize($resource);
     $rootPath = '/' . $pluralResource . '/';
     $requirements = array();
     // GET collection request.
     $routeName = sprintf('%s_api_%s_index', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:indexAction', $prefix, $resource));
     $route = new Route($rootPath, $defaults, $requirements, array(), '', array(), array('GET'));
     $routes->add($routeName, $route);
     // GET request.
     $routeName = sprintf('%s_api_%s_show', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:showAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('GET'));
     $routes->add($routeName, $route);
     // POST request.
     $routeName = sprintf('%s_api_%s_create', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:createAction', $prefix, $resource));
     $route = new Route($rootPath, $defaults, $requirements, array(), '', array(), array('POST'));
     $routes->add($routeName, $route);
     // PUT request.
     $routeName = sprintf('%s_api_%s_update', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:updateAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('PUT', 'PATCH'));
     $routes->add($routeName, $route);
     // DELETE request.
     $routeName = sprintf('%s_api_%s_delete', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:deleteAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('DELETE'));
     $routes->add($routeName, $route);
     return $routes;
 }
Example #15
Show file File: router.php Project: kidaa30/Swevers
0
 private static function load_page_files()
 {
     if (count(self::$content_pages)) {
         return self::$content_pages;
     }
     $has_apc = extension_loaded('apc') && ini_get('apc.enabled');
     $slugs_cache = $has_apc && !self::is_fw4() ? apc_fetch($_SERVER['HTTP_HOST'] . '_slugs_' . language()) : false;
     $slugs_reverse_cache = $has_apc && !self::is_fw4() ? apc_fetch($_SERVER['HTTP_HOST'] . '_slugs_reverse_' . language()) : false;
     $titles_cache = $has_apc && !self::is_fw4() ? apc_fetch($_SERVER['HTTP_HOST'] . '_titles') : false;
     if ($handle = opendir(CONTENTPATH . self::$content_prefix)) {
         while (false !== ($file = readdir($handle))) {
             $path_info = pathinfo($file);
             if (isset($path_info['extension']) && $path_info['extension'] == "php") {
                 include CONTENTPATH . self::$content_prefix . $path_info['filename'] . '.php';
             } else {
                 if (is_dir(CONTENTPATH . self::$content_prefix . $file) && file_exists(CONTENTPATH . self::$content_prefix . $file . '/' . $file . '.php')) {
                     include CONTENTPATH . self::$content_prefix . $file . '/' . $file . '.php';
                 }
             }
             $classname = str_replace('-', '_', ucfirst(strtolower($file)));
             if (class_exists($classname)) {
                 $page = new $classname();
                 if ($slugs_cache === false) {
                     $class = new ReflectionClass($page);
                     foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
                         if ($method->class != $classname || $method->name == '__construct') {
                             continue;
                         }
                         if (strstr($method->name, '_')) {
                             $route = new Route(strtolower($file) . '/' . str_replace('_', '-', strtolower($method->name)), $method->name, ROUTE_DEFAULT, ucfirst($method->name));
                             $route->set_classname($classname);
                             $route->set_contentname($file);
                             self::setup_route($route);
                         }
                         $route = new Route(strtolower($file) . '/' . strtolower($method->name), $method->name, ROUTE_DEFAULT, ucfirst($method->name));
                         $route->set_classname($classname);
                         $route->set_contentname($file);
                         self::setup_route($route);
                     }
                     foreach ($page->get_routes() as $route) {
                         self::setup_route($route);
                     }
                 }
                 self::$content_pages[str_replace('-', '_', strtolower($file))] = $page;
             }
         }
         closedir($handle);
         if ($slugs_cache !== false) {
             self::$slugs = $slugs_cache;
             self::$slugs_reverse = $slugs_reverse_cache;
             self::$titles = $titles_cache;
         } else {
             if ($has_apc) {
                 apc_store($_SERVER['HTTP_HOST'] . '_slugs_' . language(), self::$slugs, 60 * 60 * 3);
                 apc_store($_SERVER['HTTP_HOST'] . '_slugs_reverse_' . language(), self::$slugs_reverse, 60 * 60 * 3);
                 apc_store($_SERVER['HTTP_HOST'] . '_titles', self::$titles, 60 * 60 * 3);
             }
         }
     }
 }
Example #16
Show file File: services.php Project: kidaa30/Swevers
0
 public function __construct()
 {
     $index = new Route('diensten', 'index');
     $service = new Route('%s', 'service');
     $index->add_route($service);
     $this->add_route($index);
 }
Example #17
Show file File: RouteCollectionAccessorTest.php Project: Maksold/platform
0
 public function testRemoveWithAlreadyBuilderRouteMap()
 {
     $route1 = new Route('/route1');
     $route2 = new Route('/route2');
     $this->collection->add('route1', $route1);
     $this->collection->add('route2', $route2);
     // force the route map building
     $this->assertSame($route1, $this->accessor->getByPath('/route1', []));
     $this->accessor->remove('route1');
     $this->assertEquals(['route2'], array_keys($this->collection->all()));
     $this->assertNull($this->accessor->getByPath('/route1', []));
 }