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


PHP MvcEvent::setApplication方法代码示例

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


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

示例1: bootstrap

 public function bootstrap()
 {
     $event = new MvcEvent();
     $event->setApplication($this);
     $event->setTarget($this);
     $this->getEventManager()->trigger(MvcEvent::EVENT_BOOTSTRAP, $event);
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:7,代码来源:MockApplication.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: 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

示例4: bootstrap

 public function bootstrap()
 {
     $event = new MvcEvent();
     $event->setApplication($this);
     $event->setTarget($this);
     $this->getEventManager()->trigger('bootstrap', $event);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:7,代码来源:MockApplication.php

示例5: getMvcEvent

 /**
  * @param  EventManager $em
  * @return MvcEvent
  */
 protected function getMvcEvent($em)
 {
     $event = new MvcEvent();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('EventManager', $em)->setService('Request', new HttpRequest())->setService('Response', new HttpResponse());
     $application = new Application(array(), $serviceManager);
     $event->setApplication($application);
     return $event;
 }
开发者ID:simplicity-ag,项目名称:NewRelic,代码行数:13,代码来源:ModuleTest.php

示例6: 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

示例7: setUpMvcEvent

 public function setUpMvcEvent($app, $request, $response)
 {
     $event = new MvcEvent();
     $event->setTarget($app);
     $event->setApplication($app)->setRequest($request)->setResponse($response);
     $r = new ReflectionProperty($app, 'event');
     $r->setAccessible(true);
     $r->setValue($app, $event);
     return $app;
 }
开发者ID:nuxwin,项目名称:zf-apigility,代码行数:10,代码来源:ApplicationTest.php

示例8: testCurrentRouteNameViewModelVariableIsSetOnBootstrap

 public function testCurrentRouteNameViewModelVariableIsSetOnBootstrap()
 {
     $currentRouteName = self::class;
     $application = $this->setUpApplication($currentRouteName);
     $mvcEvent = new MvcEvent();
     $mvcEvent->setApplication($application);
     $module = new Module();
     $module->onBootstrap($mvcEvent);
     $viewModel = $mvcEvent->getViewModel();
     $this->assertEquals($currentRouteName, $viewModel->getVariable('__currentRouteName'));
 }
开发者ID:noiselabs,项目名称:zf-debug-utils,代码行数:11,代码来源:ModuleTest.php

示例9: testPluginManagers

 public function testPluginManagers()
 {
     $sm = $this->getServiceManager();
     $app = $sm->get('Application');
     $event = new MvcEvent();
     $event->setApplication($app);
     $module = new Module();
     $module->onBootstrap($event);
     $connectionManager = $sm->get('HumusAmqpModule\\PluginManager\\Connection');
     $this->assertInstanceOf('HumusAmqpModule\\PluginManager\\Connection', $connectionManager);
 }
开发者ID:vitapublic,项目名称:HumusAmqpModule,代码行数:11,代码来源:ModuleTest.php

示例10: testOnBootstrapListenersWithConsoleRequest

 public function testOnBootstrapListenersWithConsoleRequest()
 {
     $module = new Module();
     $application = $this->createApplication();
     $sm = $application->getServiceManager();
     $sm->setAllowOverride(true);
     $sm->setService('Request', new ConsoleRequest());
     $em = $application->getEventManager();
     $event = new MvcEvent();
     $event->setApplication($application);
     $module->onBootstrap($event);
 }
开发者ID:hummer2k,项目名称:conlayout,代码行数:12,代码来源:ModuleTest.php

示例11: setUp

 protected function setUp()
 {
     $serviceManager = Bootstrap::getServiceManager();
     $this->controller = new IndexController();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('controller' => 'index'));
     $this->event = new MvcEvent();
     $config = $serviceManager->get('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('AuthService', new AuthenticationService(new Storage\NonPersistent(), new TestAdapter()));
     $albumTableMock = $this->getMockBuilder('Zend\\Mvc\\Controller\\ControllerManager')->disableOriginalConstructor()->getMock();
     $albumTableMock->expects($this->any())->method('get')->will($this->returnValue($this->controller));
     $serviceManager->setService('ControllerManager', $albumTableMock);
     $this->event->setApplication(new Application($config, $serviceManager));
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($serviceManager);
 }
开发者ID:gontero,项目名称:gontero-acl,代码行数:21,代码来源:AuthorizedListenerTest.php

示例12: 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);
     $services = new Locator();
     $plugins = $this->plugins = new PluginManager();
     $plugins->setServiceLocator($services);
     $controllers = $this->controllers = new ControllerManager();
     $controllers->setFactory('forward', function () use($plugins) {
         $controller = new ForwardController();
         $controller->setPluginManager($plugins);
         return $controller;
     });
     $controllers->setInvokableClass('ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFq', 'ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFqController');
     $controllers->setServiceLocator($services);
     $controllerLoader = function () use($controllers) {
         return $controllers;
     };
     $services->add('ControllerLoader', $controllerLoader);
     $services->add('ControllerManager', $controllerLoader);
     $services->add('ControllerPluginManager', function () use($plugins) {
         return $plugins;
     });
     $services->add('Zend\\ServiceManager\\ServiceLocatorInterface', function () use($services) {
         return $services;
     });
     $services->add('EventManager', function () use($mockEventManager) {
         return $mockEventManager;
     });
     $services->add('SharedEventManager', function () use($mockSharedEventManager) {
         return $mockSharedEventManager;
     });
     $this->controller = new SampleController();
     $this->controller->setEvent($event);
     $this->controller->setServiceLocator($services);
     $this->controller->setPluginManager($plugins);
     $this->plugin = $this->controller->plugin('forward');
 }
