当前位置: 首页>>代码示例>>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;未经允许,请勿转载。