Created
December 11, 2014 10:05
-
-
Save shinesoftware/8a3372a0fa72d92ce28e to your computer and use it in GitHub Desktop.
Zend Framework 2 - Listeners & Fatal error: Maximum function nesting level of '100' reached, aborting!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace ProductCategory\Listeners; | |
| use Zend\EventManager\EventManagerInterface; | |
| use Zend\EventManager\ListenerAggregateInterface; | |
| class CategoryListener implements ListenerAggregateInterface | |
| { | |
| protected $serviceManager; | |
| public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceManager){ | |
| $this->serviceManager = $serviceManager; | |
| } | |
| /** | |
| * @var \Zend\Stdlib\CallbackHandler[] | |
| */ | |
| protected $listeners = array(); | |
| /** | |
| * {@inheritDoc} | |
| */ | |
| public function attach(EventManagerInterface $events) | |
| { | |
| $sharedEvents = $events->getSharedManager(); | |
| $this->listeners[] = $sharedEvents->attach(\Zend\Mvc\MvcEvent::EVENT_FINISH, array($this, 'onFinish'), 9); | |
| } | |
| public function detach(EventManagerInterface $events) | |
| { | |
| foreach ($this->listeners as $index => $listener) { | |
| if ($events->detach($listener)) { | |
| unset($this->listeners[$index]); | |
| } | |
| } | |
| } | |
| public function onFinish($e) | |
| { | |
| $data = $e->getParam('data'); | |
| // Log the data | |
| $this->serviceManager->get('Zend\Log\Logger')->crit($data); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Product; | |
| use Product\Entity\ProductAttributesElementsEntity; | |
| use ProductCategory\Listeners\CategoryListener; | |
| use Zend\Mvc\ModuleRouteListener; | |
| use Zend\Mvc\MvcEvent; | |
| use Zend\Db\TableGateway\TableGateway; | |
| use Zend\Db\ResultSet\ResultSet; | |
| use Zend\ModuleManager\Feature\DependencyIndicatorInterface; | |
| class Module implements DependencyIndicatorInterface{ | |
| public function onBootstrap(MvcEvent $e) | |
| { | |
| $eventManager = $e->getApplication()->getEventManager(); | |
| $moduleRouteListener = new ModuleRouteListener(); | |
| $moduleRouteListener->attach($eventManager); | |
| $sm = $e->getApplication()->getServiceManager(); | |
| // $eventManager->attach(new ProductListener($sm)); | |
| $eventManager->attach(new CategoryListener($sm)); | |
| } | |
| /** | |
| * Check the dependency of the module | |
| * (non-PHPdoc) | |
| * @see Zend\ModuleManager\Feature.DependencyIndicatorInterface::getModuleDependencies() | |
| */ | |
| public function getModuleDependencies() | |
| { | |
| return array(); | |
| } | |
| public function getConfig() | |
| { | |
| return include __DIR__ . '/config/module.config.php'; | |
| } | |
| public function getAutoloaderConfig() | |
| { | |
| return array( | |
| 'Zend\Loader\StandardAutoloader' => array( | |
| 'namespaces' => array( | |
| __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, | |
| __NAMESPACE__ . "Admin" => __DIR__ . '/src/' . __NAMESPACE__ . "Admin", | |
| __NAMESPACE__ . "Settings" => __DIR__ . '/src/' . __NAMESPACE__ . "Settings", | |
| __NAMESPACE__ . "Category" => __DIR__ . '/src/' . __NAMESPACE__ . "Category", | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment