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


PHP MvcEvent::getTarget方法代码示例

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


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

示例1: prepareViewModel

 public function prepareViewModel(MvcEvent $event, $action)
 {
     if ($event->getTarget()->forward()->getNumNestedForwards() > 0) {
         return $event->getResult();
     }
     $result = $event->getResult();
     $response = $event->getResponse();
     $response->setStatusCode($result->getStatusCode());
     $response->getHeaders()->addHeaders($result->getHeaders());
     $controller = $event->getTarget();
     $viewModel = $controller->acceptableViewModelSelector($controller->getOptions()->getAcceptCriteria());
     if ($vars = $result->getSerializedModel()) {
         $viewModel->setVariables($vars);
     }
     //set the template
     if ($viewModel instanceof JsonModel && count($viewModel->getVariables()) == 0) {
         if ($response->getStatusCode() == 200) {
             $response->setStatusCode(204);
         }
         return $response;
     } elseif ($viewModel->getTemplate() == null) {
         $viewModel->setTemplate($controller->getOptions()->getTemplates()[$action]);
     }
     $event->setResult($viewModel);
     return $viewModel;
 }
开发者ID:zoopcommerce,项目名称:shard-module,代码行数:26,代码来源:PrepareViewModelListener.php

示例2: layoutChange

 public function layoutChange(MvcEvent $event)
 {
     // Change By Route Defaults
     $routeMatch = $event->getRouteMatch();
     if ($routeMatch && ($layout = $routeMatch->getParam('layout', false))) {
         $event->getTarget()->layout($layout);
         return;
     }
     /** @var \Zend\Http\PhpEnvironment\Request $request */
     $request = $event->getRequest();
     $uri = $request->getServer('REQUEST_URI');
     $config = $this->getConfig($event->getParam('application')->getConfig());
     // Change Layout by URI
     foreach ($config['uri'] as $var => $value) {
         $position = strpos($var, '*');
         if ($position !== false) {
             $uri = substr($uri, 0, $position);
             $var = substr($var, 0, $position);
         }
         if ($var == $uri) {
             if (method_exists($target = $event->getTarget(), 'layout')) {
                 $target->layout($value);
             } else {
                 $event->getViewModel()->setTemplate($value);
             }
         }
     }
 }
开发者ID:marcusamatos,项目名称:jvslayout,代码行数:28,代码来源:LayoutChangeListener.php

示例3: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $eventManager = $app->getEventManager();
     #$eventManager        = $e->getApplication()->getEventManager();
     $eventManager->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $config = $e->getApplication()->getServiceManager()->get('config');
         if (isset($config['module_layouts'][$moduleNamespace])) {
             $controller->layout($config['module_layouts'][$moduleNamespace]);
         }
     }, 100);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $shared = $eventManager->getSharedManager();
     $sm = $app->getServiceManager();
     $shared->attach('ZfcUser\\Service\\User', 'register.post', function ($e) use($sm) {
         $userService = $e->getTarget();
         $sm = $userService->getServiceManager();
         $em = $sm->get('doctrine.entitymanager.orm_default');
         $newUser = $e->getParam('user');
         #$registrationForm = $e->getParam('form');
         $config = $sm->get('config');
         $criteria = array('roleId' => $config['bjyauthorize']['new_user_default_role']);
         $defaultUserRole = $em->getRepository('ErsBase\\Entity\\UserRole')->findOneBy($criteria);
         if ($defaultUserRole !== null) {
             $newUser->addRole($defaultUserRole);
             $em->persist($newUser);
             $em->flush();
         }
     });
 }
开发者ID:odegroot,项目名称:ers,代码行数:34,代码来源:Module.php

示例4: 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);
             }
         }
     }
 }
开发者ID:nathalysalamanca,项目名称:Observatorio,代码行数:32,代码来源:Module.php

示例5: handleControllerCannotDispatchRequest

 public function handleControllerCannotDispatchRequest(MvcEvent $e)
 {
     $action = $e->getRouteMatch()->getParam('action');
     $controller = get_class($e->getTarget());
     // error-controller-cannot-dispatch
     if (!method_exists($e->getTarget(), $action . 'Action')) {
         $logText = 'The requested controller ' . $controller . ' was unable to dispatch the request : ' . $action . 'Action';
         //you can do logging, redirect, etc here..
         echo $logText;
     }
 }
