getNamedExpressions() public static method

Gets the named route elements for use in app/Config/routes.php
See also: Router::$_namedExpressions
public static getNamedExpressions ( ) : array
return array Named route elements
Example #1
0
 /**
  * Returns array of GET and POST parameters. GET parameters are taken from given URL.
  *
  * @param string $fromUrl URL to mine for parameter information.
  * @return array Parameters found in POST and GET.
  * @access public
  */
 function parseParams($fromUrl)
 {
     $params = array();
     if (isset($_POST)) {
         $params['form'] = $_POST;
         if (ini_get('magic_quotes_gpc') === '1') {
             $params['form'] = stripslashes_deep($params['form']);
         }
         if (env('HTTP_X_HTTP_METHOD_OVERRIDE')) {
             $params['form']['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE');
         }
         if (isset($params['form']['_method'])) {
             if (!empty($_SERVER)) {
                 $_SERVER['REQUEST_METHOD'] = $params['form']['_method'];
             } else {
                 $_ENV['REQUEST_METHOD'] = $params['form']['_method'];
             }
             unset($params['form']['_method']);
         }
     }
     $namedExpressions = Router::getNamedExpressions();
     extract($namedExpressions);
     include CONFIGS . 'routes.php';
     $params = array_merge(Router::parse($fromUrl), $params);
     if (strlen($params['action']) === 0) {
         $params['action'] = 'index';
     }
     if (isset($params['form']['data'])) {
         $params['data'] = Router::stripEscape($params['form']['data']);
         unset($params['form']['data']);
     }
     if (isset($_GET)) {
         if (ini_get('magic_quotes_gpc') === '1') {
             $url = stripslashes_deep($_GET);
         } else {
             $url = $_GET;
         }
         if (isset($params['url'])) {
             $params['url'] = array_merge($params['url'], $url);
         } else {
             $params['url'] = $url;
         }
     }
     foreach ($_FILES as $name => $data) {
         if ($name != 'data') {
             $params['form'][$name] = $data;
         }
     }
     if (isset($_FILES['data'])) {
         foreach ($_FILES['data'] as $key => $data) {
             foreach ($data as $model => $fields) {
                 if (is_array($fields)) {
                     foreach ($fields as $field => $value) {
                         if (is_array($value)) {
                             foreach ($value as $k => $v) {
                                 $params['data'][$model][$field][$k][$key] = $v;
                             }
                         } else {
                             $params['data'][$model][$field][$key] = $value;
                         }
                     }
                 } else {
                     $params['data'][$model][$key] = $fields;
                 }
             }
         }
     }
     return $params;
 }
Example #2
0
 /**
  * testNamedArgsUrlGeneration method
  *
  * @access public
  * @return void
  */
 function testNamedArgsUrlGeneration()
 {
     $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1));
     $expected = '/posts/index/published:1/deleted:1';
     $this->assertEqual($result, $expected);
     $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 0, 'deleted' => 0));
     $expected = '/posts/index/published:0/deleted:0';
     $this->assertEqual($result, $expected);
     Router::reload();
     extract(Router::getNamedExpressions());
     Router::connectNamed(array('file' => '[\\w\\.\\-]+\\.(html|png)'));
     Router::connect('/', array('controller' => 'graphs', 'action' => 'index'));
     Router::connect('/:id/*', array('controller' => 'graphs', 'action' => 'view'), array('id' => $ID));
     $result = Router::url(array('controller' => 'graphs', 'action' => 'view', 'id' => 12, 'file' => 'asdf.png'));
     $expected = '/12/file:asdf.png';
     $this->assertEqual($result, $expected);
     $result = Router::url(array('controller' => 'graphs', 'action' => 'view', 'id' => 12, 'file' => 'asdf.foo'));
     $expected = '/graphs/view/12/file:asdf.foo';
     $this->assertEqual($result, $expected);
     Configure::write('Routing.admin', 'admin');
     Router::reload();
     Router::setRequestInfo(array(array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())));
     Router::parse('/');
     $result = Router::url(array('page' => 1, 0 => null, 'sort' => 'controller', 'direction' => 'asc', 'order' => null));
     $expected = "/admin/controller/index/page:1/sort:controller/direction:asc";
     $this->assertEqual($result, $expected);
     Router::reload();
     Router::setRequestInfo(array(array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array('type' => 'whatever'), 'argSeparator' => ':', 'namedArgs' => array('type' => 'whatever'))));
     $result = Router::parse('/admin/controller/index/type:whatever');
     $result = Router::url(array('type' => 'new'));
     $expected = "/admin/controller/index/type:new";
     $this->assertEqual($result, $expected);
 }
