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


PHP EventManager::attach方法代码示例

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


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

示例1: setUp

 /**
  * 
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 public function setUp()
 {
     vfsStream::setup(self::TEST_LOGPATH);
     $this->destfile = vfsStream::url(self::TEST_LOGPATH . '/test.log');
     date_default_timezone_set('Asia/Shanghai');
     $logger = new Logger();
     $logger->addWriter('stream', null, array('stream' => $this->destfile));
     $this->events = new EventManager();
     $this->events->attach(new AuthLoggerListener($logger));
 }
开发者ID:starflash,项目名称:MobilePf-ZF2-Example,代码行数:14,代码来源:AuthLoggerListenerTest.php

示例2: register

 public function register(Slim $app)
 {
     $app->container->singleton('cache', function () {
         return new FilesystemCache('tmp/cache/db');
     });
     $app->container->singleton('connection', function () {
         $dbOptions = (require 'config/connection.config.php');
         $config = new Configuration();
         return DriverManager::getConnection($dbOptions, $config);
     });
     $app->container->singleton('log', function () {
         $logger = new Logger('echale-gas');
         $logger->pushHandler(new StreamHandler('tmp/logs/app.log', LogLevel::DEBUG));
         return $logger;
     });
     $app->container->singleton('paginator', function () use($app) {
         return new PagerfantaPaginator($app->config('defaultPageSize'));
     });
     $app->container->singleton('paginatorFactory', function () use($app) {
         return new PaginatorFactory($app->paginator);
     });
     $app->container->singleton('proxiesConfiguration', function () use($app) {
         $config = new ProxyConfiguration();
         $config->setProxiesTargetDir('tmp/cache/proxies');
         spl_autoload_register($config->getProxyAutoloader());
         return $config;
     });
     $app->urlHelper = new TwigExtension();
     $app->container->singleton('twig', function () use($app) {
         $twig = new Twig();
         $twig->parserOptions = ['charset' => 'utf-8', 'cache' => realpath('tmp/cache/twig'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true];
         $twig->parserExtensions = [$app->urlHelper, new HalRendererExtension()];
         return $twig;
     });
     $app->container->singleton('controllerEvents', function () use($app) {
         $eventManager = new EventManager();
         // Ensure rendering is performed at the end by assigning a very low priority
         $eventManager->attach('postDispatch', new RenderResourceListener($app->twig), -100);
         $eventManager->attach('renderErrors', new RenderErrorsListener($app->twig), -100);
         return $eventManager;
     });
     $app->container->singleton('controller', function () use($app) {
         $controller = new RestController($app->request(), $app->response());
         $factory = new RestControllerProxyFactory($app->proxiesConfiguration, $app->controllerEvents);
         $controller = $factory->createProxy($controller);
         $factory->addEventManagement($controller);
         return $controller;
     });
     $app->view($app->twig);
 }
开发者ID:comphppuebla,项目名称:echale-gas-api,代码行数:50,代码来源:ApplicationContainer.php

示例3: let

 /**
  * @param \Zend\EventManager\EventManager $eventManager
  */
 public function let($eventManager)
 {
     $eventManager->trigger(Argument::cetera())->willReturn(true);
     $eventManager->setIdentifiers(Argument::cetera())->willReturn(true);
     $eventManager->attach(Argument::cetera())->willReturn(true);
     $this->setEventManager($eventManager);
 }
开发者ID:phpro,项目名称:zf-annotated-forms,代码行数:10,代码来源:BuilderSpec.php

示例4: testEventManagerHasDefaultListeners

 /**
  * 测试能正常注册身份验证过程中的事件监听器。
  */
 public function testEventManagerHasDefaultListeners()
 {
     $eventManager = new EventManager();
     $eventManager->attach($this->stub);
     $this->assertFalse($eventManager->getListeners(Event::EVENT_VERIFY_POST)->isEmpty());
     $this->assertFalse($eventManager->getListeners(Event::EVENT_TOKEN_POST)->isEmpty());
     $this->assertFalse($eventManager->getListeners(Event::EVENT_FAILURE)->isEmpty());
 }
开发者ID:starflash,项目名称:MobilePf-ZF2-Example,代码行数:11,代码来源:AuthLoggerListenerAbstractTest.php

示例5: createService

 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $logger \OcraServiceManager\ServiceManager\Logger */
     $logger = $serviceLocator->get('OcraServiceManager\\ServiceManager\\Logger');
     $eventManager = new EventManager();
     $eventManager->attach($logger);
     return $eventManager;
 }
开发者ID:rhodium289,项目名称:sandbox,代码行数:11,代码来源:EventManagerFactory.php

示例6: setUp

 public function setUp()
 {
     $resourceFactory = new UserRolesResourceFactory();
     /** @var \Zfegg\Admin\V1\Rest\UserRoles\UserRolesResource $resources */
     $resources = $resourceFactory($this->getServices());
     $events = new EventManager();
     $this->listener = $resources;
     $events->attach($this->listener);
 }
开发者ID:zfegg,项目名称:zfegg-admin,代码行数:9,代码来源:UserRolesResourceTest.php

