Not normally created as a standalone. Use Router::connect() to create Routes for your application.
Example #1
0
 /**
  * Add a route to the collection.
  *
  * @param \Cake\Routing\Route\Route $route The route object to add.
  * @param array $options Additional options for the route. Primarily for the
  *   `_name` option, which enables named routes.
  * @return void
  */
 public function add(Route $route, array $options = [])
 {
     $this->_routes[] = $route;
     // Explicit names
     if (isset($options['_name'])) {
         if (isset($this->_named[$options['_name']])) {
             $matched = $this->_named[$options['_name']];
             throw new DuplicateNamedRouteException(['name' => $options['_name'], 'url' => $matched->template, 'duplicate' => $matched]);
         }
         $this->_named[$options['_name']] = $route;
     }
     // Generated names.
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     // Index path prefixes (for parsing)
     $path = $route->staticPath();
     if (empty($this->_paths[$path])) {
         $this->_paths[$path] = [];
         krsort($this->_paths);
     }
     $this->_paths[$path][] = $route;
     $extensions = $route->getExtensions();
     if (count($extensions) > 0) {
         $this->extensions($extensions);
     }
 }
Example #2
0
 /**
  * Add a route to the collection.
  *
  * @param \Cake\Routing\Route\Route $route The route object to add.
  * @param array $options Additional options for the route. Primarily for the
  *   `_name` option, which enables named routes.
  * @return void
  */
 public function add(Route $route, array $options = [])
 {
     $this->_routes[] = $route;
     // Explicit names
     if (isset($options['_name'])) {
         $this->_named[$options['_name']] = $route;
     }
     // Generated names.
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     // Index path prefixes (for parsing)
     $path = $route->staticPath();
     if (empty($this->_paths[$path])) {
         $this->_paths[$path] = [];
         krsort($this->_paths);
     }
     $this->_paths[$path][] = $route;
     $extensions = $route->extensions();
     if ($extensions) {
         $this->extensions($extensions);
     }
 }
 /**
  * Add a route to the collection.
  *
  * Appends the route to the list of routes, and the route hashtable.
  * @param \Cake\Routing\Route\Route $route The route to add
  * @return void
  */
 public function add(Route $route)
 {
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     $this->_routes[] = $route;
 }
 public function makeRouteDetails(Entity $entity)
 {
     if (!empty($entity->link)) {
         $InflectedRoute = new Route($entity->route);
         $connection = $InflectedRoute->parse($entity->link);
         print_r($connection);
         exit;
     } else {
     }
 }
Example #5
0
 /**
  * Parses a string URL into an array. Parsed URLs will result in an automatic
  * redirection.
  *
  * @param string $url The URL to parse.
  * @param string $method The HTTP method being used.
  * @return false|null False on failure. An exception is raised on a successful match.
  * @throws \Cake\Routing\Exception\RedirectException An exception is raised on successful match.
  *   This is used to halt route matching and signal to the middleware that a redirect should happen.
  */
 public function parse($url, $method = '')
 {
     $params = parent::parse($url, $method);
     if (!$params) {
         return false;
     }
     $redirect = $this->redirect;
     if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) {
         $redirect = $this->redirect[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $redirect += ['pass' => $params['pass'], 'url' => []];
         if (is_array($this->options['persist'])) {
             foreach ($this->options['persist'] as $elem) {
                 if (isset($params[$elem])) {
                     $redirect[$elem] = $params[$elem];
                 }
             }
         }
         $redirect = Router::reverse($redirect);
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     throw new RedirectException(Router::url($redirect, true), $status);
 }
Example #6
0
 /**
  * Underscores the prefix, controller and plugin params before passing them on to the
  * parent class
  *
  * @param array $url Array of parameters to convert to a string.
  * @param array $context An array of the current request context.
  *   Contains information such as the current host, scheme, port, and base
  *   directory.
  * @return string|false Either a string URL for the parameters if they match or false.
  */
 public function match(array $url, array $context = [])
 {
     $url = $this->_underscore($url);
     if (!$this->_inflectedDefaults) {
         $this->_inflectedDefaults = true;
         $this->defaults = $this->_underscore($this->defaults);
     }
     return parent::match($url, $context);
 }
Example #7
0
 /**
  * Slug the prefix, controller and plugin params before passing them on to the
  * parent class
  *
  * @param array $url Array of parameters to convert to a string.
  * @param array $context An array of the current request context.
  *   Contains information such as the current host, scheme, port, and base
  *   directory.
  *
  * @return false|string Either false or a string URL.
  */
 public function match(array $url, array $context = [])
 {
     $url = $this->_slugerize($url);
     if (!$this->_slugedDefaults) {
         $this->_slugedDefaults = true;
         $this->defaults = $this->_slugerize($this->defaults);
     }
     return parent::match($url, $context);
 }
Example #8
0
 /**
  * match method
  *
  * @param array $url
  * @param array $context
  * @return boolean|string
  */
 public function match(array $url, array $context = [])
 {
     if (preg_match("/^ajax.+/", $url['action']) == 0) {
         return false;
     }
     $url['action'] = preg_replace("/^ajax(.+)/", '$1', $url['action']);
     $url = $this->_dasherize($url);
     return parent::match($url, $context);
 }
 /**
  * Reverse route plugin shortcut URLs. If the plugin and controller
  * are not the same the match is an auto fail.
  *
  * @param array $url Array of parameters to convert to a string.
  * @param array $context An array of the current request context.
  *   Contains information such as the current host, scheme, port, and base
  *   directory.
  * @return mixed either false or a string URL.
  */
 public function match(array $url, array $context = array())
 {
     if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] !== $url['controller']) {
         return false;
     }
     $this->defaults['controller'] = $url['controller'];
     $result = parent::match($url, $context);
     unset($this->defaults['controller']);
     return $result;
 }