开发者ID:noopable,项目名称:zf2,代码行数:50,代码来源:ForwardTest.php

示例13: testOnBootstrap

 public function testOnBootstrap()
 {
     $event = new MvcEvent();
     $application = new Application([], Bootstrap::getServiceManager());
     $em = new EventManager();
     $application->setEventManager($em);
     $event->setApplication($application);
     $isConsole = Console::isConsole();
     Console::overrideIsConsole(false);
     $this->module->onBootstrap($event);
     Console::overrideIsConsole($isConsole);
     $this->assertCount(1, $em->getListeners(MvcEvent::EVENT_DISPATCH));
     $this->assertCount(1, $em->getListeners(MvcEvent::EVENT_RENDER));
 }
开发者ID:hummer2k,项目名称:convarnish,代码行数:14,代码来源:ModuleTest.php

示例14: __Construct

 public function __Construct()
 {
     $env = getenv("DB");
     switch ($env) {
         case $env == "sqlite":
             $dbfilename = "schema.sqlite.sql";
             $configFileName = "sqlite.config.php";
             break;
         case $env == "mysql":
             $dbfilename = "schema.sql";
             $configFileName = "mysql.config.php";
             break;
         case $env == "pgsql":
             $dbfilename = "schema.pgsql.sql";
             $configFileName = "pgsql.config.php";
             break;
     }
     $configuration = (include __DIR__ . '/TestConfiguration.php');
     if (isset($configuration['output_buffering']) && $configuration['output_buffering']) {
         ob_start();
         // required to test sessions
     }
     $this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($configuration['service_manager']) ? $configuration['service_manager'] : array()));
     $this->serviceManager->setService('ApplicationConfig', $configuration);
     $this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
     /** @var $moduleManager \Zend\ModuleManager\ModuleManager */
     $moduleManager = $this->serviceManager->get('ModuleManager');
     $moduleManager->loadModules();
     $this->serviceManager->setAllowOverride(true);
     $application = $this->serviceManager->get('Application');
     $event = new MvcEvent();
     $event->setTarget($application);
     $event->setApplication($application)->setRequest($application->getRequest())->setResponse($application->getResponse())->setRouter($this->serviceManager->get('Router'));
     /// lets create user's table
     $em = $this->serviceManager->get("doctrine.entitymanager.orm_default");
     $conn = $em->getConnection();
     if (file_exists(__DIR__ . "/../vendor/zf-commons/zfc-user/data/{$dbfilename}")) {
         $sql = file_get_contents(__DIR__ . "/../vendor/zf-commons/zfc-user/data/{$dbfilename}");
     } elseif (file_exists(__DIR__ . "/../../../../vendor/zf-commons/zfc-user/data/{$dbfilename}")) {
         $sql = file_get_contents(__DIR__ . "/../../../../vendor/zf-commons/zfc-user/data/{$dbfilename}");
     } else {
         throw new \Exception("please check the zfc user sql file", 500);
     }
     $stmt = $conn->prepare($sql);
     try {
         $stmt->execute();
     } catch (Exception $exc) {
     }
 }
开发者ID:tawfekov,项目名称:zf2entityaudit,代码行数:49,代码来源:Bootstrap.php

示例15: testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult

 public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult()
 {
     //Register console service
     $sm = new ServiceManager();
     $sm->setService('console', new ConsoleAdapter());
     $mockApplication = new MockApplication();
     $mockApplication->setServiceManager($sm);
     $event = new MvcEvent();
     $event->setApplication($mockApplication);
     $model = new Model\ViewModel(array('content' => 'Page not found'));
     $response = new Response();
     $event->setResult($model);
     $event->setResponse($response);
     $this->strategy->render($event);
     $content = $response->getContent();
     $this->assertNotContains('Page not found', $content);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:17,代码来源:DefaultRenderingStrategyTest.php


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