本文整理汇总了PHP中Zend\EventManager\EventManager::attachAggregate方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::attachAggregate方法的具体用法?PHP EventManager::attachAggregate怎么用?PHP EventManager::attachAggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventManager
的用法示例。
在下文中一共展示了EventManager::attachAggregate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanDetachListenersFromEventManager
public function testCanDetachListenersFromEventManager()
{
$events = new EventManager();
$events->attachAggregate($this->strategy);
$this->assertEquals(1, count($events->getListeners(MvcEvent::EVENT_RENDER)));
$events->detachAggregate($this->strategy);
$this->assertEquals(0, count($events->getListeners(MvcEvent::EVENT_RENDER)));
}
示例2: testDetachesListeners
public function testDetachesListeners()
{
$events = new EventManager();
$events->attachAggregate($this->listener);
$listeners = $events->getListeners('dispatch');
$this->assertEquals(1, count($listeners));
$events->detachAggregate($this->listener);
$listeners = $events->getListeners('dispatch');
$this->assertEquals(0, count($listeners));
}
示例3: testDetachesListeners
public function testDetachesListeners()
{
$events = new EventManager();
$events->attachAggregate($this->listener);
$listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
$this->assertEquals(2, count($listeners));
$events->detachAggregate($this->listener);
$listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
$this->assertEquals(0, count($listeners));
}
示例4: register
/**
* @SWG\Property(name="station_id",type="integer",description="Unique identifier of the gas station")
* @SWG\Property(name="name",type="string",description="Name of the gas station")
* @SWG\Property(name="social_reason",type="string",description="Official name of the gas station")
* @SWG\Property(name="address_line_1",type="string",description="Street name and number of the gas station")
* @SWG\Property(name="address_line_2",type="string",description="Neighborhood name of the gas station")
* @SWG\Property(name="location",type="string",description="State and city name where the gas station is located")
* @SWG\Property(name="latitude",type="double",description="Latitude coordinate")
* @SWG\Property(name="longitude",type="double",description="Longitude coordinate")
* @SWG\Property(name="created_at",type="string",format="date-format",description="Registration date of the gas station")
* @SWG\Property(name="last_updated_at",type="string",format="date-format",description="Most recent date in which the gas station was edited")
*/
public function register(Slim $app)
{
$app->container->singleton('station', function () use($app) {
return new Model($app->stationTable, $app->stationValidator, $app->paginatorFactory);
});
$app->container->singleton('stationFormatter', function () use($app) {
return new ResourceFormatter($app->urlHelper, 'station', 'station_id');
});
$app->container->singleton('stationsFormatter', function () use($app) {
return new CollectionFormatter($app->urlHelper, 'stations', $app->stationFormatter);
});
$app->container->singleton('stationEvents', function () use($app) {
$eventManager = new EventManager();
$specification = new ChainedSpecification();
$specification->addSpecification(new PaginationSpecification($app->config('defaultPageSize')));
$specification->addSpecification(new GeolocationSpecification());
$eventManager->attach('postFindAll', new QuerySpecificationListener($specification));
$eventManager->attachAggregate(new HasTimestampListener());
$eventManager->attachAggregate(new CacheListener($app->cache, $app->request()->getPathInfo()));
return $eventManager;
});
$app->container->singleton('stationTable', function () use($app) {
$stationTable = new StationTable('stations', $app->connection);
$factory = new TableProxyFactory($app->proxiesConfiguration, $app->stationEvents);
$stationTable = $factory->createProxy($stationTable);
$factory->addEventManagement($stationTable);
return $stationTable;
});
$app->container->singleton('stationValidator', function () use($app) {
return new ValitronValidator(require 'config/validations/stations.config.php');
});
$app->container->singleton('stationController', function () use($app) {
$app->controller->setModel($app->station);
$app->controllerEvents->attach('postDispatch', new FormatResourceListener($app->stationFormatter));
return $app->controller;
});
$app->container->singleton('stationsController', function () use($app) {
$app->controller->setModel($app->station);
$app->controllerEvents->attach('postDispatch', new FormatResourceListener($app->stationsFormatter));
return $app->controller;
});
}
示例5: testDetachesListeners
public function testDetachesListeners()
{
$events = new EventManager();
$events->attachAggregate($this->strategy);
$listeners = $events->getListeners('renderer');
$this->assertEquals(1, count($listeners));
$listeners = $events->getListeners('response');
$this->assertEquals(1, count($listeners));
$events->detachAggregate($this->strategy);
$listeners = $events->getListeners('renderer');
$this->assertEquals(0, count($listeners));
$listeners = $events->getListeners('response');
$this->assertEquals(0, count($listeners));
}
示例6: testListenerAttachesDispatchEventAtExpectedPriority
public function testListenerAttachesDispatchEventAtExpectedPriority()
{
$events = new EventManager();
$events->attachAggregate($this->listener);
$listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
$expectedCallback = [$this->listener, 'injectActionHandles'];
$expectedPriority = 1000;
$found = false;
foreach ($listeners as $listener) {
$callback = $listener->getCallback();
if ($callback === $expectedCallback) {
if ($listener->getMetadatum('priority') == $expectedPriority) {
$found = true;
break;
}
}
}
$this->assertTrue($found, 'Listener not found');
}
示例7: attach
/**
*
* @param ListenerAggregateInterface $listener
*/
public function attach(ListenerAggregateInterface $listener)
{
$this->eventManager->attachAggregate($listener);
}
示例8: testPrepareExceptionRendersPreviousMessages
public function testPrepareExceptionRendersPreviousMessages()
{
$events = new EventManager();
$events->attachAggregate($this->strategy);
$messages = array('message foo', 'message bar', 'deepest message');
$exception = null;
$i = 0;
do {
$exception = new \Exception($messages[$i], null, $exception);
$i++;
} while ($i < count($messages));
$event = new MvcEvent(MvcEvent::EVENT_DISPATCH_ERROR, null, array('exception' => $exception));
$event->setError('user-defined-error');
$events->trigger($event, null, array('exception' => $exception));
//$this->strategy->prepareExceptionViewModel($event);
foreach ($messages as $message) {
$this->assertContains($message, $event->getResult()->getResult(), sprintf('Not all errors are rendered'));
}
}