RE: [PHP] observer pattern
| From: | Daevid Vincent | Date: | Mon, 23 May 2011 21:14:34 +0000 |
| Subject: | RE: [PHP] observer pattern | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313126@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Eric Butera [mailto:eric.butera@gmail.com]
> Sent: Friday, May 20, 2011 2:25 PM
> To: PHP
> Subject: Re: [PHP] observer pattern
>
> [whoops didn't hit reply-all]
>
> On Wed, May 18, 2011 at 5:18 AM, Ken Guest <ken@linux.ie> wrote:
> > Lo,
> >
> > so, I'm wondering - how many of you use the observer pattern in php;
> > and if so, do you implement it 'standalone' or with the spl classes?
> > Is there any particular advantage to doing it "your way"; whichever
> > your way is?
> >
> > Ken
> >
> > --
> > http://blogs.linux.ie/kenguest/
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> I use it quite a bit over the various projects I maintain. It allows
> subjects to trigger events that observers can process if they're
> interested, or better yet, completely ignore. This allows
> standardized code bases to create nice hooks that allow extensibility
> without needing to place one-off code inside the main project.
>
> A quick example might be on saving a record in your code, it triggers
> an event, then an observer in a custom site watches for said event and
> injects/updates a search entry in Lucene. This way one site can have
> a custom search engine that another site might not need.
>
> I started off with the concepts I found in
> http://examples.stubbles.net/docroot/events/ but created my own
> because I wanted something stand-alone.
Well, you (or in this case, *I*) learn something new every day.
I had no idea PHP could do observers. How very "Java" (and neat!)
Granted, it is just a design pattern, but to have the SplObserver stuff built in is pretty cool.
What version of PHP is this available from? The web page doesn't say.
http://www.labelmedia.co.uk/blog/posts/php-design-patterns-observer-pattern.html
http://cormacscode.wordpress.com/2010/10/12/practical-example-php-implementation-of-the-observer-pattern/
http://www.php.net/manual/en/book.spl.php