當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。