本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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'));
}
示例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"}"
}
示例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));
}
示例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();
}
示例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);
}
示例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'));
}