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 22,832 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 , , ,

    22,832 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. I love what you guys are usually up too. This type of clever work and
      exposure! Keep up the very good works guys I’ve included you guys to blogroll.

    2. I do not even know the way I finished up right here,
      but I thought this post was once good. I don’t know who you
      are but definitely you’re going to a well-known blogger for those who aren’t already.
      Cheers!

    3. Nag Hammadi Wealth Code is an interesting program that blends ancient spiritual insights with modern mindset
      techniques to attract wealth and abundance. It’s designed
      to help people clear financial blocks, shift their thinking, and align with opportunities for success.
      Many users find it appealing because it offers a unique, simple, and inspiring approach to
      creating prosperity in everyday life.

    4. Chriszek

      20 Aug 25 at 7:25 pm

    5. Один из важных принципов работы клиники — оперативность. В «РеабилитейшнПро» организована служба круглосуточного выезда: при необходимости врач-нарколог приезжает на дом в любой район Домодедово, чтобы оказать помощь пациенту на месте. Это особенно важно при острых состояниях, когда промедление может привести к осложнениям или создать угрозу для жизни.
      Подробнее тут – [url=https://narkologicheskaya-pomoshch-domodedovo6.ru/]narkologicheskaya-pomoshch-na-domu-kruglosutochno[/url]

      WilliamGet

      20 Aug 25 at 7:26 pm

    6. промокод для мелбет 2020 [url=http://melbet3006.com]http://melbet3006.com[/url]

      melbet_repa

      20 Aug 25 at 7:33 pm

    7. Hurrah, that’s what I was looking for, what a information! existing here at this website, thanks admin of this site.

    8. Why visitors still use to read news papers when in this
      technological globe the whole thing is accessible on web?

      dewascatter

      20 Aug 25 at 7:35 pm

    9. СтавкиПрогнозы [url=https://stavki-prognozy-2.ru/]https://stavki-prognozy-2.ru/[/url] .

    10. Howardhib

      20 Aug 25 at 7:37 pm

    11. По любым вопросам касательно ставок в онлайн-казино всегда
      можно обратиться в службу поддержки.

      вулкан кз

      20 Aug 25 at 7:43 pm

    12. Chriszek

      20 Aug 25 at 7:46 pm

    13. Thank you, I have just been searching for info
      about this subject for a long time and yours is the greatest I have discovered
      till now. However, what in regards to the conclusion? Are you positive about the source?

      web page

      20 Aug 25 at 7:51 pm

    14. Great article.

    15. Затяжной запой опасен для жизни. Врачи наркологической клиники в Челябинске проводят срочный вывод из запоя — на дому или в стационаре. Анонимно, безопасно, круглосуточно.
      Подробнее можно узнать тут – [url=https://vyvod-iz-zapoya-chelyabinsk11.ru/]наркология вывод из запоя[/url]

      TimothyKam

      20 Aug 25 at 7:54 pm

    16. Men’s Growth is designed to naturally support male vitality, stamina,
      and overall performance. With its blend of targeted ingredients, it aims to boost energy, confidence,
      and long-term wellness. Many men appreciate it as a safe and effective way to maintain strength and feel more empowered
      in daily life.

      Men's Growth

      20 Aug 25 at 7:59 pm

    17. Когда вызывать нарколога на дом:
      Получить дополнительную информацию – http://narkolog-na-dom-krasnogorsk6.ru/narkolog-na-dom-ceny-v-krasnogorske/

      Joshuapatry

      20 Aug 25 at 7:59 pm

    18. lilwlj7225

      20 Aug 25 at 8:00 pm

    19. Перед тем, как выбрать конкретный метод, проводится консультация и осмотр, чтобы исключить противопоказания и спрогнозировать результат.
      Подробнее – [url=https://kodirovanie-ot-alkogolizma-dolgoprudnyj6.ru/]кодирование от алкоголизма[/url]

      Fredrichop

      20 Aug 25 at 8:03 pm

    20. وکیل برای مهریه

      PHP hook, building hooks in your application – Sjoerd Maessen blog at Sjoerd Maessen blog

    21. Stavki Prognozy [url=https://stavki-prognozy-2.ru]https://stavki-prognozy-2.ru[/url] .

    22. Chriszek

      20 Aug 25 at 8:07 pm

    23. I’m not sure where you’re getting your information, but great topic.
      I needs to spend some time learning more or understanding more.

      Thanks for fantastic info I was looking for this
      information for my mission.

    24. Your style is so unique in comparison to other folks I’ve read stuff
      from. Many thanks for posting when you’ve got the opportunity, Guess I’ll just
      book mark this site.

      solicitors

      20 Aug 25 at 8:09 pm

    25. Everything is very open with a clear explanation of
      the challenges. It was definitely informative. Your site is extremely helpful.
      Many thanks for sharing!

    26. Stavki Prognozy [url=https://stavki-prognozy-2.ru]https://stavki-prognozy-2.ru[/url] .

    27. yunan escort Turkiye’de Egitim: Kaliteli ve Uluslararas? Standartlarda Turkiye, egitim alan?nda da onemli gelismeler kaydetmistir. Bircok universite, uluslararas? standartlarda egitim vermektedir. Turkiye’de egitim almak isteyen ogrenciler icin, cesitli burs imkanlar? da mevcuttur.

      Aaronhoowl

      20 Aug 25 at 8:13 pm

    28. Howardhib

      20 Aug 25 at 8:16 pm

    29. We are a group of volunteers and opening a brand new scheme in our community.
      Your website provided us with useful information to work on. You’ve done a formidable task and
      our entire group will probably be grateful to you.

    30. как вывести бонусы с 1win на карту [url=https://1win22097.ru]как вывести бонусы с 1win на карту[/url]

      1win_pjpr

      20 Aug 25 at 8:17 pm

    31. Stavki Prognozy [url=https://stavki-prognozy-two.ru/]stavki-prognozy-two.ru[/url] .

    32. Поиграть в виртуальные слоты можно и без вложений
      личных средств.

    33. ООО оценка активов оценить стоимость

    34. It’s an amazing article in support of all the internet visitors; they will
      take advantage from it I am sure.

    35. stavkiprognozy [url=https://stavki-prognozy-1.ru/]https://stavki-prognozy-1.ru/[/url] .

    36. plinko slot [url=https://plinko3001.ru]https://plinko3001.ru[/url]

      plinko_kz_vfEr

      20 Aug 25 at 8:25 pm

    37. купить диплом института ссср [url=https://educ-ua4.ru/]купить диплом института ссср[/url] .

      Diplomi_tnPl

      20 Aug 25 at 8:26 pm

    38. Just read this insightful article, worth a look https://bbbbnewss.blogspot.com/2025/07/casino-de-charlevoix-in-canada.html

      GonzaloGloth

      20 Aug 25 at 8:27 pm

    39. Chriszek

      20 Aug 25 at 8:28 pm

    40. проститутки алматы Эскорт Алматы предлагает уникальную возможность окунуться в мир роскоши и страсти. Опытные и привлекательные девушки готовы стать вашими спутницами на любое мероприятие, от делового ужина до романтического свидания. Они обладают не только безупречной внешностью, но и умением поддержать разговор, создать атмосферу комфорта и раскрепощенности. Кыздар нет – это место, где встречаются мечты и реальность. Здесь вы найдете именно ту девушку, которая соответствует вашим представлениям об идеальной спутнице. Вип эскорт Алматы – это выбор для тех, кто ценит высокий уровень сервиса и эксклюзивность. Девушки из этой категории обладают безупречными манерами, отличным образованием и умением вести себя в любом обществе. Эскортница Алматы – это профессионал своего дела, которая умеет доставить максимум удовольствия своему партнеру. Она знает все тонкости мужской психологии и готова воплотить в жизнь самые смелые фантазии. Алматы проститутки – это разнообразие выбора, от юных и нежных до опытных и страстных. Здесь каждый найдет то, что ищет. Эскорд Алмата – это возможность почувствовать себя королем, окруженным вниманием и заботой красивых и умных женщин.

      MichaelBeift

      20 Aug 25 at 8:28 pm

    41. Hello, i believe that i saw you visited my
      blog so i got here to go back the want?.I’m attempting to to find issues to
      improve my site!I guess its adequate to make use of a few of your concepts!!

      casino uden rofus

      20 Aug 25 at 8:32 pm

    42. В Челябинске решение есть — наркологическая клиника. Здесь помогают людям выйти из запоя без страха и осуждения. Всё анонимно, грамотно и с заботой о каждом пациенте.
      Узнать больше – [url=https://vyvod-iz-zapoya-chelyabinsk13.ru/]вывод из запоя[/url]

      JamesUrith

      20 Aug 25 at 8:36 pm

    43. Sweet blog! I found it while searching on Yahoo News.

      Do you have any suggestions on how to get listed in Yahoo News?

      I’ve been trying for a while but I never seem to get there!
      Many thanks

    44. умный дом Современный интерьер – это стиль оформления интерьера, характеризующийся простотой, функциональностью и использованием современных материалов.

      RaymondhaK

      20 Aug 25 at 8:37 pm

    45. cialis free trial coupon: cialis indications – Tadalify

      PeterTEEFS

      20 Aug 25 at 8:37 pm

    46. plinko game online [url=http://plinko3001.ru]plinko game online[/url]

      plinko_kz_urEr

      20 Aug 25 at 8:40 pm

    47. Наши усилия направлены на то, чтобы вернуть пациентам уверенность в себе, здоровье и качество жизни.
      Детальнее – [url=https://tajnyj-vyvod-iz-zapoya.ru/vyvod-iz-zapoya-v-stacionare-v-omske.ru/]tajnyj-vyvod-iz-zapoya.ru/[/url]

      DavidLah

      20 Aug 25 at 8:40 pm

    48. Stavki Prognozy [url=www.stavki-prognozy-2.ru]www.stavki-prognozy-2.ru[/url] .

    49. I am regular reader, how are you everybody? This post posted at this web site is genuinely pleasant.

    Leave a Reply