本文整理汇总了PHP中Zend\Mvc\MvcEvent::setRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::setRequest方法的具体用法?PHP MvcEvent::setRequest怎么用?PHP MvcEvent::setRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::setRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke(MvcEvent $event)
{
if ($event->getRouteMatch()->getMatchedRouteName() === 'oauth/authorize' || $event->getRouteMatch()->getMatchedRouteName() === 'oauth/code') {
$auth = $this->authentication;
if (!$auth->hasIdentity()) {
//redirect to login form before granting permissions - exception would be client_credentials grant type
$url = $event->getRouter()->assemble([], array('name' => 'dotuser/login'));
$host = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'on' ? 'https://' : 'http://';
$host .= $_SERVER['HTTP_HOST'];
$url = $host . $url . '?redirect=' . urlencode($event->getRequest()->getUriString());
$response = $event->getResponse();
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
$response->sendHeaders();
exit;
} else {
$identity = $auth->getIdentity();
$request = $event->getRequest();
$client_id = $request->getQuery('client_id');
//check to see if user already ganted permissions and is not revoked to skip the step and redirecting directly
if ($event->getRouteMatch()->getMatchedRouteName() === 'oauth/authorize') {
if ($this->userRevokeStorage->isAuthorized($client_id, $identity->getUsername())) {
$newRequest = new \ZF\ContentNegotiation\Request();
$newRequest->setMethod(\Zend\Http\Request::METHOD_POST);
$newRequest->getPost()->set('authorized', 'yes');
$event->setRequest($newRequest);
}
}
}
}
}
示例2: setUp
/**
* @see \PHPUnit_Framework_TestCase::setUp()
*/
protected function setUp()
{
$this->manager = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock();
$this->repository = $this->getMockBuilder(ImageRepository::class)->disableOriginalConstructor()->getMock();
$this->request = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
$this->event = new MvcEvent();
$this->event->setRequest($this->request);
$this->listener = new ApplicationListener($this->manager, $this->repository);
}
示例3: testOnResponseInAjaxHttpRequestContext
public function testOnResponseInAjaxHttpRequestContext()
{
$this->moduleOptions->setBrowserTimingEnabled(true);
$this->client->expects($this->once())->method('disableAutorum');
$this->client->expects($this->never())->method('getBrowserTimingHeader');
$this->client->expects($this->never())->method('getBrowserTimingFooter');
$request = $this->createMock(HttpRequest::class);
$request->expects($this->once())->method('isXmlHttpRequest')->will($this->returnValue(true));
$this->event->setRequest($request);
$this->listener->onResponse($this->event);
}
示例4: setUp
protected function setUp()
{
$this->console = $this->getMockOfConsole();
$this->controller = new IndexController();
$this->event = new MvcEvent();
$this->request = new Request();
$this->response = new Response();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->controller->setConsole($this->console);
$this->controller->setEvent($this->event);
$this->event->setRequest($this->request);
$this->event->setResponse($this->response);
$this->event->setRouteMatch($this->routeMatch);
}
示例5: dispatch
/**
* Dispatch a request
*
* @events dispatch.pre, dispatch.post
* @param Request $request
* @param null|Response $response
* @param null|Event $e
* @return Response|mixed
*/
public function dispatch(Request $request, Response $response = null, Event $e = null)
{
$this->request = $request;
if (!$response) {
$response = new HttpResponse();
}
$this->response = $response;
if ($e instanceof Event && !$e instanceof MvcEvent) {
$eventParams = $e->getParams();
$e = new MvcEvent();
$e->setParams($eventParams);
unset($eventParams);
}
if (null === $e) {
$e = new MvcEvent();
}
$e->setRequest($request)
->setResponse($response)
->setTarget($this);
$this->event = $e;
$result = $this->events()->trigger('dispatch', $e, function($test) {
return ($test instanceof Response);
});
if ($result->stopped()) {
return $result->last();
}
return $e->getResult();
}
示例6: testOnRenderErrorCreatesAnApiProblemResponse
public function testOnRenderErrorCreatesAnApiProblemResponse()
{
$response = new Response();
$request = new Request();
$request->getHeaders()->addHeaderLine('Accept', 'application/json');
$event = new MvcEvent();
$event->setError(Application::ERROR_EXCEPTION);
$event->setRequest($request);
$event->setResponse($response);
$this->listener->onRenderError($event);
$this->assertTrue($event->propagationIsStopped());
$this->assertSame($response, $event->getResponse());
$this->assertEquals(406, $response->getStatusCode());
$headers = $response->getHeaders();
$this->assertTrue($headers->has('Content-Type'));
$this->assertEquals('application/problem+json', $headers->get('content-type')->getFieldValue());
$content = json_decode($response->getContent(), true);
$this->assertArrayHasKey('status', $content);
$this->assertArrayHasKey('title', $content);
$this->assertArrayHasKey('describedBy', $content);
$this->assertArrayHasKey('detail', $content);
$this->assertEquals(406, $content['status']);
$this->assertEquals('Not Acceptable', $content['title']);
$this->assertContains('www.w3.org', $content['describedBy']);
$this->assertContains('accept', $content['detail']);
}
示例7: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$locator = new Locator;
$locator->add('forward', function () {
return new ForwardController();
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($locator);
$this->plugin = $this->controller->plugin('forward');
}
示例8: testDoNothingIfNotHttpRequest
public function testDoNothingIfNotHttpRequest()
{
$event = new MvcEvent();
/* @var \Zend\Stdlib\RequestInterface $request */
$request = $this->getMock(RequestInterface::class);
$event->setRequest($request);
$this->assertNull($this->httpMethodOverrideListener->overrideHttpMethod($event));
}
示例9: testCanStartSession
public function testCanStartSession()
{
$event = new MvcEvent();
$event->setApplication($this->getApplication());
$event->setRequest(new Request());
$sessionListener = new RouteListener();
$sessionListener->startSession($event);
$this->assertArrayHasKey('__ZF', $_SESSION);
}
示例10: testNoneHtmlRequest
public function testNoneHtmlRequest()
{
$request = $this->getMock(RequestInterface::class);
$event = new MvcEvent();
$event->setRequest($request);
$clonedRequest = clone $request;
$this->listener->override($event);
$this->assertEquals($clonedRequest, $request);
}
示例11: testSet201StatusCodeIfPost
public function testSet201StatusCodeIfPost()
{
$request = new HttpRequest();
$request->setMethod(HttpRequest::METHOD_POST);
$this->event->setRequest($request);
$this->response->setContent('foo');
$this->resourceResponseListener->finishResponse($this->event);
$this->assertEquals(201, $this->response->getStatusCode());
}
示例12: setUp
public function setUp()
{
Console::overrideIsConsole(false);
parent::setUp();
$this->request = new Request();
$this->request->setHeaders(new Headers());
$this->routeMatch = new RouteMatch(array('controller' => $this->controllerName));
$this->event = $this->getApplication()->getMvcEvent();
$this->event->setRequest($this->request);
$this->event->setRouteMatch($this->routeMatch);
$this->event->getRouter()->setRequestUri(new HttpUri('http://localhost'));
if (null === $this->controller) {
if (null === $this->controllerName) {
throw new PHPUnit_Framework_Exception('No controller name was specified in the test');
}
$this->controller = $this->getServiceManager()->get('ControllerLoader')->get($this->controllerName);
}
$this->controller->setEvent($this->event);
}
示例13: setUp
public function setUp()
{
// authentication service
$this->authentication = new AuthenticationService(new NonPersistent());
$this->request = $request = new HttpRequest();
$this->response = $response = new HttpResponse();
$mvcEvent = new MvcEvent();
$mvcEvent->setRequest($request)->setResponse($response);
$this->event = new MvcAuthEvent($mvcEvent, $this->authentication, $this->getMock('ZF\\MvcAuth\\Authorization\\AuthorizationInterface'));
}
示例14: setUp
public function setUp()
{
$this->request = new Request();
$event = new MvcEvent();
$event->setRequest($this->request);
$this->event = $event;
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->plugin = $this->controller->plugin('acceptableViewModelSelector');
}
示例15: testBailsEarlyOnMissingRouteMatch
public function testBailsEarlyOnMissingRouteMatch()
{
$listener = $this->listener;
$request = new HttpRequest();
$response = new HttpResponse();
$mvcEvent = new MvcEvent();
$mvcEvent->setRequest($request)->setResponse($response);
$mvcAuthEvent = new MvcAuthEvent($mvcEvent, $this->authentication, $this->authorization);
$this->assertNull($listener($mvcAuthEvent));
}