本文整理汇总了PHP中Router::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::parse方法的具体用法?PHP Router::parse怎么用?PHP Router::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public static function run()
{
session_start();
$router = new Router();
list($controller, $action, $mergedParams) = $router->parse();
return $router->dispatch($controller, $action, $mergedParams);
}
示例2: testHomeRoute
/**
* 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));
}
示例3: _getRequest
/**
* 指定された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;
}
示例4: parse
/**
* 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);
}
示例5: dispatch
/**
* 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
}
示例6: beforeDispatch
/**
* 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;
}
示例7: isUserGroupAccess
/**
* 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;
}
示例8: edit
/**
* 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);
}
示例9: check
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']);
}
示例10: link
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);
}
示例11: _prepareAction
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();
}
示例12: setUp
/**
* 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');
}
示例13: __construct
/**
* 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);
}
示例14: setUp
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');
}
示例15: _iterate
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;
}