开发者ID:oussaka,项目名称:magasins-feedback,代码行数:11,代码来源:Module.php

示例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);
 }
开发者ID:mt-olympus,项目名称:hermes-loslog,代码行数:52,代码来源:Module.php

示例7: flush

 public function flush(MvcEvent $event)
 {
     if ($event->getTarget()->forward()->getNumNestedForwards() > 0) {
         return $event->getResult();
     }
     $options = $event->getTarget()->getOptions();
     $options->getModelManager()->flush();
     if (!($flushExceptions = $options->getExceptionSubscriber()->getFlushExceptions())) {
         return $event->getResult();
     } else {
         return $this->prepareExceptions($flushExceptions, $options->getExceptionSerializer());
     }
 }
开发者ID:zoopcommerce,项目名称:shard-module,代码行数:13,代码来源:FlushListener.php

示例8: unserializeSingle

 public function unserializeSingle(MvcEvent $event, $mode)
 {
     if (count($event->getParam('deeperResource')) > 0 || ($result = $event->getResult())) {
         return $event->getResult();
     }
     $data = $event->getParam('data');
     $id = $event->getParam('id');
     $options = $event->getTarget()->getOptions();
     if ($property = $options->getProperty()) {
         $data[$property] = $id;
     }
     $result = new Result($event->getTarget()->getOptions()->getManifest()->getServiceManager()->get('unserializer')->fromArray($data, $event->getTarget()->getOptions()->getClass(), $event->getParam('document'), $mode));
     $event->setResult($result);
     return $result;
 }
开发者ID:zoopcommerce,项目名称:shard-module,代码行数:15,代码来源:UnserializeListener.php

示例9: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $application = $e->getApplication();
     $sm = $application->getServiceManager();
     $sharedManager = $eventManager->getSharedManager();
     //Setting layouts
     $sharedManager->attach('Zend\\Mvc\\Controller\\AbstractController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $config = $e->getApplication()->getServiceManager()->get('config');
         if (isset($config['module_layouts'][$moduleNamespace])) {
             $controller->layout($config['module_layouts'][$moduleNamespace]);
         }
     }, 100);
     $router = $sm->get('router');
     $request = $sm->get('request');
     $matchedRoute = $router->match($request);
     if (null !== $matchedRoute) {
         //Check the Authentication in every controller different with Login
         //If there is no identity this will redirect to Login
         $sharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function () use($sm) {
             $sm->get('ControllerPluginManager')->get('Authentication')->isAuthtenticated();
         }, 2);
         // @todo implement ACL
         //Check ACL and show the menu
         //$sharedManager->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function() use ($sm) {
         //    $sm->get('ControllerPluginManager')->get('Privileges')->doAuthorization();
         //}, 2);
     }
 }
开发者ID:rhionair3,项目名称:myzend,代码行数:34,代码来源:Module.php

示例10: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) {
         $auth = $e->getApplication()->getServiceManager()->get("Auth_Service");
         $application = $e->getApplication();
         $viewModel = $application->getMvcEvent()->getViewModel();
         $viewModel->UserAuth = false;
         if ($auth->hasIdentity()) {
             $viewModel->UserAuth = true;
             $viewModel->UserName = $auth->getStorage()->read()->name;
         }
         $routeMatch = $e->getRouteMatch();
         $controller = $routeMatch->getParam('controller');
         $whitelist = array('Customers\\Controller\\Login');
         if (!in_array($controller, $whitelist)) {
             if (!$auth->hasIdentity()) {
                 $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
                     $controller = $e->getTarget();
                     $controller->plugin('redirect')->toRoute('customers');
                 }, 100);
             }
         }
     });
     //        $config  = new StandardConfig();
     //        $config->setOptions(array(
     //            'remember_me_seconds' => 10,
     //            'name'                => 'zf2',
     //        ));
     //        $manager = new SessionManager($config);
 }
