parse() public static method

Parses given URL string. Returns 'routing' parameters for that URL.
public static parse ( string $url ) : array
$url string URL to be parsed
return array Parsed elements from URL
Example #1
0
 public static function run()
 {
     session_start();
     $router = new Router();
     list($controller, $action, $mergedParams) = $router->parse();
     return $router->dispatch($controller, $action, $mergedParams);
 }
Example #2
0
 /**
  * testHomeRoute
  */
 public function testHomeRoute()
 {
     $promoted = array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'promoted');
     $result = CroogoRouter::connect('/', $promoted);
     $translateLoaded = CakePlugin::loaded('Translate');
     $expected = $translateLoaded ? 2 : 1;
     $this->assertEquals($expected, count($result));
     $this->assertNotEmpty($result[0]);
     $this->assertInstanceOf('CakeRoute', $result[0]);
     $reversed = Router::parse('/');
     $this->assertEquals($promoted, array_intersect_key($promoted, $reversed));
     // another route
     $index = array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'index');
     $result = CroogoRouter::connect('/nodes', $index);
     $expected = $translateLoaded ? 4 : 2;
     $this->assertEquals($expected, count($result));
     $reversed = Router::parse('/');
     $this->assertEquals($promoted, array_intersect_key($promoted, $reversed));
     $terms = array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'terms');
     $result = CroogoRouter::connect('/', $terms);
     $expected = $translateLoaded ? 6 : 3;
     $this->assertEquals($expected, count($result));
     // override '/' route
     Router::promote();
     $reversed = Router::parse('/');
     $this->assertEquals($terms, array_intersect_key($terms, $reversed));
 }
Example #3
0
 /**
  * 指定されたURLに対応しRouterパース済のCakeRequestのインスタンスを返す
  *
  * @param string $url URL
  * @return CakeRequest
  */
 protected function _getRequest($url)
 {
     Router::reload();
     $request = new CakeRequest($url);
     // コンソールからのテストの場合、requestのパラメーターが想定外のものとなってしまうので調整
     if (isConsole()) {
         $baseUrl = Configure::read('App.baseUrl');
         if ($request->url === false) {
             $request->here = $baseUrl . '/';
         } elseif (preg_match('/^' . preg_quote($request->webroot, '/') . '/', $request->here)) {
             $request->here = $baseUrl . '/' . preg_replace('/^' . preg_quote($request->webroot, '/') . '/', '', $request->here);
         }
         if ($baseUrl) {
             if (preg_match('/^\\//', $baseUrl)) {
                 $request->base = $baseUrl;
             } else {
                 $request->base = '/' . $baseUrl;
             }
             $request->webroot = $baseUrl;
         } else {
             $request->base = '';
             $request->webroot = '/';
         }
     }
     Router::setRequestInfo($request);
     $params = Router::parse($request->url);
     $request->addParams($params);
     return $request;
 }
Example #4
0
File: Pas.php Project: tsmsogn/Pas
 /**
  * Parsed URL which is generate from given $url and current request query params
  *
  * @param CakeRequest $request CakeRequest
  * @param string|array|null $url URL to be parsed
  * @return array Parsed elements which is generate from given $url and current request query params
  */
 public static function parse(CakeRequest $request, $url)
 {
     $pass = $named = $query = $queryParameters = array();
     if (!is_array($url)) {
         $url = Router::parse($url);
     }
     if (isset($url['pass'])) {
         $pass = $url['pass'];
         unset($url['pass']);
     }
     if (isset($url['named'])) {
         $named = $url['named'];
         unset($url['named']);
     }
     if (isset($url['?'])) {
         $queryParameters = $url['?'];
         unset($url['?']);
     }
     if (!is_array($queryParameters)) {
         parse_str($queryParameters, $queryParameters);
     }
     $named = Hash::merge($request->named, $named);
     $queryParameters = Hash::merge($request->query, $queryParameters);
     if (!empty($queryParameters)) {
         $query = array('?' => $queryParameters);
     }
     return Hash::merge($query, $named, $pass, $url);
 }
