Roulette Wiel: Wed liefde om u een mooie gemakkelijke manier om een overwinning te garanderen wanneer u klikt om te draaien.
  • Gratis Casino I Mobilen - Rekening houdend met alles, heeft dit Grosvenor beoordeling denk dat deze operator heeft het recht om zichzelf te labelen als de meest populaire casino in het Verenigd Koninkrijk.
  • Wat Heb Je Nodig Om Bingo Te Spelen: Jagen prooi groter dan zichzelf, terwijl heimelijk negeren van hun vijand early warning systeem is slechts een van de vele coole combinaties in het spel.
  • Winkans bij loterijen

    Wild Spells Online Gokkast Spelen Gratis En Met Geld
    We hebben deze download online casino's door middel van een strenge beoordeling proces om ervoor te zorgen dat u het meeste uit uw inzetten wanneer u wint.
    Nieuwe Gokkasten Gratis
    Dit betekent dat het hangt af van wat inkomstenbelasting bracket je in, en of de winst zal duwen u in een andere bracket.
    The delight is de geanimeerde banner met de welkomstpromotie bij de eerste duik je in.

    Pokersites voor Enschedeers

    Nieuw Casino
    De reel set is 7x7, met een totaal van 49 symbolen in het spel.
    Casigo Casino 100 Free Spins
    Holland Casino Eindhoven is een vestiging waar veel georganiseerd op het gebied van entertainment..
    Casino Spel Gratis Slots

    Sjoerd Maessen blog

    PHP and webdevelopment

    PHP hook, building hooks in your application

    with 50,880 comments

    Introduction
    One of the real challenges in building any type of framework, core or application is making it possible for the developers to hook into the business logic at specific points. Since PHP is not event based, nor it works with interrupts you have to come up an alternative.

    The test case
    Lets assume we are the main developers of a webshop framework. Programmers can use our framework to build complete webshops. Programmers can manage the orders that are placed on the webshop with the order class. The order class is part of our framework and we don’t want it to be extended by any programmer. However we don’t want to limit to programmers in their possibilities to hook into the orders process.

    For example programmers should be able to send an email to the webshopowner if an order changes from one specific delivery status to another. This functionality is not part of the default behavior in our framework and is custom for the progammers webshop implementation.

    Like said before, PHP doesn’t provide interrupts or real events so we need to come up with another way to implement hooks into our application. Lets take a look at the observer pattern.

    Implementing the Observer pattern
    The observer pattern is a design-pattern that describes a way for objects to be notified to specific state-changes in objects of the application.

    For the first implementation we can use SPL. The SPL provides in two simple objects:

    SPLSubject

    • attach (new observer to attach)
    • detach (existing observer to detach)
    • notify (notify all observers)

    SPLObserver

    • update (Called from the subject (i.e. when it’s value has changed).
    iOrderRef = $iOrderRef;
    		
    		// Get order information from the database or an other resources
    		$this->iStatus = Order::STATUS_SHIPPED;
    	}
    	
    	/**
    	 * Attach an observer
    	 * 
    	 * @param SplObserver $oObserver 
    	 * @return void
    	 */
    	public function attach(SplObserver $oObserver)
    	{
    		$sHash = spl_object_hash($oObserver);
    		if (isset($this->aObservers[$sHash])) {
    			throw new Exception('Observer is already attached');
    		}
    
    		$this->aObservers[$sHash] = $oObserver;
    	}
    
    	/**
    	 * Detach observer
    	 * 
    	 * @param SplObserver $oObserver 
    	 * @return void
    	 */
    	public function detach(SplObserver $oObserver)
    	{
    		$sHash = spl_object_hash($oObserver);
    		if (!isset($this->aObservers[$sHash])) {
    			throw new Exception('Observer not attached');
    		}
    		unset($this->aObservers[$sHash]);
    	}
    
    	/**
    	 * Notify the attached observers
    	 * 
    	 * @param string $sEvent, name of the event
    	 * @param mixed $mData, optional data that is not directly available for the observers
    	 * @return void
    	 */
    	public function notify()
    	{
    		foreach ($this->aObservers as $oObserver) {
    			try {
    				$oObserver->update($this);
    			} catch(Exception $e) {
    
    			}
    		}
    	}
    
    	/**
    	 * Add an order
    	 * 
    	 * @param array $aOrder 
    	 * @return void
    	 */
    	public function delete()
    	{
    		$this->notify();
    	}
    	
    	/**
    	 * Return the order reference number
    	 * 
    	 * @return int
    	 */
    	public function getRef()
    	{
    		return $this->iOrderRef;
    	}
    	
    	/**
    	 * Return the current order status
    	 * 
    	 * @return int
    	 */
    	public function getStatus()
    	{
    		return $this->iStatus;
    	}
    	
    	/**
    	 * Update the order status
    	 */
    	public function updateStatus($iStatus)
    	{
    		$this->notify();
    		// ...
    		$this->iStatus = $iStatus;
    		// ...
    		$this->notify();
    	}
    }
    
    /**
     * Order status handler, observer that sends an email to secretary
     * if the status of an order changes from shipped to delivered, so the
     * secratary can make a phone call to our customer to ask for his opinion about the service
     * 
     * @package Shop
     */
    class OrderStatusHandler implements SplObserver
    {
    	/**
    	 * Previous orderstatus
    	 * @var int
    	 */
    	protected $iPreviousOrderStatus;
    	/**
    	 * Current orderstatus
    	 * @var int
    	 */
    	protected $iCurrentOrderStatus;
    	
    	/**
    	 * Update, called by the observable object order
    	 * 
    	 * @param Observable_Interface $oSubject
    	 * @param string $sEvent
    	 * @param mixed $mData 
    	 * @return void
    	 */
    	public function update(SplSubject $oSubject)
    	{
    		if(!$oSubject instanceof Order) {
    			return;
    		}
    		if(is_null($this->iPreviousOrderStatus)) {
    			$this->iPreviousOrderStatus = $oSubject->getStatus();
    		} else {
    			$this->iCurrentOrderStatus = $oSubject->getStatus();
    			if($this->iPreviousOrderStatus === Order::STATUS_SHIPPED && $this->iCurrentOrderStatus === Order::STATUS_DELIVERED) {
    				$sSubject = sprintf('Order number %d is shipped', $oSubject->getRef());
    				//mail('secratary@example.com', 'Order number %d is shipped', 'Text');
    				echo 'Mail sended to the secratary to help her remember to call our customer for a survey.';
    			}
    		}
    	}
    }
    
    $oOrder = new Order(26012011);
    $oOrder->attach(new OrderStatusHandler());
    $oOrder->updateStatus(Order::STATUS_DELIVERED);
    $oOrder->delete();
    ?>

    There are several problems with the implementation above. To most important disadvantage is that we have only one update method in our observer. In this update method we don’t know when and why we are getting notified, just that something happened. We should keep track of everything that happens in the subject. (Or use debug_backtrace… just joking, don’t even think about using it that way ever!).

    Taking it a step further, events
    Lets take a look at the next example, we will extend the Observer implementation with some an additional parameter for the eventname that occured.

    Finishing up, optional data

    iOrderRef = $iOrderRef;
    		
    		// Get order information from the database or something else...
    		$this->iStatus = Order::STATUS_SHIPPED;
    	}
    	
    	/**
    	 * Attach an observer
    	 * 
    	 * @param Observer_Interface $oObserver 
    	 * @return void
    	 */
    	public function attachObserver(Observer_Interface $oObserver)
    	{
    		$sHash = spl_object_hash($oObserver);
    		if (isset($this->aObservers[$sHash])) {
    			throw new Exception('Observer is already attached');
    		}
    
    		$this->aObservers[$sHash] = $oObserver;
    	}
    
    	/**
    	 * Detach observer
    	 * 
    	 * @param Observer_Interface $oObserver 
    	 * @return void
    	 */
    	public function detachObserver(Observer_Interface $oObserver)
    	{
    		$sHash = spl_object_hash($oObserver);
    		if (!isset($this->aObservers[$sHash])) {
    			throw new Exception('Observer not attached');
    		}
    		unset($this->aObservers[$sHash]);
    	}
    
    	/**
    	 * Notify the attached observers
    	 * 
    	 * @param string $sEvent, name of the event
    	 * @param mixed $mData, optional data that is not directly available for the observers
    	 * @return void
    	 */
    	public function notifyObserver($sEvent, $mData=null)
    	{
    		foreach ($this->aObservers as $oObserver) {
    			try {
    				$oObserver->update($this, $sEvent, $mData);
    			} catch(Exception $e) {
    
    			}
    		}
    	}
    
    	/**
    	 * Add an order
    	 * 
    	 * @param array $aOrder 
    	 * @return void
    	 */
    	public function add($aOrder = array())
    	{
    		$this->notifyObserver('onAdd');
    	}
    	
    	/**
    	 * Return the order reference number
    	 * 
    	 * @return int
    	 */
    	public function getRef()
    	{
    		return $this->iOrderRef;
    	}
    	
    	/**
    	 * Return the current order status
    	 * 
    	 * @return int
    	 */
    	public function getStatus()
    	{
    		return $this->iStatus;
    	}
    	
    	/**
    	 * Update the order status
    	 */
    	public function updateStatus($iStatus)
    	{
    		$this->notifyObserver('onBeforeUpdateStatus');
    		// ...
    		$this->iStatus = $iStatus;
    		// ...
    		$this->notifyObserver('onAfterUpdateStatus');
    	}
    }
    
    /**
     * Order status handler, observer that sends an email to secretary
     * if the status of an order changes from shipped to delivered, so the
     * secratary can make a phone call to our customer to ask for his opinion about the service
     * 
     * @package Shop
     */
    class OrderStatusHandler implements Observer_Interface
    {
    	protected $iPreviousOrderStatus;
    	protected $iCurrentOrderStatus;
    	
    	/**
    	 * Update, called by the observable object order
    	 * 
    	 * @param Observable_Interface $oObservable
    	 * @param string $sEvent
    	 * @param mixed $mData 
    	 * @return void
    	 */
    	public function update(Observable_Interface $oObservable, $sEvent, $mData=null)
    	{
    		if(!$oObservable instanceof Order) {
    			return;
    		}
    		
    		switch($sEvent) {
    			case 'onBeforeUpdateStatus':
    				$this->iPreviousOrderStatus = $oObservable->getStatus();
    				return;
    			case 'onAfterUpdateStatus':
    				$this->iCurrentOrderStatus = $oObservable->getStatus();
    				
    				if($this->iPreviousOrderStatus === Order::STATUS_SHIPPED && $this->iCurrentOrderStatus === Order::STATUS_DELIVERED) {
    					$sSubject = sprintf('Order number %d is shipped', $oObservable->getRef());
    					//mail('secratary@example.com', 'Order number %d is shipped', 'Text');
    					echo 'Mail sended to the secratary to help her remember to call our customer for a survey.';
    				}
    		}
    	}
    }
    
    $oOrder = new Order(26012011);
    $oOrder->attachObserver(new OrderStatusHandler());
    $oOrder->updateStatus(Order::STATUS_DELIVERED);
    $oOrder->add();
    ?>

    Now we are able to take action on different events that occur.

    Disadvantages
    Although this implementation works quite well there are some drawbacks. One of those drawbacks is that we need to dispatch an event in our framework, if we don’t programmers can’t hook into our application. Triggering events everywhere give us a small performance penalty however I do think this way of working gives the programmers a nice way to hook into your application on those spots that you want them to hook in.

    Just for the record
    Notice that this code is just an example and can still use some improvements, for example: each observer is initialized even it will maybe never be notified, therefore I suggest to make use of lazy in some cases for loading the objects. There are other systems to hook into an application, more to follow!

    Written by Sjoerd Maessen

    May 23rd, 2011 at 8:02 pm

    Posted in API

    Tagged with , , ,

    50,880 Responses to 'PHP hook, building hooks in your application'

    Subscribe to comments with RSS or TrackBack to 'PHP hook, building hooks in your application'.

    1. Расчёт оклада военнослужащего по должности командира взвода — 16 500 руб. в 2025. новости военная служба

      Brentagila

      18 Sep 25 at 7:01 am

    2. микрозайм всем [url=www.zaimy-11.ru]www.zaimy-11.ru[/url] .

      zaimi_cyPt

      18 Sep 25 at 7:03 am

    3. bs2best at, bs2web at и bs2 market: глубокий анализ технологий 2025 года

      bs2best.at blacksprut marketplace Official

      CharlesNarry

      18 Sep 25 at 7:04 am

    4. электрические карнизы купить [url=https://razdvizhnoj-elektrokarniz.ru/]https://razdvizhnoj-elektrokarniz.ru/[/url] .

    5. Howardreomo

      18 Sep 25 at 7:04 am

    6. займы всем [url=www.zaimy-14.ru]www.zaimy-14.ru[/url] .

      zaimi_pbSr

      18 Sep 25 at 7:05 am

    7. I like the valuable info you supply for your articles.
      I’ll bookmark your weblog and take a look at again here frequently.
      I am relatively certain I will be told many new stuff right here!
      Good luck for the following!

    8. After I initially left a comment I appear to have clicked the -Notify me
      when new comments are added- checkbox and now every time a comment
      is added I receive four emails with the exact same comment.
      Is there a way you are able to remove me from that service?
      Thanks!

      Click here

      18 Sep 25 at 7:06 am

    9. Timothyces

      18 Sep 25 at 7:07 am

    10. I like what you guys tend to be up too. This sort of clever work and coverage!
      Keep up the amazing works guys I’ve you guys to blogroll.

      macauslot88

      18 Sep 25 at 7:07 am

    11. список займов онлайн на карту [url=http://zaimy-15.ru/]http://zaimy-15.ru/[/url] .

      zaimi_sfpn

      18 Sep 25 at 7:07 am

    12. раздвижные шторы [url=http://razdvizhnoj-elektrokarniz.ru/]http://razdvizhnoj-elektrokarniz.ru/[/url] .

    13. займы все онлайн [url=https://zaimy-14.ru/]https://zaimy-14.ru/[/url] .

      zaimi_dwSr

      18 Sep 25 at 7:09 am

    14. займы россии [url=http://zaimy-11.ru]http://zaimy-11.ru[/url] .

      zaimi_fkPt

      18 Sep 25 at 7:09 am

    15. online apotheke preisvergleich: sicherheit und wirkung von potenzmitteln – gГјnstigste online apotheke

      Israelpaync

      18 Sep 25 at 7:10 am

    16. микрозаймы все [url=http://zaimy-14.ru/]http://zaimy-14.ru/[/url] .

      zaimi_faSr

      18 Sep 25 at 7:11 am

    17. Good day very nice web site!! Guy .. Excellent .. Amazing
      .. I’ll bookmark your blog and take the feeds also? I am glad to find a lot
      of helpful info right here within the put up, we need work
      out extra techniques on this regard, thanks for sharing.
      . . . . .

    18. Эта статья предлагает захватывающий и полезный контент, который привлечет внимание широкого круга читателей. Мы постараемся представить тебе идеи, которые вдохновят вас на изменения в жизни и предоставят практические решения для повседневных вопросов. Читайте и вдохновляйтесь!
      Все материалы собраны здесь – https://onlitrip.com/convergent-and-divergent-plate-margins

      RichardChemo

      18 Sep 25 at 7:15 am

    19. Good day! I just would like to give you a huge thumbs
      up for your great information you have right here
      on this post. I will be coming back to your blog for more soon.

    20. займы все [url=zaimy-15.ru]zaimy-15.ru[/url] .

      zaimi_cqpn

      18 Sep 25 at 7:15 am

    21. всезаймы [url=http://zaimy-15.ru/]http://zaimy-15.ru/[/url] .

      zaimi_hepn

      18 Sep 25 at 7:19 am

    22. Your style is really unique compared to other people I have read stuff from.

      I appreciate you for posting when you’ve got the opportunity, Guess I will
      just book mark this web site.

    23. Hello, i think that i saw you visited my site thus i came to “return the favor”.I’m attempting to find things to improve
      my website!I suppose its ok to use some of your ideas!!

    24. официальные займы онлайн на карту бесплатно [url=https://www.zaimy-11.ru]https://www.zaimy-11.ru[/url] .

      zaimi_wcPt

      18 Sep 25 at 7:20 am

    25. займы россии [url=www.zaimy-14.ru/]www.zaimy-14.ru/[/url] .

      zaimi_zvSr

      18 Sep 25 at 7:23 am

    26. займы все онлайн [url=https://zaimy-11.ru/]https://zaimy-11.ru/[/url] .

      zaimi_xgPt

      18 Sep 25 at 7:24 am

    27. Surf Kaizenaire.com for Singapore’s curated promotions,
      mаking it tһe top choicee fоr deals аnd event notifies.

      Singaporeans’ deal-chasing prowess іs legendary in Singapore, tһe
      utmostt shopping heaven bursting witһ promotions.

      Singaporeans appгeciate DIY home design projects fօr individualized
      spaces, аnd bear in mind t᧐ remɑіn upgraded оn Singapore’s neѡest promotions and shopping deals.

      Negligent Ericka ρrovides edgy, experimental style, cherished Ƅy bold Singaporeans for theіr
      bold cuts aand vibrant prints.

      TWG Tea supplies gourmet teas ɑnd devices lah, treasured by tea connoisseurs in Singapore f᧐r their beautiful blends
      аnd elegant packaging lor.

      Τhings ‘ԁ fills burritos аnd kebabs with fresh active
      ingredients, loved Ƅy locals fοr tasty, mobile fusion consumes.

      Aiyo, fаst leh, visit Kaizenaire.com for price cuts օne.

      Feel free to surf t᧐ my рage :: singapore promotions

    28. раздвижной электрокарниз [url=http://razdvizhnoj-elektrokarniz.ru/]http://razdvizhnoj-elektrokarniz.ru/[/url] .

    29. Timothyces

      18 Sep 25 at 7:29 am

    30. займ все [url=https://www.zaimy-14.ru]https://www.zaimy-14.ru[/url] .

      zaimi_mlSr

      18 Sep 25 at 7:31 am

    31. электрокарнизы для штор купить в москве [url=http://razdvizhnoj-elektrokarniz.ru]http://razdvizhnoj-elektrokarniz.ru[/url] .

    32. Эта обзорная заметка содержит ключевые моменты и факты по актуальным вопросам. Она поможет читателям быстро ориентироваться в теме и узнать о самых важных аспектах сегодня. Получите краткий курс по современной информации и оставайтесь в курсе событий!
      Погрузиться в научную дискуссию – https://webofthings.org/2009/01/20/we-want-you

      Melvinevofs

      18 Sep 25 at 7:33 am

    33. For the reason that the admin of this web site is working, no uncertainty very
      rapidly it will be well-known, due to its quality contents.

      au88

      18 Sep 25 at 7:34 am

    34. I constantly spent my half an hour to read this weblog’s content everyday along with a mug of
      coffee.

      Miroxa Viax

      18 Sep 25 at 7:34 am

    35. раздвижные электрокарнизы для штор [url=https://www.razdvizhnoj-elektrokarniz.ru]https://www.razdvizhnoj-elektrokarniz.ru[/url] .

    36. микро займы онлайн [url=https://zaimy-14.ru/]микро займы онлайн[/url] .

      zaimi_axSr

      18 Sep 25 at 7:36 am

    37. Great web site. Lots of useful info here. I am sending it to a few pals ans additionally sharing in delicious.
      And certainly, thanks to your sweat!

      Puro Bitline

      18 Sep 25 at 7:36 am

    38. Hurrah, that’s what I was exploring for, what a material! present here at
      this blog, thanks admin of this site.

    39. список займов онлайн [url=zaimy-15.ru]список займов онлайн[/url] .

      zaimi_ndpn

      18 Sep 25 at 7:37 am

    40. все микрозаймы [url=http://zaimy-14.ru/]все микрозаймы[/url] .

      zaimi_iwSr

      18 Sep 25 at 7:38 am

    41. мфо займ онлайн [url=http://zaimy-15.ru]мфо займ онлайн[/url] .

      zaimi_zdpn

      18 Sep 25 at 7:41 am

    42. кракен onion kraken onion, kraken onion ссылка, kraken onion зеркала, kraken рабочая ссылка onion, сайт kraken onion, kraken darknet, kraken darknet market, kraken darknet ссылка, сайт kraken darknet, kraken актуальные ссылки, кракен ссылка kraken, kraken официальные ссылки, kraken ссылка тор, kraken ссылка зеркало, kraken ссылка на сайт, kraken онион, kraken онион тор, кракен онион, кракен онион тор, кракен онион зеркало, кракен даркнет маркет, кракен darknet, кракен onion, кракен ссылка onion, кракен onion сайт, kra ссылка, kraken сайт, kraken актуальные ссылки, kraken зеркало, kraken ссылка зеркало, kraken зеркало рабочее, актуальные зеркала kraken, kraken сайт зеркала, kraken маркетплейс зеркало, кракен ссылка, кракен даркнет

      RichardPep

      18 Sep 25 at 7:42 am

    43. взо [url=www.zaimy-15.ru/]www.zaimy-15.ru/[/url] .

      zaimi_hqpn

      18 Sep 25 at 7:44 am

    44. займы россии [url=http://zaimy-11.ru]http://zaimy-11.ru[/url] .

      zaimi_ugPt

      18 Sep 25 at 7:45 am

    45. раздвижной электрокарниз купить [url=razdvizhnoj-elektrokarniz.ru]razdvizhnoj-elektrokarniz.ru[/url] .

    46. Читатели получат представление о том, как современные технологии влияют на развитие медицины. Обсуждаются новые методы лечения, персонализированный подход и роль цифровых решений в повышении качества медицинских услуг.
      Не упусти важное! – https://placesrf.ru/moscow/company/klinika-chastnaya-skoraya-pomoschy-1-v-odincovo-ul-arhitektora-vlasova

      SteveMal

      18 Sep 25 at 7:46 am

    47. займер ру [url=zaimy-14.ru]займер ру[/url] .

      zaimi_qeSr

      18 Sep 25 at 7:48 am

    48. Awesome issues here. I’m very happy to peer your article.
      Thanks a lot and I am taking a look ahead to touch you.
      Will you please drop me a mail?

    49. I’ll immediately clutch your rss as I can not to find your
      email subscription link or newsletter service.
      Do you have any? Kindly let me recognise in order that I may subscribe.
      Thanks.

    50. Nice post. I learn something new and challenging on websites I stumbleupon every day.
      It’s always useful to read through content from other authors
      and use something from other websites.

    Leave a Reply