本文整理汇总了PHP中Zend\Mvc\MvcEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::getRequest方法的具体用法?PHP MvcEvent::getRequest怎么用?PHP MvcEvent::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::getRequest方法的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: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
UriFactory::registerScheme('chrome-extension', 'Zend\\Uri\\Uri');
if (method_exists($e->getRequest(), 'getHeaders')) {
$headers = $e->getRequest()->getHeaders();
if ($headers->has('Origin') && $headers->has('X-Requested-With') && $headers->addHeaderLine('Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE, OPTIONS') && $headers->get('X-Requested-With')->getFieldValue() === 'com.ionicframework.notifycar') {
//convert to array because get method throw an exception
$headersArray = $headers->toArray();
$origin = $headersArray['Origin'];
if ($origin === 'file://') {
unset($headersArray['Origin']);
$headers->clearHeaders();
$headers->addHeaders($headersArray);
//$headers->addHeaderLine('Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE, OPTIONS');
//this is a valid uri
$headers->addHeaderLine('Origin', 'file://mobile');
} else {
if ($origin === 'chrome-extension') {
unset($headersArray['Origin']);
$headers->clearHeaders();
$headers->addHeaders($headersArray);
//$headers->addHeaderLine('Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE, OPTIONS');
//this is a valid uri
$headers->addHeaderLine('Origin', 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop');
//$headers->addHeaderLine('Origin', 'chrome-extension://aicmkgpgakddgnaphhhpliifpcfhicfo');
}
}
}
}
}
示例3: runControllerAction
/**
* @param $controllerName
* @param $action
* @param array $params
* @return string|\Zend\Stdlib\ResponseInterface
* @throws \Exception
*/
public function runControllerAction($controllerName, $action, $params = array())
{
$this->event->getRouteMatch()->setParam('controller', $controllerName)->setParam('action', $action);
foreach ($params as $key => $value) {
$this->event->getRouteMatch()->setParam($key, $value);
}
$serviceManager = $this->event->getApplication()->getServiceManager();
$controllerManager = $serviceManager->get('ControllerLoader');
/** @var AbstractActionController $controller */
$controller = $controllerManager->get($controllerName);
$controller->setEvent($this->event);
$result = $controller->dispatch($this->event->getRequest());
if ($result instanceof Response) {
return $result;
}
/** @var ViewManager $viewManager */
$viewManager = $serviceManager->get('ViewManager');
$renderingStrategy = $viewManager->getMvcRenderingStrategy();
$this->event->setViewModel($result);
/** @var ViewModel $result */
if (!$result->terminate()) {
$layout = new ViewModel();
$layoutTemplate = $renderingStrategy->getLayoutTemplate();
$layout->setTemplate($layoutTemplate);
$layout->addChild($result);
$this->event->setViewModel($layout);
}
$response = $renderingStrategy->render($this->event);
return $response;
}
示例4: __invoke
public function __invoke(MvcEvent $e)
{
$response = $e->getResponse();
$this->rateLimitService->consume($e->getRouteMatch(), $e->getRequest());
//var_dump($this->rateLimitService->getTopMeters('daily_limits'));exit;
$status = $this->rateLimitService->getLimitStatus($e->getRouteMatch(), $e->getRequest(), 'daily_limits');
if (!empty($status)) {
//add info headers
$headers = $response->getHeaders();
$headers->addHeaderLine('X-RateLimit-Limit', $status['limit']);
$headers->addHeaderLine('X-RateLimit-Remaining', $status['remaining']);
$headers->addHeaderLine('X-RateLimit-Reset', $status['reset']);
$response->setHeaders($headers);
}
if ($this->rateLimitService->isLimitExceeded()) {
//trigger the ratelimit exceeded event
$mvcLimitEvent = $this->mvcLimitEvent;
$response = $this->eventManager->trigger(MvcLimitEvent::EVENT_RATELIMIT_EXCEEDED, $mvcLimitEvent, function ($r) {
return $r instanceof Response;
});
$response = $response->last();
return $response;
} elseif ($this->rateLimitService->isLimitWarning()) {
//trigger the ratelimit warning event
$mvcLimitEvent = $this->mvcLimitEvent;
$response = $this->eventManager->trigger(MvcLimitEvent::EVENT_RATELIMIT_WARN, $mvcLimitEvent, function ($r) {
return $r instanceof Response;
});
$response = $response->last();
$e->setResponse($response);
}
}
示例5: onInvokation
protected function onInvokation(MvcEvent $e, $error = false)
{
$viewModel = $e->getResult();
$isJsonModel = $viewModel instanceof JsonModel;
$routeMatch = $e->getRouteMatch();
if ($routeMatch && $routeMatch->getParam('forceJson', false) || $isJsonModel || "json" == $e->getRequest()->getQuery('format') || "json" == $e->getRequest()->getPost('format')) {
if (!$isJsonModel) {
$model = new JsonModel();
if ($error) {
$model->status = 'error';
$model->message = $viewModel->message;
if ($viewModel->display_exceptions) {
if (isset($viewModel->exception)) {
$model->exception = $viewModel->exception->getMessage();
}
}
} else {
$model->setVariables($viewModel->getVariables());
}
$viewModel = $model;
$e->setResult($model);
$e->setViewModel($model);
}
$viewModel->setTerminal(true);
$strategy = new \Zend\View\Strategy\JsonStrategy(new \Zend\View\Renderer\JsonRenderer());
$view = $e->getApplication()->getServiceManager()->get('ViewManager')->getView();
$view->addRenderingStrategy(array($strategy, 'selectRenderer'), 10);
$view->addResponseStrategy(array($strategy, 'injectResponse'), 10);
}
}
示例6: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$serviceLocator = $e->getApplication()->getServiceManager();
$e->getApplication()->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) use($serviceLocator) {
if (!$e->getRequest() instanceof Request) {
return;
}
$request = $e->getRequest();
$config = $serviceLocator->get('Config');
$serviceName = isset($config['hermes']['service_name']) ? $config['hermes']['service_name'] : '';
$data = ['direction' => 'in', 'status' => 'success', 'destination' => ['service' => $serviceName, 'server' => $request->getUri()->getHost(), 'uri' => $request->getUriString()], 'source' => ['server' => $_SERVER['REMOTE_ADDR'], 'service' => $request->getHeader('X-Request-Name') ? $request->getHeader('X-Request-Name')->getFieldValue() : '', 'uri' => '']];
if (!$e->getRequest()->isGet()) {
$post = json_decode($e->getRequest()->getContent(), true, 100);
unset($post['password']);
$data['data'] = $post;
}
\LosLog\Log\RequestLogger::save($e->getRequest(), $data);
}, 100);
$hermes = $serviceLocator->get('hermes');
$em = $hermes->getEventManager();
$em->attach('request.post', function (Event $e) use($serviceLocator) {
/* @var \Hermes\Api\Client $hermes */
$hermes = $e->getTarget();
$request = $hermes->getZendClient()->getRequest();
$config = $serviceLocator->get('Config');
$serviceName = isset($config['hermes']['service_name']) ? $config['hermes']['service_name'] : '';
$data = ['direction' => 'out', 'status' => 'success', 'source' => ['service' => $serviceName, 'server' => $_SERVER['SERVER_ADDR'], 'uri' => $_SERVER['REQUEST_URI']], 'destination' => ['service' => $hermes->getServiceName(), 'server' => $request->getUri()->getHost(), 'uri' => $request->getUriString()], 'http_code' => $hermes->getZendClient()->getResponse()->getStatusCode()];
if (!$request->isGet()) {
$post = json_decode($request->getContent(), true, 100);
unset($post['password']);
$data['data'] = $post;
}
\LosLog\Log\RequestLogger::save($request, $data);
}, 100);
$em->attach('request.fail', function (Event $e) use($serviceLocator) {
/* @var \Hermes\Api\Client $hermes */
$hermes = $e->getTarget();
$request = $hermes->getZendClient()->getRequest();
$config = $serviceLocator->get('Config');
$serviceName = isset($config['hermes']['service_name']) ? $config['hermes']['service_name'] : '';
$data = ['direction' => 'out', 'status' => 'failed', 'source' => ['service' => $serviceName, 'server' => $_SERVER['SERVER_ADDR'], 'uri' => $_SERVER['REQUEST_URI']], 'destination' => ['service' => $hermes->getServiceName(), 'server' => $request->getUri()->getHost(), 'uri' => $request->getUriString()]];
if (!$request->isGet()) {
$post = json_decode($request->getContent(), true, 100);
unset($post['password']);
$data['data'] = $post;
}
$exception = $e->getParams();
$data['http_code'] = $exception->getCode();
$data['error'] = $exception->getMessage();
\LosLog\Log\RequestLogger::save($request, $data);
}, 100);
}
示例7: onRoute
/**
* Called after routing
*
* @param MvcEvent $event
*/
public function onRoute(MvcEvent $event)
{
$serviceManager = $event->getApplication()->getServiceManager();
/* @var RouteMatch $routeMatch */
$routeMatch = $event->getRouteMatch();
$language = '';
// check if the language is set by routing (parameter, domain name, etc)
if ($routeMatch->getParam('language') == '') {
// get route
$route = explode('/', $routeMatch->getMatchedRouteName());
//
$module = $route[0];
/** @var \Msingi\Cms\Settings $settings */
$settings = $event->getApplication()->getServiceManager()->get('Settings');
// get defaults from settings
$multilanguage = (bool) $settings->get($module . ':languages:multilanguage');
$language_default = $settings->get($module . ':languages:default');
$languages_enabled = $settings->get($module . ':languages:enabled');
if ($multilanguage && is_array($languages_enabled)) {
/** @var \Zend\Http\Request $request */
$request = $event->getRequest();
// try to get language from cookie
if ($request->getCookie('language') != '') {
$language = $event->getRequest()->getCookie('language');
}
// try to get language from browser
if ($language == '' && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$language = \Locale::getPrimaryLanguage(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']));
}
// fallback to default language if given one is not supported
if (!in_array($language, $languages_enabled)) {
$language = $language_default;
}
} else {
// not multilanguage module, use default language
$language = $language_default;
}
$routeMatch->setParam('language', $language);
} else {
$language = $routeMatch->getParam('language');
$language_default = $language;
}
// translator
$translator = $serviceManager->get('Translator');
$translator->setLocale($language)->setFallbackLocale($language_default);
// cache
$cache = $serviceManager->get('Application\\Cache');
if ($cache) {
$translator->setCache($cache);
}
}
示例8: routeEvent
/**
* Redirect old assets on sites that we do not control to new AWS urls
*/
public function routeEvent(MvcEvent $event)
{
$host = $event->getRequest()->getUri()->getHost();
if (!isset($this->domainRedirects[$host])) {
return null;
}
$event->getResponse()->setStatusCode(301);
/**
* @var $headers \Zend\Http\Headers
*/
$headers = $event->getResponse()->getHeaders();
$headers->addHeaderLine('location', $this->domainRedirects[$host] . $event->getRequest()->getUri()->getPath());
return $event->getResponse();
}
示例9: onDispatch
public function onDispatch(MvcEvent $e)
{
if (!$e->getRequest() instanceof ConsoleRequest) {
throw new RuntimeException('You can only use this action from a console!');
}
$migrations = $this->versionResolver->getAll($e->getRequest()->getParam('all'));
$list = [];
foreach ($migrations as $m) {
$list[] = sprintf("%s %s - %s", $m['applied'] ? '-' : '+', $m['version'], $m['description']);
}
$response = (empty($list) ? 'No migrations available.' : implode("\n", $list)) . "\n";
$e->setResult($response);
return $response;
}
示例10: collect
/**
* {@inheritdoc}
*/
public function collect(MvcEvent $mvcEvent)
{
if (PHP_VERSION_ID >= 50400) {
$start = $mvcEvent->getRequest()->getServer()->get('REQUEST_TIME_FLOAT');
} elseif (defined('REQUEST_MICROTIME')) {
$start = REQUEST_MICROTIME;
} else {
$start = $mvcEvent->getRequest()->getServer()->get('REQUEST_TIME');
}
if (!isset($this->data)) {
$this->data = array();
}
$this->data['start'] = $start;
$this->data['end'] = microtime(true);
}
示例11: outputFatalError
public function outputFatalError(ErrorException $exception, MvcEvent $e)
{
// Clean the buffer from previously badly rendered views
if (ob_get_level() >= 1) {
ob_end_clean();
}
$sm = $e->getApplication()->getServiceManager();
$request = $e->getRequest();
$manager = $sm->get('viewManager');
$renderer = $manager->getRenderer();
$config = $sm->get('Config');
$display = isset($config['view_manager']['display_exceptions']) ? $config['view_manager']['display_exceptions'] : null;
$layout = $manager->getLayoutTemplate();
$template = isset($config['view_manager']['exception_template']) ? $config['view_manager']['exception_template'] : null;
$viewType = get_class($manager->getViewModel());
// Console
if ($request instanceof ConsoleRequest || (bool) $display !== true) {
return;
}
// Get layout
$model = new $viewType();
$model->setTemplate($layout);
// Error page
if (null !== $template) {
$content = new $viewType(array('exception' => $exception, 'display_exceptions' => $display));
$content->setTemplate($template);
$result = $renderer->render($content);
$model->setVariables(['content' => $result, 'exception' => $exception]);
}
$this->triggerErrorEvent($exception, $e);
echo $renderer->render($model);
exit;
}
示例12: dispatch
public function dispatch(MvcEvent $event)
{
$request = $event->getRequest();
if ($request instanceof ConsoleRequest) {
return true;
}
$auth = new AuthenticationService();
//ALREADY LOGGED IN
// user has auth,
if ($auth->hasIdentity()) {
return true;
//NOT LOGGED IN
//
} else {
/** @var $request \Zend\Http\PhpEnvironment\Request */
$cookies = $request->getCookie();
/** @var $cookies \Zend\Http\Header\Cookie */
$userService = $this->getServiceLocator()->get('Stjornvisi\\Service\\User');
/** @var $user \Stjornvisi\Service\User */
if ($cookies && $cookies->offsetExists('backpfeifengesicht')) {
if (($user = $userService->getByHash($cookies->offsetGet('backpfeifengesicht'))) != false) {
$authAdapter = $this->getServiceLocator()->get('Stjornvisi\\Auth\\Adapter');
$authAdapter->setIdentifier($user->id);
$result = $auth->authenticate($authAdapter);
$result->isValid();
}
}
}
}
示例13: onPostLogin
public function onPostLogin(MvcEvent $e)
{
if (!$e->getRouteMatch()) {
return;
}
/** @var string $matchedRouteName */
$matchedRouteName = $e->getRouteMatch()->getMatchedRouteName();
if ($matchedRouteName !== 'login') {
return;
}
if (!$e->getRequest()->isPost()) {
return;
}
/** @var ZourceAuthenticationService $authenticationService */
$authenticationService = $e->getApplication()->getServiceManager()->get(AuthenticationService::class);
/** @var ManagerInterface $sessionManager */
$sessionManager = $e->getApplication()->getServiceManager()->get(ManagerInterface::class);
/** @var EntityManager $entityManager */
$entityManager = $e->getApplication()->getServiceManager()->get('doctrine.entitymanager.orm_default');
/** @var SessionEntity $respository */
$respository = $entityManager->getRepository(SessionEntity::class);
/** @var SessionEntity $session */
$session = $respository->find($sessionManager->getId());
$session->setAccount($authenticationService->getAccountEntity());
$entityManager->persist($session);
$entityManager->flush($session);
}
示例14: afterDispatch
public function afterDispatch(MvcEvent $e)
{
$controllerName = $e->getRouteMatch()->getMatchedRouteName();
if ($controllerName != 'login' && ($controllerName != 'application' && $controllerName != 'home')) {
$containerSession = new \Zend\Session\Container('cbol');
$e->getTarget()->layout()->repo = $containerSession->reportesVias;
$e->getTarget()->layout()->acceso = $containerSession->permisosUser;
$e->getTarget()->layout()->suge = $containerSession->sugerencias;
$auth = new \Zend\Authentication\AuthenticationService();
$response = $e->getResponse();
if (!$auth->hasIdentity()) {
$url = $e->getRequest()->getBaseUrl() . '/login';
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
$response->sendHeaders();
return $response;
} else {
$localAcl = new \Login\Model\permisos();
if (!$localAcl->isAllowed($auth->getIdentity()->perfil_id, $controllerName)) {
$this->onDispatchError($e, $controllerName);
} elseif (is_null($containerSession->idSession)) {
$url = $e->getRequest()->getBaseUrl() . '/login/logout';
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
$response->sendHeaders();
return $response;
} elseif ($e->getResponse()->getStatusCode() == 403) {
$this->onDispatchError($e, $controllerName);
}
}
}
}
示例15: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sharedEvents = $eventManager->getSharedManager();
$application = $e->getApplication();
$sm = $application->getServiceManager();
/*SETANDO BASE URL */
$e->getRequest()->setBaseUrl('/');
$basePathHelper = $sm->get('viewRenderer')->plugin('basePath');
/* @var $basePathHelper \Zend\View\Helper\BasePath */
$basePathHelper->setBasePath('/');
$sharedEvents->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($ev) use($sm) {
$auth = $ev->getApplication()->getServiceManager()->get('Zend\\Authentication\\AuthenticationService');
if ($auth->hasIdentity()) {
return;
}
if ($ev->getRouteMatch()->getParam('action') == 'login') {
return;
}
$target = $ev->getTarget();
$flash = $sm->get('ControllerPluginManager')->get('FlashMessenger')->addErrorMessage('Efetue login no sistema para acessar este recurso!');
return $target->redirect()->toUrl('/security/autenticacao/login');
//return;
}, 3);
$eventManager->attach('route', array($this, 'loadConfiguration'), 2);
}