本文整理汇总了PHP中Dispatcher::parseParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::parseParams方法的具体用法?PHP Dispatcher::parseParams怎么用?PHP Dispatcher::parseParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::parseParams方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startActionForTest
/**
* Starts the process for the given $url.
*
* @param string $url Requested URL
* @param array $params Settings array ("bare", "return") which is
* melded with the GET and POST params
* @return mixed The results of the called action
*/
public function startActionForTest($url, $params = array())
{
$default = array('fixturize' => false, 'data' => array(), 'method' => 'get', 'connection' => 'default');
$params = array_merge($default, $params);
$toSave = array('case' => null, 'group' => null, 'app' => null, 'output' => null, 'show' => null, 'plugin' => null);
$this->__savedGetData = empty($this->__savedGetData) ? array_intersect_key($_GET, $toSave) : $this->__savedGetData;
$data = !empty($params['data']) ? $params['data'] : array();
if (strtolower($params['method']) == 'get') {
$_GET = array_merge($this->__savedGetData, $data);
$_POST = array();
} else {
$_POST = array('data' => $data);
$_GET = $this->__savedGetData;
}
$_SERVER['REQUEST_METHOD'] = strtoupper($params['method']);
$params = array_diff_key($params, array('data' => null, 'method' => null));
$Dispatcher = new Dispatcher();
$url = $Dispatcher->getUrl($url);
$this->params = array_merge($Dispatcher->parseParams($url), $params);
$this->here = $this->base . '/' . $url;
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
$this->base = $this->base;
$this->here = $this->here;
$this->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null;
$this->action =& $this->params['action'];
$this->passedArgs = array_merge($this->params['pass'], $this->params['named']);
if (!empty($this->params['data'])) {
$this->data =& $this->params['data'];
} else {
$this->data = null;
}
if (!empty($this->params['bare'])) {
$this->autoLayout = false;
}
if (isset($this->_testCase) && method_exists($this->_testCase, 'startController')) {
$this->_testCase->startController($this, $this->params);
}
unset($_SESSION);
$this->constructClasses();
$this->startupProcess();
}
示例2: testHttpMethodOverrides
/**
* testHttpMethodOverrides method
*
* @return void
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
*/
public function testHttpMethodOverrides()
{
Router::reload();
Router::mapResources('Posts');
$_SERVER['REQUEST_METHOD'] = 'POST';
$dispatcher = new Dispatcher();
$request = new CakeRequest('/posts');
$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
$dispatcher->parseParams($event);
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST');
foreach ($expected as $key => $value) {
$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
}
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
$request = new CakeRequest('/posts/5');
$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
$dispatcher->parseParams($event);
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
foreach ($expected as $key => $value) {
$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
}
unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
$_SERVER['REQUEST_METHOD'] = 'GET';
$request = new CakeRequest('/posts/5');
$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
$dispatcher->parseParams($event);
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET');
foreach ($expected as $key => $value) {
$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
}
$_POST['_method'] = 'PUT';
$request = new CakeRequest('/posts/5');
$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
$dispatcher->parseParams($event);
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
foreach ($expected as $key => $value) {
$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
}
$_POST['_method'] = 'POST';
$_POST['data'] = array('Post' => array('title' => 'New Post'));
$_POST['extra'] = 'data';
$_SERVER = array();
$request = new CakeRequest('/posts');
$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
$dispatcher->parseParams($event);
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'data' => array('extra' => 'data', 'Post' => array('title' => 'New Post')));
foreach ($expected as $key => $value) {
$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
}
unset($_POST['_method']);
}
示例3: testLoginRedirect
/**
* testLoginRedirect method
*
* @access public
* @return void
*/
function testLoginRedirect()
{
if (isset($_SERVER['HTTP_REFERER'])) {
$backup = $_SERVER['HTTP_REFERER'];
} else {
$backup = null;
}
$_SERVER['HTTP_REFERER'] = false;
$this->Controller->Session->write('Auth', array('AuthUser' => array('id' => '1', 'username' => 'nate')));
$this->Controller->params = Router::parse('users/login');
$this->Controller->params['url']['url'] = 'users/login';
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'welcome');
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize($this->Controller->Auth->loginRedirect);
$this->assertEqual($expected, $this->Controller->Auth->redirect());
$this->Controller->Session->delete('Auth');
$this->Controller->params['url']['url'] = 'admin/';
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->loginRedirect = null;
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('admin/');
$this->assertTrue($this->Controller->Session->check('Message.auth'));
$this->assertEqual($expected, $this->Controller->Auth->redirect());
$this->Controller->Session->delete('Auth');
//empty referer no session
$_SERVER['HTTP_REFERER'] = false;
$_ENV['HTTP_REFERER'] = false;
putenv('HTTP_REFERER=');
$url = '/posts/view/1';
$this->Controller->Session->write('Auth', array('AuthUser' => array('id' => '1', 'username' => 'nate')));
$this->Controller->testUrl = null;
$this->Controller->params = Router::parse($url);
array_push($this->Controller->methods, 'view', 'edit', 'index');
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->authorize = 'controller';
$this->Controller->params['testControllerAuth'] = true;
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('/');
$this->assertEqual($expected, $this->Controller->testUrl);
$this->Controller->Session->delete('Auth');
$_SERVER['HTTP_REFERER'] = Router::url('/admin/', true);
$this->Controller->Session->write('Auth', array('AuthUser' => array('id' => '1', 'username' => 'nate')));
$this->Controller->params['url']['url'] = 'auth_test/login';
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = 'auth_test/login';
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->loginRedirect = false;
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('/admin');
$this->assertEqual($expected, $this->Controller->Auth->redirect());
//Ticket #4750
//named params
$this->Controller->Session->delete('Auth');
$url = '/posts/index/year:2008/month:feb';
$this->Controller->params = Router::parse($url);
$this->Controller->params['url']['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('posts/index/year:2008/month:feb');
$this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
//passed args
$this->Controller->Session->delete('Auth');
$url = '/posts/view/1';
$this->Controller->params = Router::parse($url);
$this->Controller->params['url']['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('posts/view/1');
$this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
// QueryString parameters
$_back = $_GET;
$_GET = array('url' => '/posts/index/29', 'print' => 'true', 'refer' => 'menu');
$this->Controller->Session->delete('Auth');
$url = '/posts/index/29?print=true&refer=menu';
$this->Controller->params = Dispatcher::parseParams($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('posts/index/29?print=true&refer=menu');
$this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
$_GET = array('url' => '/posts/index/29', 'print' => 'true', 'refer' => 'menu', 'ext' => 'html');
$this->Controller->Session->delete('Auth');
$url = '/posts/index/29?print=true&refer=menu';
$this->Controller->params = Dispatcher::parseParams($url);
//.........这里部分代码省略.........
示例4: testHttpMethodOverrides
/**
* testHttpMethodOverrides method
*
* @return void
* @access public
*/
function testHttpMethodOverrides()
{
Router::reload();
Router::mapResources('Posts');
$_SERVER['REQUEST_METHOD'] = 'POST';
$dispatcher = new Dispatcher();
$dispatcher->base = false;
$result = $dispatcher->parseParams('/posts');
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array(), 'url' => array());
$this->assertEqual($result, $expected);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
$result = $dispatcher->parseParams('/posts/5');
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
$this->assertEqual($result, $expected);
unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
$_SERVER['REQUEST_METHOD'] = 'GET';
$result = $dispatcher->parseParams('/posts/5');
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array(), 'url' => array());
$this->assertEqual($result, $expected);
$_POST['_method'] = 'PUT';
$result = $dispatcher->parseParams('/posts/5');
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
$this->assertEqual($result, $expected);
$_POST['_method'] = 'POST';
$_POST['data'] = array('Post' => array('title' => 'New Post'));
$_POST['extra'] = 'data';
$_SERVER = array();
$result = $dispatcher->parseParams('/posts');
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')), 'url' => array());
$this->assertEqual($result, $expected);
unset($_POST['_method']);
}