Example #10
0
 public function match(array $url, array $context = [])
 {
     //debug($url); debug($context); die;
     if (isset($url['_entity'])) {
         $entity = $url['_entity'];
         preg_match_all('@:(\\w+)@', $this->template, $matches);
         foreach ($matches[1] as $field) {
             $url[$field] = $entity[$field];
         }
         $url = ['slug' => $url['_entity']['slug'], 'controller' => $url['_entity']['controller'], 'action' => $url['_entity']['action'], 'plugin' => $url['_entity']['plugin']];
     }
     return parent::match($url, $context);
 }
Example #11
0
 /**
  * Parses a string URL into an array. If it matches, it will convert the prefix, controller and
  * plugin keys to their camelized form
  *
  * @param string $url The URL to parse
  * @return mixed false on failure, or an array of request parameters
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     $this->Posts = TableRegistry::get('Posts');
     $query = $this->Posts->find('all', ['conditions' => ['Posts.slug' => $params['slug']]]);
     if (!$query->count()) {
         return false;
     }
     return $params;
 }
Example #12
0
 /**
  * Testing that patterns on the :action param work properly.
  *
  * @return void
  */
 public function testPatternOnAction()
 {
     $route = new Route('/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions'));
     $result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo'));
     $this->assertFalse($result);
     $result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions'));
     $this->assertEquals('/blog/actions/', $result);
     $result = $route->parse('/blog/other');
     $expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => []);
     $this->assertEquals($expected, $result);
     $result = $route->parse('/blog/foobar');
     $this->assertFalse($result);
 }
 /**
  * Test for __set_state magic method on CakeRoute
  *
  * @return void
  */
 public function testSetState()
 {
     $route = Route::__set_state(['keys' => [], 'options' => [], 'defaults' => ['controller' => 'pages', 'action' => 'display', 'home'], 'template' => '/', '_greedy' => false, '_compiledRoute' => null]);
     $this->assertInstanceOf('Cake\\Routing\\Route\\Route', $route);
     $this->assertSame('/', $route->match(['controller' => 'pages', 'action' => 'display', 'home']));
     $this->assertFalse($route->match(['controller' => 'pages', 'action' => 'display', 'about']));
     $expected = ['controller' => 'pages', 'action' => 'display', 'pass' => ['home']];
     $this->assertEquals($expected, $route->parse('/'));
 }
Example #14
0
 /**
  * test that utf-8 patterns work for :section
  *
  * @return void
  */
 public function testUTF8PatternOnSection()
 {
     $route = new Route('/:section', array('plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index'), array('persist' => array('section'), 'section' => 'آموزش|weblog'));
     $result = $route->parse('/%D8%A2%D9%85%D9%88%D8%B2%D8%B4');
     $expected = array('section' => 'آموزش', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array());
     $this->assertEquals($expected, $result);
     $result = $route->parse('/weblog');
     $expected = array('section' => 'weblog', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array());
     $this->assertEquals($expected, $result);
 }
Example #15
0
 /**
  * Test getting the static path for a route.
  *
  * @return void
  */
 public function testStaticPath()
 {
     $route = new Route('/*', ['controller' => 'Pages', 'action' => 'display']);
     $this->assertEquals('/', $route->staticPath());
     $route = new Route('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
     $this->assertEquals('/pages', $route->staticPath());
     $route = new Route('/pages/:id/*', ['controller' => 'Pages', 'action' => 'display']);
     $this->assertEquals('/pages/', $route->staticPath());
     $route = new Route('/:controller/:action/*');
     $this->assertEquals('/', $route->staticPath());
     $route = new Route('/books/reviews', ['controller' => 'Reviews', 'action' => 'index']);
     $this->assertEquals('/books/reviews', $route->staticPath());
 }
Example #16
-1
 /**
  * Parses a string URL into an array. Parsed URLs will result in an automatic
  * redirection
  *
  * @param string $url The URL to parse
  * @return bool False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new Response();
     }
     $redirect = $this->redirect;
     if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) {
         $redirect = $this->redirect[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $redirect += ['pass' => $params['pass'], 'url' => []];
         if (is_array($this->options['persist'])) {
             foreach ($this->options['persist'] as $elem) {
                 if (isset($params[$elem])) {
                     $redirect[$elem] = $params[$elem];
                 }
             }
         }
         $redirect = Router::reverse($redirect);
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(['Location' => Router::url($redirect, true)]);
     $this->response->statusCode($status);
     $this->response->send();
     $this->response->stop();
 }