Skip to content

Instantly share code, notes, and snippets.

@fritz-gerneth
Created April 27, 2012 21:00
Show Gist options
  • Save fritz-gerneth/2513188 to your computer and use it in GitHub Desktop.
Save fritz-gerneth/2513188 to your computer and use it in GitHub Desktop.
'di' => array(
'instance' => array(
'Test\Collection' => array(
'injections' => array(
'addListener' => array(
array('listener' => 'Test\View'),
),
)
),
),
'definition' => array(
'class' => array(
'Test\Collection' => array(
'addListener' => array(
'listener' => array(
'type' => 'Test\Listener',
'required' => false,
)
)
)
)
)
),
class Module
{
public function init(Manager $moduleManager)
{
$events = $moduleManager->events();
$sharedEvents = $events->getSharedCollections();
$sharedEvents->attach('Zend\Mvc\Bootstrap', 'bootstrap', array($this, 'test'), 900);
}
public function test($e)
{
$f = $e->getParam('application')->getLocator()->get('Test\Collection');
}
}
<?php
namespace Test;
use \Zend\EventManager\EventCollection,
\Zend\EventManager\EventManagerAware,
\Zend\Di\Locator;
class Collection //implements EventManagerAware
{
protected $counter = 0;
public function __construct()
{
}
public function setEventManager(EventCollection $eventManager)
{
$eventManager->getSharedCollections()->attach('*', '*', array($this, 'onEvent'));
$this->counter++;
echo "Counter: " . $this->counter . "<br />";
}
public function setLocator(Locator $locator)
{
//\Zend\Debug::dump(debug_backtrace());
$f = $locator->get('Test\Collection');
if($f == $this)
{ echo "true"; }
}
public function onEvent($e)
{
echo $e->getName() . "<br />";
}
}
<?php
namespace Test;
use \Zend\EventManager\EventCollection,
\Zend\EventManager\EventManagerAware,
\Zend\Di\Locator;
class Collection //implements EventManagerAware
{
protected $counter = 0;
public function __construct()
{
}
public function setEventManager(EventCollection $eventManager)
{
$eventManager->getSharedCollections()->attach('*', '*', array($this, 'onEvent'));
$this->counter++;
echo "Counter: " . $this->counter . "<br />";
}
public function setLocator(Locator $locator)
{
//\Zend\Debug::dump(debug_backtrace());
$f = $locator->get('Test\Collection');
if($f == $this)
{ echo "true"; }
}
public function onEvent($e)
{
echo $e->getName() . "<br />";
}
}
<?php
namespace Test;
use \Zend\EventManager\EventCollection,
\Zend\EventManager\EventManagerAware,
\Zend\Di\Locator;
class Collection //implements EventManagerAware
{
protected $counter = 0;
public function __construct()
{
}
public function setEventManager(EventCollection $eventManager)
{
$eventManager->getSharedCollections()->attach('*', '*', array($this, 'onEvent'));
$this->counter++;
echo "Counter: " . $this->counter . "<br />";
}
public function onEvent($e)
{
echo $e->getName() . "<br />";
}
}
<?php
namespace Test;
use \Zend\EventManager\EventCollection,
\Zend\EventManager\EventManagerAware,
\Zend\Di\Locator;
class Collection implements EventManagerAware
{
protected $counter = 0;
public function __construct()
{
}
public function setEventManager(EventCollection $eventManager)
{
$eventManager->getSharedCollections()->attach('*', '*', array($this, 'onEvent'));
$this->counter++;
echo "Counter: " . $this->counter . "<br />";
}
public function onEvent($e)
{
echo $e->getName() . "<br />";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment