當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MvcEvent::setRequest方法代碼示例

本文整理匯總了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);
                 }
             }
         }
     }
 }
開發者ID:n3vrax,項目名稱:dotkernel,代碼行數:31,代碼來源:OauthRouteGuard.php

示例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);
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:12,代碼來源:ApplicationListenerTest.php

示例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);
 }
開發者ID:neeckeloo,項目名稱:newrelic,代碼行數:11,代碼來源:ResponseListenerTest.php

示例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);
 }
開發者ID:bazzline,項目名稱:zf_cli_generator,代碼行數:14,代碼來源:IndexControllerTest.php

示例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();
    }
開發者ID:noose,項目名稱:zf2,代碼行數:40,代碼來源:ActionController.php

示例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']);
 }
開發者ID:gstearmit,項目名稱:EshopVegeTable,代碼行數:26,代碼來源:RenderErrorListenerTest.php

示例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');
    }
開發者ID:benivaldo,項目名稱:zf2-na-pratica,代碼行數:31,代碼來源:ForwardTest.php

示例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));
 }
開發者ID:omusico,項目名稱:zfr-rest,代碼行數:8,代碼來源:HttpMethodOverrideListenerTest.php

示例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);
 }
開發者ID:uthando-cms,項目名稱:uthando-session-manager,代碼行數:9,代碼來源:RouteListenerTest.php

示例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);
 }
開發者ID:rstgroup,項目名稱:http-method-override,代碼行數:9,代碼來源:HttpMethodOverrideListenerTest.php

示例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());
 }
開發者ID:omusico,項目名稱:zfr-rest,代碼行數:9,代碼來源:ResourceResponseListenerTest.php

示例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);
 }
開發者ID:outeredge,項目名稱:edge-zf2,代碼行數:19,代碼來源:AbstractControllerTestCase.php

示例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'));
 }
開發者ID:nuxwin,項目名稱:zf-mvc-auth,代碼行數:10,代碼來源:HttpAdapterTest.php

示例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');
 }
開發者ID:rajanlamic,項目名稱:IntTest,代碼行數:10,代碼來源:AcceptableViewModelSelectorTest.php

示例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));
 }
開發者ID:nuxwin,項目名稱:zf-mvc-auth,代碼行數:10,代碼來源:DefaultAuthorizationListenerTest.php


注:本文中的Zend\Mvc\MvcEvent::setRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。