本文整理汇总了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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例6: createMvcEventWithException
private function createMvcEventWithException()
{
$mvcEvent = new MvcEvent();
$exception = new Exception('foo');
$mvcEvent->setParam('exception', $exception);
return $mvcEvent;
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
}
示例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);
}