Example #3
0
 /**
  * Reloads the routes configuration from app/Config/routes.php, and compiles
  * all routes found
  *
  * @return boolean True if config reload was a success, otherwise false
  */
 protected function _loadRoutes()
 {
     Router::reload();
     extract(Router::getNamedExpressions());
     if (!@(include APP . 'Config' . DS . 'routes.php')) {
         return false;
     }
     CakePlugin::routes();
     Router::parse('/');
     return true;
 }
Example #4
0
 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
  *
  * @param CakeRequest $request CakeRequest object to mine for parameter information.
  * @param array $additionalParams An array of additional parameters to set to the request.
  *   Useful when Object::requestAction() is involved
  * @return CakeRequest The request object with routing params set.
  */
 public function parseParams(CakeRequest $request, $additionalParams = array())
 {
     if (count(Router::$routes) == 0) {
         $namedExpressions = Router::getNamedExpressions();
         extract($namedExpressions);
         $this->_loadRoutes();
     }
     $params = Router::parse($request->url);
     $request->addParams($params);
     if (!empty($additionalParams)) {
         $request->addParams($additionalParams);
     }
     return $request;
 }
Example #5
0
 /**
  * test the parse method of CakeRoute.
  *
  * @return void
  */
 function testParse()
 {
     extract(Router::getNamedExpressions());
     $route =& new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $ID));
     $route->compile();
     $result = $route->parse('/posts/view/1');
     $this->assertEqual($result['controller'], 'posts');
     $this->assertEqual($result['action'], 'view');
     $this->assertEqual($result['id'], '1');
     $route =& new Cakeroute('/admin/:controller', array('prefix' => 'admin', 'admin' => 1, 'action' => 'index'));
     $route->compile();
     $result = $route->parse('/admin/');
     $this->assertFalse($result);
     $result = $route->parse('/admin/posts');
     $this->assertEqual($result['controller'], 'posts');
     $this->assertEqual($result['action'], 'index');
 }
 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
  *
  * @param CakeEvent $event containing the request, response and additional params
  * @return void
  */
 public function parseParams($event)
 {
     $request = $event->data['request'];
     Router::setRequestInfo($request);
     if (count(Router::$routes) == 0) {
         $namedExpressions = Router::getNamedExpressions();
         extract($namedExpressions);
         $this->_loadRoutes();
     }
     $params = Router::parse($request->url);
     $request->addParams($params);
     if (!empty($event->data['additionalParams'])) {
         $request->addParams($event->data['additionalParams']);
     }
 }
Example #7
0
 /**
  * Reloads the routes configuration from app/Config/routes.php, and compiles
  * all routes found
  *
  * @return boolean True if config reload was a success, otherwise false
  */
 protected function _loadRoutes()
 {
     Router::reload();
     extract(Router::getNamedExpressions());
     //@codingStandardsIgnoreStart
     if (!@(include APP . 'Config' . DS . 'routes.php')) {
         //@codingStandardsIgnoreEnd
         return false;
     }
     CakePlugin::routes();
     Router::parse('/');
     return true;
 }
Example #8
0
 /**
  * Reloads the routes configuration from app/Config/routes.php, and compiles
  * all routes found
  *
  * @return boolean True if config reload was a success, otherwise false
  */
 protected function _loadRoutes()
 {
     Router::reload();
     extract(Router::getNamedExpressions());
     if (!@(include APP . 'Config' . DS . 'routes.php')) {
         return false;
     }
     CakePlugin::routes();
     Router::parse('/');
     foreach (array_keys(Router::getNamedExpressions()) as $var) {
         unset(${$var});
     }
     foreach (Router::$routes as $route) {
         $route->compile();
     }
     return true;
 }
Example #9
0
<?php