Example #5
0
 /**
  * Fonction chargée d'initialiser le contrôleur et de lancer la fonction demandée
  *
  * @access	public
  * @author	koéZionCMS
  * @version 0.1 - 30/01/2012 by FI 
  * @version 0.2 - 18/04/2015 by FI - Mise en place du test sur le premier caractère de la fonction pour savoir si elle est privée ou non
  */
 public function dispatch()
 {
     Router::parse($this->request->url, $this->request);
     //Parsing de l'url
     $controller = $this->load_controller();
     //Chargement du controller
     //On va tester si il y a un prefixe
     $action = $this->request->action;
     if ($this->request->prefix) {
         $action = $this->request->prefix . '_' . $action;
     }
     $isPrivateFunction = $action[0] == '_' ? true : false;
     //On vérifie si la fonction demandée n'est pas une fonction privée
     //Gestion des erreurs pour savoir si l'action demandée existe
     //On va supprimer les fonctions de la classe parente avec le array_diff
     if (!in_array($action, array_diff(get_class_methods($controller), get_class_methods('Controller'))) || $isPrivateFunction) {
         $this->error('Le contrôleur ' . $this->request->controller . " n'a pas de méthode " . $action . " dans le fichier dispatcher");
         die;
     }
     //Cette fonction va permettre l'appel dynamique de la fonction (située dans le controller) demandée dans l'url
     $this->dispatch_method($controller, $action, $this->request->params);
     if ($controller->auto_render) {
         $controller->render($action);
     }
     //AUTO RENDER
 }
 /**
  * beforeDispatch Event
  *
  * @param CakeEvent $event イベント
  * @return void|CakeResponse
  */
 public function beforeDispatch(CakeEvent $event)
 {
     $request = $event->data['request'];
     $response = $event->data['response'];
     if (!empty($request->params['Content'])) {
         return;
     } else {
         if ($this->_existController($request)) {
             return;
         }
     }
     $site = BcSite::findCurrent();
     if (!$site || !$site->enabled) {
         return;
     }
     $mainSite = $site->getMain();
     if (!$mainSite) {
         return;
     }
     $mainSiteUrl = '/' . preg_replace('/^' . $site->alias . '\\//', '', $request->url);
     if ($mainSite->alias) {
         $mainSiteUrl = '/' . $mainSite->alias . $mainSiteUrl;
     }
     if ($mainSiteUrl) {
         $request = new CakeRequest($mainSiteUrl);
         $params = Router::parse($request->url);
         $request->addParams($params);
         if ($this->_existController($request)) {
             $response->header('Location', $request->base . $mainSiteUrl);
             $response->statusCode(302);
             return $response;
         }
     }
     return;
 }
