Created
April 30, 2012 17:49
-
-
Save fritz-gerneth/2560437 to your computer and use it in GitHub Desktop.
This file contains 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 Test; | |
use \Zend\EventManager\EventCollection, | |
\Zend\EventManager\EventManagerAware, | |
\Zend\Di\Locator, | |
\Zend\EventManager\SharedEventCollectionAware, | |
\Zend\EventManager\SharedEventCollection; | |
class Collection implements SharedEventCollectionAware | |
{ | |
protected $listeners; | |
protected $counter = 0; | |
public function __construct() | |
{ | |
$this->listeners = array(); | |
} | |
public function addListener(Listener $listener) | |
{ | |
$this->listeners[] = $listener; | |
} | |
public function setSharedCollections(SharedEventCollection $sharedEventCollection) | |
{ | |
$this->counter++; | |
echo "Counter Collection: " . $this->counter . "<br />"; | |
//\Zend\Debug::dump($sharedEventCollection); | |
} | |
} |
This file contains 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 | |
return array( | |
'di' => array( | |
'instance' => array( | |
'Test\Collection' => array( | |
'injections' => array( | |
'addListener' => array( | |
array('listener' => 'Test\View'), | |
), | |
) | |
), | |
'DebuggingTools\Event\View' => array( | |
'shared' => true | |
) | |
), | |
'definition' => array( | |
'class' => array( | |
'Test\Collection' => array( | |
'addListener' => array( | |
'listener' => array( | |
'type' => 'Test\Listener', | |
'required' => false, | |
) | |
) | |
) | |
) | |
) | |
), | |
); |
This file contains 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
class Module | |
{ | |
public function init(Manager $moduleManager) | |
{ | |
$events = $moduleManager->events(); | |
$sharedEvents = $events->getSharedCollections(); | |
$sharedEvents->attach('bootstrap', 'bootstrap', array($this, 'test'), 900); | |
} | |
public function test($e) | |
{ | |
$f = $e->getParam('application')->getLocator()->get('Test\View'); | |
$f1 = $e->getParam('application')->getLocator()->get('Test\View'); | |
\Zend\Debug::dump($f); | |
\Zend\Debug::dump($f1); | |
$f = $e->getParam('application')->getLocator()->get('Test\Collection'); | |
} | |
} |
This file contains 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
constructed | |
(dump of the application's sharedeventmanager) 2x | |
Counter Collection: 1 | |
Counter Collection: 2 | |
constructed | |
(dump of an empty sharedeventmanager) 2x |
This file contains 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 Test\Event; | |
use \Zend\EventManager\EventCollection, | |
\Zend\EventManager\EventManager, | |
\Zend\EventManager\SharedEventCollectionAware, | |
\Zend\EventManager\SharedEventCollection; | |
class View implements Listener, SharedEventCollectionAware | |
{ | |
public function __construct() | |
{ | |
echo "constructed <br />"; | |
} | |
public function attach(EventCollection $events) | |
{ | |
} | |
public function detach(EventCollection $events) | |
{ | |
} | |
public function setSharedCollections(SharedEventCollection $sharedEventCollection) | |
{ | |
\Zend\Debug::dump($sharedEventCollection); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment