/** * Initialize * * @return void */ public function initialize() { if ($this->isInitialized) { return; } // Special case for PostgreSQL inserts -- we need to provide an extra // clue so that the database knows how to write bytea data correctly: if ($this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql") { if (!is_object($this->featureSet)) { $this->featureSet = new Feature\FeatureSet(); } $eventFeature = new Feature\EventFeature(); $eventFeature->getEventManager()->attach(Feature\EventFeature::EVENT_PRE_INSERT, [$this, 'onPreInsert']); $this->featureSet->addFeature($eventFeature); } parent::initialize(); }
public function getServiceConfig() { return array('factories' => array('Cache\\Adapter\\MemcachedOptions' => function ($sm) { $config = $sm->get('config'); return new MemcachedOptions($config['memcached']); }, 'Cache\\Adapter\\Memcached' => function ($sm) { return new Memcached($sm->get('Cache\\Adapter\\MemcachedOptions')); }, "Application\\Listener\\MemcachedListener" => function ($sm) { $memcached = $sm->get('Cache\\Adapter\\Memcached'); $cacheListener = new MemcachedListener($memcached); return $cacheListener; }, 'Zend\\EventManager\\EventManager' => function ($sm) { $eventManager = new EventManager(); return $eventManager; }), 'initializers' => array('EventFeatureCacheAwareInterface' => function ($model, $serviceLocator) { if ($model instanceof EventFeatureCacheAwareInterface) { $logListener = $serviceLocator->get('Security\\Listener\\LogListener'); $eventFeature = new EventFeature(); $eventFeature->getEventManager()->attachAggregate($logListener); $model->setEventFeatureCache($eventFeature); } })); }
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')); }