开发者ID:AlexandrKozyr,项目名称:ver_site,代码行数:33,代码来源:Module.php

示例11: addRoutes

 /**
  * addRoutes Event Handler
  * set static pages routes
  * 
  * @access public
  * @param MvcEvent $event
  */
 public function addRoutes(MvcEvent $event)
 {
     $serviceManager = $event->getTarget()->getServiceManager();
     $routeEvent = $serviceManager->get('CMS\\Event\\RouteEvent');
     $routeConfig = $routeEvent->addStaticPagesRoutes($event);
     $this->addedRoutes = $routeConfig;
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:14,代码来源:Module.php

示例12: onBootstrap

 /**
  * Override default rendering strategy
  *
  * @param MvcEvent $e
  */
 public function onBootstrap(MvcEvent $e)
 {
     // attach the JSON view strategy
     $app = $e->getTarget();
     /** @var ServiceLocator $locator */
     $locator = $app->getServiceManager();
     /**
      * @var View $view
      */
     $view = $locator->get('ZendViewView');
     /**
      * @var ViewJsonStrategyFactory $strategy
      */
     $strategy = $locator->get('ViewJsonStrategy');
     $view->getEventManager()->attach($strategy, 100);
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     //Add listener to check the response
     // Allow possibility to return a simple array
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'));
     //Add listener for rendering the error
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'onRenderError'));
     //Add listener to finish the execution of request
     $eventManager->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish'));
 }
开发者ID:sarancea,项目名称:ciklum,代码行数:31,代码来源:Module.php

示例13: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $application = $e->getApplication();
     $serviceManager = $application->getServiceManager();
     $eventManager = $application->getEventManager();
     $sharedManager = $eventManager->getSharedManager();
     // DISPATCH EVENT
     $sharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         if ($moduleNamespace == 'Frontend') {
             // frontend layout
             // wenn der benutzer eingeloggt ist darf er das admin panel betreten?
             $authService = $e->getApplication()->getServiceManager()->get('AuthService');
             // normal layout
             $controller->layout('layout/frontend');
             /**
                             if( $authService->isLoggedIn() ) {
                                 // layout für registrierte user
                     			$controller->layout('layout/frontend/registered');
                             } else {
                                 // normal layout unregistriert
                                 $controller->layout('layout/frontend');
                             }
                             **/
         }
     }, 50);
 }
开发者ID:GlitchedMan,项目名称:armasquads,代码行数:29,代码来源:Module.php

示例14: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     //$eventManager->attach(MvcEvent::EVENT_DISPATCH,array($this,'authPreDispatch'),1);
     /**
      * This allows to set the layout by module by action. By default
      * it gets layout\layout. This gets the modules from module_layouts
      * array in module.config.php.
      */
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $controllerName = explode('\\', $controllerClass);
         $controllerName = str_replace('Controller', '', array_pop($controllerName));
         $config = $e->getApplication()->getServiceManager()->get('config');
         $routeMatch = $e->getRouteMatch();
         $actionName = strtolower($routeMatch->getParam('action', 'not-found'));
         // get the action name
         if (isset($config['module_layouts'][$moduleNamespace][$controllerName][$actionName])) {
             $controller->layout($config['module_layouts'][$moduleNamespace][$controllerName][$actionName]);
         } elseif (isset($config['module_layouts'][$moduleNamespace][$controllerName]['default'])) {
             $controller->layout($config['module_layouts'][$moduleNamespace][$controllerName]['default']);
         }
     }, -100);
 }
开发者ID:elericuz,项目名称:clearingservice,代码行数:28,代码来源:Module.php

示例15: loadConfiguration

 public function loadConfiguration(MvcEvent $e)
 {
     $controller = $e->getTarget();
     $user_session = new Container('usuario');
     $controller->layout()->nome = trim(substr($user_session->nome, 0, 16));
     $controller->layout()->foto = $user_session->foto ? "/fotos/" . str_replace(" ", "_", $user_session->foto) : "/fotos/default.jpg";
 }
开发者ID:lucasfbr,项目名称:assistente,代码行数:7,代码来源:Module.php


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