当前位置: 首页>>代码示例>>PHP>>正文


PHP MvcEvent::setParam方法代码示例

本文整理汇总了PHP中Zend\Mvc\MvcEvent::setParam方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::setParam方法的具体用法?PHP MvcEvent::setParam怎么用?PHP MvcEvent::setParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mvc\MvcEvent的用法示例。


在下文中一共展示了MvcEvent::setParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: injectMatchedNode

 /**
  * Injects the node into the global MVC-Event-instance.
  * 
  * @param MvcEvent $event
  */
 public function injectMatchedNode(MvcEvent $event)
 {
     $routeMatch = $event->getRouteMatch();
     /* @var $routeMatch \Zend\Mvc\Router\Http\RouteMatch */
     $name = $routeMatch->getMatchedRouteName();
     $serviceLocator = $event->getApplication()->getServiceManager();
     $node = $serviceLocator->get('NodeService')->getNode(str_replace('node-', '', $name));
     if (false != $node) {
         $event->setParam('matchedNode', $node);
         // Update access counter if enabled
         if (true == $serviceLocator->get('NodeOptions')->getEnableAccessCounter()) {
             $sessionContainer = new Container('node_access');
             $node->setNodeAccessDate(date('Y-m-d H:i:s'));
             if (false == $sessionContainer->{$node->getNodeId()}) {
                 $node->setNodeAccessCount($node->getNodeAccessCount() + 1);
                 $sessionContainer->{$node->getNodeId()} = 1;
             }
             $serviceLocator->get('NodeService')->saveNode($node);
         }
         // Redirect if it's a Redirect-Node...
         if ('redirect' == $node->getNodeType()) {
             $response = $event->getResponse();
             $response->setStatusCode($node->getNodeRedirectCode());
             $response->getHeaders()->addHeaderLine('Location', $node->getNodeRedirectTarget());
             $response->sendHeaders();
         }
     } else {
         $event->setParam('matchedNode', null);
     }
 }
开发者ID:alexsawallich,项目名称:node,代码行数:35,代码来源:MvcListenerAggregate.php

示例2: testDoesNotLimitDispatchErrorEventToOnlyOneListener

 public function testDoesNotLimitDispatchErrorEventToOnlyOneListener()
 {
     $eventManager = new EventManager();
     $application = $this->prophesize(Application::class);
     $application->getEventManager()->willReturn($eventManager);
     $event = new MvcEvent();
     $event->setApplication($application->reveal());
     $guard = new DummyGuard();
     $guard->attach($eventManager);
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) {
         $event->setParam('first-listener', true);
     });
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) {
         $event->setParam('second-listener', true);
     });
     // attach listener with lower priority than DummyGuard
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function (MvcEvent $event) {
         $this->fail('should not be called, because guard should stop propagation');
     }, DummyGuard::EVENT_PRIORITY - 1);
     $event->setName(MvcEvent::EVENT_ROUTE);
     $eventManager->triggerEvent($event);
     $this->assertTrue($event->getParam('first-listener'));
     $this->assertTrue($event->getParam('second-listener'));
     $this->assertTrue($event->propagationIsStopped());
 }
开发者ID:zf-commons,项目名称:zfc-rbac,代码行数:25,代码来源:AbstractGuardTest.php