Example #7
0
 /**
  * Checks if a user group has access to a url
  * @param $userGroupID
  * @param $access
  * @param $includeGuestPermission
  * @return unknown_type
  */
 function isUserGroupAccess($userGroupID, $access, $includeGuestPermission = true)
 {
     if (empty($access) || $access == '/' || substr($access, 0, 4) == 'css/') {
         return true;
     }
     $permissions = $this->getPermissions($userGroupID, $includeGuestPermission);
     //$paths = explode('/',$access);
     $actionRequested = Router::parse($access);
     //debug($permissions);
     //debug($actionRequested);
     //$this->log($permissions);
     //$this->log($actionRequested);
     foreach ($permissions as $perm) {
         if ($perm['plugin'] == $actionRequested['plugin'] && strtoupper($perm['controller']) == strtoupper($actionRequested['controller']) && ($perm['action'] == '*' || strtoupper($perm['action']) == strtoupper($actionRequested['action']))) {
             // authorized
             //$this->log("SparkPlug: authorized $access for group id $userGroupID");
             //debug($perm, true);
             //die("SparkPlug: authorized $access for group id $userGroupID");
             return true;
         }
     }
     // not authorized
     //$this->log("SparkPlug: unauthorized $access for group id $userGroupID");
     //die("SparkPlug: authorized $access for group id $userGroupID");
     return false;
 }
 /**
  * edit
  *
  * @return void
  */
 public function edit()
 {
     //事前準備
     $this->__prepare();
     //リクエストセット
     if ($this->request->is('post')) {
         $this->set('membershipTab', Hash::get($this->request->data['SiteSetting'], 'membershipTab', 'automatic-registration'));
         $this->request->data['SiteSetting'] = Hash::remove($this->request->data['SiteSetting'], 'membershipTab');
         $automaticInputItems = Hash::get($this->request->data, '_siteManager.automaticInputItems', 'false');
         $this->Session->write('automaticInputItems', $automaticInputItems);
         $this->__parseRequestData();
         $this->SiteSetting->autoRegistRoles = $this->viewVars['userRoles'];
         //登録処理
         $redirect = Router::parse($this->referer());
         $redirect['?'] = array('membershipTab' => $this->viewVars['membershipTab']);
         $this->SiteManager->saveData($redirect);
     } else {
         $this->set('membershipTab', Hash::get($this->request->query, 'membershipTab', 'automatic-registration'));
         if ($this->Session->read('automaticInputItems')) {
             $automaticInputItems = $this->Session->read('automaticInputItems');
             $this->Session->delete('automaticInputItems');
         } else {
             $automaticInputItems = 'false';
         }
         $this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(array('SiteSetting.key' => array('AutoRegist.use_automatic_register', 'AutoRegist.confirmation', 'AutoRegist.use_secret_key', 'AutoRegist.secret_key', 'AutoRegist.role_key', 'AutoRegist.prarticipate_default_room', 'AutoRegist.disclaimer', 'AutoRegist.approval_mail_subject', 'AutoRegist.approval_mail_body', 'AutoRegist.acceptance_mail_subject', 'AutoRegist.acceptance_mail_body', 'UserRegist.mail_subject', 'UserRegist.mail_body', 'UserCancel.use_cancel_feature', 'UserCancel.disclaimer', 'UserCancel.notify_administrators', 'UserCancel.mail_subject', 'UserCancel.mail_body')));
     }
     $this->set('automaticInputItems', $automaticInputItems);
 }
Example #9
0
 private function check($controller, $action, $route)
 {
     $expects = array('controller' => $controller, 'action' => $action);
     $url = Router::parse($route);
     $this->assertEqual($expects['controller'], $url['controller']);
     $this->assertEqual($expects['action'], $url['action']);
 }
Example #10
0
 public function link($title, $url = null, $options = array(), $confirmMessage = false)
 {
     if (!is_array($url)) {
         $tmp = Router::parse($url);
     } else {
         $tmp = $url;
     }
     if (!isset($this->request->params['action'])) {
         $this->request->params['action'] = 'index';
     }
     if (!isset($tmp['action'])) {
         $tmp['action'] = 'index';
     }
     if ($tmp['controller'] == $this->request->params['controller']) {
         if (!isset($options) || !is_array($options)) {
             $options = array();
         }
         if (!isset($options['class'])) {
             $options['class'] = 'current-controller';
         } else {
             $options['class'] .= ' current-controller';
         }
         if ($tmp['action'] == $this->request->params['action'] || $this->request->params['controller'] == 'Pages' && $this->request->params['action'] == 'display' && $this->request->params['pass'][0] == $tmp['action']) {
             $options['class'] .= ' current-page';
             if (isset($tmp[0]) && isset($this->request->params['pass']) && isset($this->request->params['pass'][0]) && $tmp[0] == $this->request->params['pass'][0]) {
                 $options['class'] .= ' current-item';
             }
         }
     }
     return parent::link($title, $url, $options, $confirmMessage);
 }
Example #11
0
 public function _prepareAction($action = '')
 {
     $this->Formatting->params = Router::parse($action);
     $this->Formatting->passedArgs = array_merge($this->Formatting->params['named'], $this->Formatting->params['pass']);
     $this->Formatting->params['url'] = $this->Formatting->params;
     $this->Formatting->beforeFilter();
 }
Example #12
0
 /**
  * set Up test case
  *
  * @return void
  **/
 function setUp()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Controller =& ClassRegistry::init('Controller');
     $this->View =& new DebugView($this->Controller, false);
     $this->_debug = Configure::read('debug');
 }