/* SVN FILE: $Id$ */
/* Chaw Test cases generated on: 2008-11-18 18:11:32 : 1227060572*/
App::import('Helper', 'Chaw');
App::import('Helper', 'Html');
extract(Router::getNamedExpressions());
include CONFIGS . 'routes.php';
class TestChaw extends ChawHelper
{
}
class ChawHelperTest extends CakeTestCase
{
    function start()
    {
        parent::start();
        $this->Chaw = new TestChaw();
        $this->Chaw->Html = new HtmlHelper();
        $this->Chaw->params = array('url' => array('url' => '/', 'ext' => 'html'));
        $this->Chaw->webroot = '/';
    }
    function testChawInstance()
    {
        $this->assertTrue(is_a($this->Chaw, 'ChawHelper'));
    }
    function testParams()
    {
        $result = $this->Chaw->params(array('id' => 1, 'url' => 'chaw', 'fork' => null));
        $expected = array('project' => null, 'fork' => null);
        $this->assertEqual($result, $expected);
        $result = $this->Chaw->params(array('id' => 2, 'url' => 'some_project', 'fork' => null));
 /**
  * Returns array of GET and POST parameters. GET parameters are taken from given URL.
  *
  * @param string $fromUrl URL to mine for parameter information.
  * @return array Parameters found in POST and GET.
  * @access public
  */
 function parseParams($fromUrl)
 {
     $Route = Router::getInstance();
     extract(Router::getNamedExpressions());
     include CONFIGS . 'routes.php';
     $params = Router::parse($fromUrl);
     if (isset($_POST)) {
         if (ini_get('magic_quotes_gpc') == 1) {
             $params['form'] = stripslashes_deep($_POST);
         } else {
             $params['form'] = $_POST;
         }
     }
     if (isset($params['form']['data'])) {
         $params['data'] = Router::stripEscape($params['form']['data']);
         unset($params['form']['data']);
     }
     if (isset($_GET)) {
         if (ini_get('magic_quotes_gpc') == 1) {
             $url = stripslashes_deep($_GET);
         } else {
             $url = $_GET;
         }
         if (isset($params['url'])) {
             $params['url'] = am($params['url'], $url);
         } else {
             $params['url'] = $url;
         }
     }
     foreach ($_FILES as $name => $data) {
         if ($name != 'data') {
             $params['form'][$name] = $data;
         }
     }
     if (isset($_FILES['data'])) {
         foreach ($_FILES['data'] as $key => $data) {
             foreach ($data as $model => $fields) {
                 foreach ($fields as $field => $value) {
                     $params['data'][$model][$field][$key] = $value;
                 }
             }
         }
     }
     $params['bare'] = empty($params['ajax']) ? empty($params['bare']) ? 0 : 1 : 1;
     $params['webservices'] = empty($params['webservices']) ? null : $params['webservices'];
     return $params;
 }
Example #11
0
 /**
  * testNamedArgsUrlGeneration method
  *
  * @return void
  */
 public function testNamedArgsUrlGeneration()
 {
     $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1));
     $expected = '/posts/index/published:1/deleted:1';
     $this->assertEquals($expected, $result);
     $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 0, 'deleted' => 0));
     $expected = '/posts/index/published:0/deleted:0';
     $this->assertEquals($expected, $result);
     Router::reload();
     extract(Router::getNamedExpressions());
     Router::connectNamed(array('file' => '[\\w\\.\\-]+\\.(html|png)'));
     Router::connect('/', array('controller' => 'graphs', 'action' => 'index'));
     Router::connect('/:id/*', array('controller' => 'graphs', 'action' => 'view'), array('id' => $ID));
     $result = Router::url(array('controller' => 'graphs', 'action' => 'view', 'id' => 12, 'file' => 'asdf.png'));
     $expected = '/12/file:asdf.png';
     $this->assertEquals($expected, $result);
     $result = Router::url(array('controller' => 'graphs', 'action' => 'view', 12, 'file' => 'asdf.foo'));
     $expected = '/graphs/view/12/file:asdf.foo';
     $this->assertEquals($expected, $result);
     Configure::write('Routing.prefixes', array('admin'));
     Router::reload();
     $request = new CakeRequest();
     Router::setRequestInfo($request->addParams(array('admin' => TRUE, 'controller' => 'controller', 'action' => 'index', 'plugin' => NULL))->addPaths(array('base' => '/', 'here' => '/', 'webroot' => '/base/')));
     Router::parse('/');
     $result = Router::url(array('page' => 1, 0 => NULL, 'sort' => 'controller', 'direction' => 'asc', 'order' => NULL));
     $expected = "/admin/controller/index/page:1/sort:controller/direction:asc";
     $this->assertEquals($expected, $result);
     Router::reload();
     $request = new CakeRequest('admin/controller/index');
     $request->addParams(array('admin' => TRUE, 'controller' => 'controller', 'action' => 'index', 'plugin' => NULL));
     $request->base = '/';
     Router::setRequestInfo($request);
     Router::parse('/admin/controller/index/type:whatever');
     $result = Router::url(array('type' => 'new'));
     $expected = "/admin/controller/index/type:new";
     $this->assertEquals($expected, $result);
 }