示例3: onDispatch

 public function onDispatch(MvcEvent $e)
 {
     $routeMatch = $e->getRouteMatch();
     $contentNegotiationParams = $e->getParam('ZFContentNegotiationParameterData');
     if ($contentNegotiationParams) {
         $routeParameters = $contentNegotiationParams->getRouteParams();
     } else {
         $routeParameters = $routeMatch->getParams();
     }
     $parameterMatcher = new ParameterMatcher($e);
     // match route params to dispatchable parameters
     if ($this->wrappedCallable instanceof \Closure) {
         $callable = $this->wrappedCallable;
     } elseif (is_array($this->wrappedCallable) && is_callable($this->wrappedCallable)) {
         $callable = $this->wrappedCallable;
     } elseif (is_object($this->wrappedCallable) || is_null($this->wrappedCallable)) {
         $action = $routeMatch->getParam('action', 'not-found');
         $method = static::getMethodFromAction($action);
         $callable = is_null($this->wrappedCallable) && get_class($this) != __CLASS__ ? $this : $this->wrappedCallable;
         if (!method_exists($callable, $method)) {
             $method = 'notFoundAction';
         }
         $callable = [$callable, $method];
     } else {
         throw new \Exception('RPC Controller Not Understood');
     }
     $dispatchParameters = $parameterMatcher->getMatchedParameters($callable, $routeParameters);
     $result = call_user_func_array($callable, $dispatchParameters);
     $e->setParam('ZFContentNegotiationFallback', ['Zend\\View\\Model\\JsonModel' => ['application/json']]);
     $e->setResult($result);
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:31,代码来源:RpcController.php

示例4: isAuthorized

 /**
  * {@inheritDoc}
  */
 public function isAuthorized(MvcEvent $event)
 {
     $service = $this->getAuthorizationService();
     $match = $event->getRouteMatch();
     $controller = $match->getParam('controller');
     $action = $match->getParam('action');
     $request = $event->getRequest();
     $method = $request instanceof HttpRequest ? strtolower($request->getMethod()) : null;
     if ($service->isAllowed($this->getResourceName($controller)) || $service->isAllowed($this->getResourceName($controller, $action)) || $method && $service->isAllowed($this->getResourceName($controller, $method))) {
         return true;
     }
     $event->setParam('controller', $controller);
     $event->setParam('action', $action);
     $errorMessage = sprintf('You are not authorized to access %s:%s', $controller, $action);
     throw new UnauthorizedException($errorMessage, 403);
 }
开发者ID:coolms,项目名称:acl,代码行数:19,代码来源:Controller.php

示例5: testProcessPostRequestReturnsToken

    public function testProcessPostRequestReturnsToken()
    {
        $request = new Request();
        $request->setMethod('post');

        $parameters = new ParameterDataContainer();
        $parameters->setBodyParam('format', 'ZIP');
        $event = new MvcEvent();
        $event->setParam('ZFContentNegotiationParameterData', $parameters);

        $request->getHeaders()->addHeaderLine('Content-Type', 'application/json');
        $request->getHeaders()->addHeaderLine('Accept', 'application/json');

        $this->controller->setRequest($request);
        $this->controller->setEvent($event);

        $cwd = getcwd();
        chdir(__DIR__ . '/TestAsset');
        $result = $this->controller->indexAction();
        chdir($cwd);

        $this->assertInternalType('array', $result);
        $this->assertTrue(isset($result['token']));
        $this->assertTrue(isset($result['format']));
        $package = sys_get_temp_dir() . '/apigility_' . $result['token'] . '.' . $result['format'];
        $this->assertTrue(file_exists($package));

        return $result;
    }
开发者ID:jbarentsen,项目名称:drb,代码行数:29,代码来源:PackageControllerTest.php

示例6: createMvcEventWithException

 private function createMvcEventWithException()
 {
     $mvcEvent = new MvcEvent();
     $exception = new Exception('foo');
     $mvcEvent->setParam('exception', $exception);
     return $mvcEvent;
 }
开发者ID:neeckeloo,项目名称:newrelic,代码行数:7,代码来源:ErrorListenerTest.php

示例7: terminateEvent

 protected function terminateEvent(MvcEvent $event, $error, \Exception $exception)
 {
     $eventManager = $event->getApplication()->getEventManager();
     $event->setError($error);
     $event->setParam('exception', $exception);
     $event->stopPropagation(true);
     $eventManager->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
 }
开发者ID:aerisweather,项目名称:ZfAuth,代码行数:8,代码来源:Module.php

示例8: onRoute

 /**
  * Event callback to be triggered on dispatch, causes application error triggering
  * in case of failed authorization check
  *
  * @param MvcEvent $event
  *
  * @return void
  */
 public function onRoute(MvcEvent $event)
 {
     /* @var $service \BjyAuthorize\Service\Authorize */
     $service = $this->serviceLocator->get('BjyAuthorize\\Service\\Authorize');
     $match = $event->getRouteMatch();
     $routeName = $match->getMatchedRouteName();
     if ($service->isAllowed('route/' . $routeName)) {
         return;
     }
     $event->setError(static::ERROR);
     $event->setParam('route', $routeName);
     $event->setParam('identity', $service->getIdentity());
     $event->setParam('exception', new UnauthorizedException('You are not authorized to access ' . $routeName));
     /* @var $app \Zend\Mvc\Application */
     $app = $event->getTarget();
     $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
 }
开发者ID:kler,项目名称:BjyAuthorize,代码行数:25,代码来源:Route.php

示例9: testExecute_WhenExceptionIsNotFromAPI

 public function testExecute_WhenExceptionIsNotFromAPI()
 {
     $exception = new \Exception();
     $event = new MvcEvent();
     $event->setParam('exception', $exception);
     $this->loggerMock->expects($this->once())->method('crit')->with($exception);
     $this->testedObject->execute($event);
 }
开发者ID:omusico,项目名称:zf2-demo,代码行数:8,代码来源:LogExceptionListenerTest.php

示例10: testCanCreateFromCustomException

 public function testCanCreateFromCustomException()
 {
     $httpExceptionListener = new HttpExceptionListener([\InvalidArgumentException::class => Exception\Client\NotFoundException::class]);
     $this->event->setParam('exception', new \InvalidArgumentException('An error'));
     $httpExceptionListener->onDispatchError($this->event);
     $this->assertInstanceOf(Response::class, $this->event->getResponse());
     $this->assertEquals('An error', $this->event->getResponse()->getReasonPhrase());
     $this->assertTrue($this->event->propagationIsStopped());
 }
开发者ID:omusico,项目名称:zfr-rest,代码行数:9,代码来源:HttpExceptionListenerTest.php

示例11: testOnError_WithApiException

 public function testOnError_WithApiException()
 {
     $event = new MvcEvent();
     $event->setError("The resource doesn't support the specified HTTP verb.");
     $event->setParam('exception', new MethodNotAllowedException());
     $event->setResponse(new Response());
     $result = $this->testedObject->onError($event);
     $this->assertInstanceOf(JsonModel::class, $result);
 }
开发者ID:omusico,项目名称:zf2-demo,代码行数:9,代码来源:ResolveExceptionToJsonModelListenerTest.php

示例12: testFillEvent

 public function testFillEvent()
 {
     $event = new MvcEvent();
     $event->setParam('exception', new Exception\UnauthorizedException());
     $response = new HttpResponse();
     $event->setResponse($response);
     $listener = new ErrorListener();
     $listener->onError($event);
 }
开发者ID:neeckeloo,项目名称:recurly,代码行数:9,代码来源:ErrorListenerTest.php

示例13: testCatchesUnknownErrorTypes

 public function testCatchesUnknownErrorTypes()
 {
     $exception = new \Exception();
     $event = new MvcEvent();
     $event->setParam('exception', $exception)->setError('custom_error');
     $this->strategy->prepareExceptionViewModel($event);
     $response = $event->getResponse();
     $this->assertTrue($response->isServerError());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:9,代码来源:ExceptionStrategyTest.php

示例14: loadPage

 public function loadPage(MvcEvent $e)
 {
     $match = $e->getRouteMatch();
     $pageId = $match->getParam('page-id', null);
     if (null !== $pageId && is_numeric($pageId)) {
         $em = $this->doctrine->getEntityManager();
         $page = $em->find('Zcmf\\Application\\Model\\Page', $pageId);
         $e->setParam('page', $page);
     }
 }
开发者ID:bb-drummer,项目名称:Zcmf,代码行数:10,代码来源:Listener.php

示例15: onRoute

 public function onRoute(MvcEvent $event)
 {
     $err = RouteGuard::ERROR;
     $service = $this->serviceLocator->get('BjyAuthorize\\Service\\Authorize');
     /* @var $match \Zend\Mvc\Router\RouteMatch */
     $match = $event->getRouteMatch();
     $routeName = $match->getMatchedRouteName();
     $privilege = $match->getParam('xelax_admin_privilege');
     $privilegeParts = explode('/', $privilege);
     if (empty($privilege) || array_pop($privilegeParts) == 'subroute' || $service->isAllowed('xelax-route/' . $routeName, $privilege)) {
         return;
     }
     $event->setError($err);
     $event->setParam('route', $routeName);
     $event->setParam('identity', $service->getIdentity());
     $event->setParam('exception', new UnAuthorizedException('You are not authorized to access ' . $routeName));
     /* @var $app \Zend\Mvc\Application */
     $app = $event->getTarget();
     $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
 }
开发者ID:xelax90,项目名称:xelax-admin,代码行数:20,代码来源:ListController.php


注:本文中的Zend\Mvc\MvcEvent::setParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。