示例7: testAttach

 public function testAttach()
 {
     $eventManager = new EventManager();
     $listener = new BodyClassListener(new BodyClass());
     $before = $eventManager->getListeners(\Zend\Mvc\MvcEvent::EVENT_DISPATCH);
     $this->assertCount(0, $before);
     $eventManager->attach($listener);
     $after = $eventManager->getListeners(\Zend\Mvc\MvcEvent::EVENT_DISPATCH);
     $this->assertCount(1, $after);
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:10,代码来源:BodyClassListenerTest.php

示例8: testFirewallOn

 /**
  * Test if firewall is on
  */
 public function testFirewallOn()
 {
     self::setUpFirewallOn();
     $spyListener = new SpyingFirewallListener();
     $spyListener->setServiceLocator($this->getServiceManager());
     $eventManager = new EventManager();
     $eventManager->attach($spyListener);
     $eventManager->trigger(FirewallEvent::EVENT_FIREWALL_DISPATCH);
     $this->assertTrue($spyListener->isFirewallEnabled());
 }
开发者ID:dollyaswin,项目名称:pyro,代码行数:13,代码来源:FirewallListenerTest.php

示例9: testAttachesToRouteEventAtNegativePriority

 public function testAttachesToRouteEventAtNegativePriority()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners('route');
     $this->assertEquals(1, count($listeners));
     $this->assertTrue($listeners->hasPriority(-41));
     $callback = $listeners->getIterator()->current()->getCallback();
     $test     = array_shift($callback);
     $this->assertSame($this->listener, $test);
 }
开发者ID:jbarentsen,项目名称:drb,代码行数:11,代码来源:VersionListenerTest.php

示例10: testGetDashboard

 public function testGetDashboard()
 {
     $eventManager = new EventManager();
     $eventManager->attach(DashboardEvent::DASHBOARD_RENDER_EVENT, function (DashboardEvent $event) {
         $viewModel = $event->getDashboardViewModel();
         $viewModel->setVariable('foo', 'bar');
     });
     $controller = new DashboardController();
     $controller->setEventManager($eventManager);
     $result = $controller->indexAction();
     $this->assertInstanceOf('Zend\\View\\Model\\ModelInterface', $result);
     $this->assertEquals('bar', $result->getVariable('foo'));
 }
开发者ID:ughly,项目名称:ugh-administration,代码行数:13,代码来源:DashboardControllerTest.php

示例11: indexAction

 public function indexAction()
 {
     $events = new EventManager();
     $events->attach('do', function ($e) {
         $event = $e->getName();
         $params = $e->getParams();
         printf('Handled event "%s" with parameter "%s"', $event, json_encode($params));
     });
     $params = array('foo' => 'bar', 'baz' => 'bat');
     $events->trigger('do', null, $params);
     //event, target, parameter
     //print : Handled event "do" with parameter "{"foo":"bar","baz":"bat"}"
 }
开发者ID:HaiderAliCoeus,项目名称:new-doct,代码行数:13,代码来源:AuthController.php

示例12: testListenerAttached

 public function testListenerAttached()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $this->assertEquals(1, count($listeners));
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $this->assertEquals(1, count($listeners));
     $events->detach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $this->assertEquals(0, count($listeners));
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $this->assertEquals(0, count($listeners));
 }
开发者ID:simplicity-ag,项目名称:NewRelic,代码行数:14,代码来源:ErrorListenerTest.php

示例13: setDbAdapter

 public function setDbAdapter(Adapter $adapter)
 {
     $this->adapter = $adapter;
     $this->resultSetPrototype = new HydratingResultSet(new ClassMethods(), new User());
     if (!$this->featureSet instanceof FeatureSet) {
         $this->featureSet = new FeatureSet();
     }
     $eventManager = new EventManager();
     $eventManager->attach(['preSelect', 'preUpdate', 'preDelete', 'preInsert'], function (EventInterface $event) {
         $sqlKey = strtolower(str_replace('pre', '', $event->getName()));
         echo $event->getParam($sqlKey)->getSqlString($event->getTarget()->getAdapter()->getPlatform()), '<br>';
     });
     $this->featureSet->addFeature(new EventFeature($eventManager));
     $this->initialize();
 }
开发者ID:quality520,项目名称:zend-framework-2-video-code,代码行数:15,代码来源:UserTable.php

示例14: testAddExistingNotChangedEntity

 public function testAddExistingNotChangedEntity()
 {
     $id = 111;
     $data = ['id' => $id, 'name' => 'some name', 'status' => 1];
     $originalEntity = new SimpleEntity($data);
     $changedEntity = clone $originalEntity;
     $this->identityMapOriginalMock->offsetSet($id, $originalEntity);
     $this->identityMapMock->offsetSet($id, $originalEntity);
     $this->dbMapperMock->expects($this->never())->method('toTableRow');
     $this->tableGatewayMock->expects($this->never())->method('updateByPrimaryKey');
     $callbackMock = $this->getMock('stdClass', array('onChangeEntity'));
     $callbackMock->expects($this->never())->method('onChangeEntity')->will($this->returnValue(true));
     $this->eventManagerMock->attach('entity:T4webBaseTest\\Domain\\Assets\\SimpleEntity:changed', array($callbackMock, 'onChangeEntity'));
     $this->dbRepository->add($changedEntity);
 }
开发者ID:t4web,项目名称:base,代码行数:15,代码来源:DbRepositoryTest.php

示例15: testPostDelete

 public function testPostDelete()
 {
     $closureHasRun = false;
     /** @var $event EventFeature\TableGatewayEvent */
     $event = null;
     $this->eventManager->attach('postDelete', function ($e) use(&$closureHasRun, &$event) {
         $event = $e;
         $closureHasRun = true;
     });
     $this->feature->postDelete($stmt = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface'), $result = $this->getMock('Zend\\Db\\Adapter\\Driver\\ResultInterface'));
     $this->assertTrue($closureHasRun);
     $this->assertInstanceOf('Zend\\Db\\TableGateway\\TableGateway', $event->getTarget());
     $this->assertEquals('postDelete', $event->getName());
     $this->assertSame($stmt, $event->getParam('statement'));
     $this->assertSame($result, $event->getParam('result'));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:16,代码来源:EventFeatureTest.php


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