phalcon/cphalcon — pull request #663 by golovanov (2013-05-22 14:58:39+00:00)
Title: Example/Simple implementation for [NFR] Events & Weak References

*this pull for discussion #658*

I wrote a simple implementation for [NFR] Events & Weak References which uses WeakRef php-extension.
Some simple example of how it works/how it use.

```php

class MyFirstListener
{
public function afterShow()
{
echo 'show first listener';
}
}

class MySecondListener
{
public function afterShow()
{
echo 'show second listener';
}
}

$eventsManager = new \Phalcon\Events\Manager();

$firstListener = new MyFirstListener();
$secondListener = new MySecondListener();

$eventsManager->attach('my', $firstListener); // without weakref
$eventsManager->attach('my', new WeakRef($secondListener)); // with weakref

// fire when two listeners still exists.
$eventsManager->fire('my:afterShow', null);
/**
* will be shown:
* - show first listener
* - show second listener
*/
unset($firstListener);
unset($secondListener);

// fire when two listeners was unsetted.
$eventsManager->fire('my:afterShow', null);
/**
* will be shown only:
* - show first listener
*/

```