Example #13
0
 /**
  * construct method
  *
  */
 public function __construct($request, $response)
 {
     $request->addParams(Router::parse('/seo_test'));
     $request->here = '/seo_test';
     $request->webroot = '/';
     Router::setRequestInfo($request);
     parent::__construct($request, $response);
 }
Example #14
0
 function setUp()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Controller =& ClassRegistry::init('Controller');
     $this->Controller->Component =& ClassRegistry::init('Component');
     $this->Controller->Toolbar =& ClassRegistry::init('TestToolBarComponent', 'Component');
 }
Example #15
0
 function _iterate($count = 1)
 {
     $starttime = microtime(true);
     for ($i = 0; $i < $count / 2; $i++) {
         Router::url(array('controller' => 'route_tests', 'action' => 'view', 'RouteTest' => 42));
         Router::parse('/route_tests/view/42-some-route');
     }
     $endtime = microtime(true);
     return $endtime - $starttime;
 }
 /**
  * setup
  *
  * @return void
  **/
 function setup()
 {
     parent::setup();
     $this->_pluginPath = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
     $controller = new Controller();
     $view = new View($controller);
     $view->set('basePath', $this->_pluginPath);
     $this->ApiDoc = new ApiDocHelper($view);
     Router::reload();
     Router::parse('/');
 }
Example #17
0
 /**
  * setUp
  *
  * @return void
  **/
 function startTest()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Asset =& new AssetHelper();
     $this->Asset->Html =& new HtmlHelper();
     $this->Controller =& ClassRegistry::init('Controller');
     if (isset($this->_debug)) {
         Configure::write('debug', $this->_debug);
     }
 }
 /**
  * startTest
  *
  * @return void
  **/
 function startTest()
 {
     $this->_pluginPath = dirname(dirname(dirname(dirname(__FILE__))));
     $controller = new Controller();
     $view = new View($controller);
     $view->set('basePath', $this->_pluginPath);
     $this->ApiDoc = new ApiDocHelper();
     $this->ApiDoc->Html = new HtmlHelper();
     Router::reload();
     Router::parse('/');
 }
Example #19
0
 function startTest()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->GpsForm =& new GpsFormHelper();
     $this->GpsForm->MockBackend = new MockBackendHelper();
     $this->Controller =& ClassRegistry::init('Controller');
     if (isset($this->_debug)) {
         Configure::write('debug', $this->_debug);
     }
 }
Example #20
0
 /**
  * setUp
  *
  * @return void
  **/
 function setUp()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Toolbar =& new ToolbarHelper(array('output' => 'DebugKit.FirePhpToolbar'));
     $this->Toolbar->FirePhpToolbar =& new FirePhpToolbarHelper();
     $this->Controller =& ClassRegistry::init('Controller');
     if (isset($this->_debug)) {
         Configure::write('debug', $this->_debug);
     }
 }
Example #21
0
 function settings()
 {
     if (!empty($this->request->data['Settings'])) {
         $this->request->data['Settings']['loginAction'] = Router::parse($this->request->data['Settings']['loginAction']);
         $this->request->data['Settings']['defaultDeniedAction'] = Router::parse($this->request->data['Settings']['defaultDeniedAction']);
         Configure::write('Authake', $this->request->data['Settings']);
     }
     $configs = Configure::read('Authake');
     Configure::dump('authake_config.php', 'Authake', array('Authake'));
     $this->set(compact('configs'));
     // fix permissions dropdown menu
 }
 /**
  * setUp
  *
  * @return void
  **/
 function startTest()
 {
     Configure::write('Cache.disable', false);
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Toolbar =& new ToolbarHelper(array('output' => 'MockBackendHelper', 'cacheKey' => 'debug_kit_toolbar_test_case', 'cacheConfig' => 'default'));
     $this->Toolbar->MockBackend = new MockBackendHelper();
     $this->Controller =& ClassRegistry::init('Controller');
     if (isset($this->_debug)) {
         Configure::write('debug', $this->_debug);
     }
 }
Example #23
0
/**
 * Function is responsible for returning the current classes for 
 * this given page
 */
function body_classes()
{
    $route = Router::parse();
    $class = $route['controller'];
    if (!empty($route['plugin'])) {
        $class .= ' ' . $route['plugin'];
    }
    if (!empty($route['action'])) {
        $class .= ' ' . $route['action'];
    }
    echo $class;
}
Example #24
0
 function __construct()
 {
     $this->request = new Request();
     //echo $this->request->url;
     Router::parse($this->request->url, $this->request);
     $controller = $this->loadController();
     if (!in_array($this->request->action, get_class_methods($controller))) {
         $this->error('Error 404 not found');
     }
     call_user_func_array(array($controller, $this->request->action), $this->request->params);
     $controller->render($this->request->action);
 }
Example #25
0
 /**
  * set Up test case
  *
  * @return void
  **/
 function startTest()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Controller =& new Controller();
     $this->View =& new DebugView($this->Controller, false);
     $this->_debug = Configure::read('debug');
     $this->_paths = array();
     $this->_paths['plugins'] = App::path('plugins');
     $this->_paths['views'] = App::path('views');
     $this->_paths['vendors'] = App::path('vendors');
     $this->_paths['controllers'] = App::path('controllers');
 }
Example #26
0
 /**
  * setUp
  *
  * @return void
  **/
 function setUp()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Toolbar =& new ToolbarHelper(array('output' => 'DebugKit.HtmlToolbar'));
     $this->Toolbar->HtmlToolbar =& new HtmlToolbarHelper();
     $this->Toolbar->HtmlToolbar->Html =& new HtmlHelper();
     $this->Toolbar->HtmlToolbar->Form =& new FormHelper();
     $this->Controller =& new Controller();
     if (isset($this->_debug)) {
         Configure::write('debug', $this->_debug);
     }
 }
Example #27
0
 function isInternalUrl($url)
 {
     if (preg_match('/https?:\\/\\//i', $url)) {
         if (strpos($url, Router::url('/', true)) === false) {
             return false;
         } else {
             $url = str_replace(Router::url('/', true), '/', $url);
         }
     }
     $params = Router::parse($url);
     //debug($params);
     return $params['plugin'] == 'shop';
 }
 /**
  * set Up test case
  *
  * @return void
  **/
 function startTest()
 {
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Controller =& ClassRegistry::init('Controller');
     $this->View =& new DebugView($this->Controller, false);
     $this->_debug = Configure::read('debug');
     $this->_paths = array();
     $this->_paths['plugin'] = Configure::read('pluginPaths');
     $this->_paths['view'] = Configure::read('viewPaths');
     $this->_paths['vendor'] = Configure::read('vendorPaths');
     $this->_paths['controller'] = Configure::read('controllerPaths');
 }
Example #29
0
 /**
  * Get the ACO path of a link.
  * This can be useful for example to check then if a user is allowed to access an url.
  *
  * @param mixed $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4"
  *   or an array specifying any of the following: 'controller', 'action',
  *   and/or 'plugin', in addition to named arguments (keyed array elements),
  *   and standard URL arguments (indexed array elements)
  */
 static function aco_path($url)
 {
     $r_url = Router::url($url);
     $r_url = str_replace(Router::url('/'), '/', $r_url);
     $parsed_url = Router::parse($r_url);
     $aco_path = 'controllers/';
     if (!empty($parsed_url['plugin'])) {
         $aco_path .= Inflector::camelize($parsed_url['plugin']) . '/';
     }
     $aco_path .= Inflector::camelize($parsed_url['controller']) . '/';
     $aco_path .= $parsed_url['action'];
     return $aco_path;
 }
Example #30
0
 /**
  * setUp
  *
  * @return void
  **/
 public function setUp()
 {
     Configure::write('Cache.disable', false);
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Controller = new Controller(null);
     $this->View = new View($this->Controller);
     $this->Toolbar = new ToolbarHelper($this->View, array('output' => 'MockBackendHelper', 'cacheKey' => 'debug_kit_toolbar_test_case', 'cacheConfig' => 'default'));
     $this->Toolbar->MockBackend = $this->getMock('Helper', array('testMethod'), array($this->View));
     if (isset($this->_debug)) {
         Configure::write('debug', $this->_debug);
     }
 }