Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example/Simple implementation for [NFR] Events & Weak References #663

Closed
wants to merge 1 commit into from
Closed

Example/Simple implementation for [NFR] Events & Weak References #663

wants to merge 1 commit into from

Conversation

igorgolovanov
Copy link
Contributor

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.

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
 */

@xblabs
Copy link

xblabs commented May 22, 2013

nice

@phalcon
Copy link
Collaborator

phalcon commented May 28, 2013

Could you write some unit-tests for events + WeakRef?

https://github.com/phalcon/cphalcon/blob/1.2.0/unit-tests/EventsTest.php

@phalcon
Copy link
Collaborator

phalcon commented Oct 2, 2013

Implemented in 1.3.0

@phalcon phalcon closed this Oct 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants