本文整理汇总了PHP中Cake\Routing\Router::pushRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::pushRequest方法的具体用法?PHP Router::pushRequest怎么用?PHP Router::pushRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Routing\Router
的用法示例。
在下文中一共展示了Router::pushRequest方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBuildResetWithPlugin
/**
* @return void
*/
public function testBuildResetWithPlugin()
{
Router::connect('/:controller/:action/*');
$result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
$expected = '/foobar/test';
$this->assertSame($expected, $result);
$this->Url->request->here = '/admin/foo/bar/baz/test';
$this->Url->request->params['prefix'] = 'admin';
$this->Url->request->params['plugin'] = 'Foo';
Router::reload();
Router::connect('/:controller/:action/*');
Router::plugin('Foo', function ($routes) {
$routes->fallbacks();
});
Router::prefix('admin', function ($routes) {
$routes->plugin('Foo', function ($routes) {
$routes->fallbacks();
});
});
Plugin::routes();
Router::pushRequest($this->Url->request);
$result = $this->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
$expected = '/admin/foo/bar/baz/x';
$this->assertSame($expected, $result);
$result = $this->Url->buildReset(['controller' => 'bar', 'action' => 'baz', 'x']);
$expected = '/bar/baz/x';
$this->assertSame($expected, $result);
}
示例2: setUp
/**
* @return void
*/
public function setUp()
{
parent::setUp();
Configure::write('Captcha', ['debug' => false]);
$this->request = new Request();
$this->request->env('REMOTE_ADDR', '127.0.0.1');
$this->session = $this->getMockBuilder(Session::class)->setMethods(['id'])->getMock();
$this->session->expects($this->once())->method('id')->willReturn(1);
$this->request->session($this->session);
Router::pushRequest($this->request);
Router::reload();
$this->Captchas = TableRegistry::get('Captcha.Captchas');
$this->Comments = TableRegistry::get('Captcha.Comments');
$this->Comments->addBehavior('Captcha.Captcha');
}
示例3: dispatch
public function dispatch(Request $request, Response $response)
{
Router::pushRequest($request);
$beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
$request = $beforeEvent->data['request'];
if ($beforeEvent->result instanceof Response) {
return $beforeEvent->result;
}
$controller = $this->factory->create($request, $response);
$response = $this->_invoke($controller);
if (isset($request->params['return'])) {
return $response;
}
$afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
return $afterEvent->data['response'];
}
示例4: dispatch
/**
* Dispatches a Request & Response
*
* @param \Cake\Network\Request $request The request to dispatch.
* @param \Cake\Network\Response $response The response to dispatch.
* @return \Cake\Network\Response a modified/replaced response.
*/
public function dispatch(Request $request, Response $response)
{
if (Router::getRequest(true) !== $request) {
Router::pushRequest($request);
}
$beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
$request = $beforeEvent->data['request'];
if ($beforeEvent->result instanceof Response) {
return $beforeEvent->result;
}
// Use the controller built by an beforeDispatch
// event handler if there is one.
if (isset($beforeEvent->data['controller'])) {
$controller = $beforeEvent->data['controller'];
} else {
$controller = $this->factory->create($request, $response);
}
$response = $this->_invoke($controller);
if (isset($request->params['return'])) {
return $response;
}
$afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
return $afterEvent->data['response'];
}
示例5: testDefaultToLoginRedirect
/**
* Default to loginRedirect, if set, on authError.
*
* @return void
* @triggers Controller.startup $Controller
*/
public function testDefaultToLoginRedirect()
{
$url = '/party/on';
$this->Auth->request = $request = new Request($url);
$request->env('HTTP_REFERER', false);
$request->addParams(Router::parse($url));
$request->addPaths(['base' => 'dirname', 'webroot' => '/dirname/']);
Router::pushRequest($request);
$this->Auth->config('authorize', ['Controller']);
$this->Auth->setUser(['username' => 'mariano', 'password' => 'cake']);
$this->Auth->config('loginRedirect', ['controller' => 'something', 'action' => 'else']);
$response = new Response();
$Controller = $this->getMock('Cake\\Controller\\Controller', ['on', 'redirect'], [$request, $response]);
$event = new Event('Controller.startup', $Controller);
// Should not contain basedir when redirect is called.
$expected = '/something/else';
$Controller->expects($this->once())->method('redirect')->with($this->equalTo($expected));
$this->Auth->startup($event);
}
示例6: testRefererSlash
/**
* Test that the referer is not absolute if it is '/'.
*
* This avoids the base path being applied twice on string urls.
*
* @return void
*/
public function testRefererSlash()
{
$request = $this->getMockBuilder('Cake\\Network\\Request')->setMethods(['referer'])->getMock();
$request->base = '/base';
Router::pushRequest($request);
$request->expects($this->any())->method('referer')->will($this->returnValue('/'));
$controller = new Controller($request);
$result = $controller->referer('/', true);
$this->assertEquals('/', $result);
$controller = new Controller($request);
$result = $controller->referer('/some/path', true);
$this->assertEquals('/base/some/path', $result);
}
示例7: testGetRequest
/**
* test get request.
*
* @return void
*/
public function testGetRequest()
{
$requestA = new Request('/');
$requestB = new Request('/posts');
Router::pushRequest($requestA);
Router::pushRequest($requestB);
$this->assertSame($requestA, Router::getRequest(false));
$this->assertSame($requestB, Router::getRequest(true));
}
示例8: testImageWithFullBase
/**
* Test that image() works with fullBase and a webroot not equal to /
*
* @return void
*/
public function testImageWithFullBase()
{
$result = $this->Html->image('test.gif', array('fullBase' => true));
$here = $this->Html->url('/', true);
$this->assertTags($result, array('img' => array('src' => $here . 'img/test.gif', 'alt' => '')));
$result = $this->Html->image('sub/test.gif', array('fullBase' => true));
$here = $this->Html->url('/', true);
$this->assertTags($result, array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => '')));
$request = $this->Html->request;
$request->webroot = '/myproject/';
$request->base = '/myproject';
Router::pushRequest($request);
$result = $this->Html->image('sub/test.gif', array('fullBase' => true));
$here = $this->Html->url('/', true);
$this->assertTags($result, array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => '')));
}
示例9: testImageWithFullBase
/**
* Test that image() works with fullBase and a webroot not equal to /
*
* @return void
*/
public function testImageWithFullBase()
{
$result = $this->Html->image('test.gif', ['fullBase' => true]);
$here = $this->Html->Url->build('/', true);
$expected = ['img' => ['src' => $here . 'img/test.gif', 'alt' => '']];
$this->assertHtml($expected, $result);
$result = $this->Html->image('sub/test.gif', ['fullBase' => true]);
$here = $this->Html->Url->build('/', true);
$expected = ['img' => ['src' => $here . 'img/sub/test.gif', 'alt' => '']];
$this->assertHtml($expected, $result);
$request = $this->Html->request;
$request->webroot = '/myproject/';
$request->base = '/myproject';
Router::pushRequest($request);
$result = $this->Html->image('sub/test.gif', ['fullBase' => true]);
$here = $this->Html->Url->build('/', true);
$expected = ['img' => ['src' => $here . 'img/sub/test.gif', 'alt' => '']];
$this->assertHtml($expected, $result);
}