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 39,609 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 , , ,

    39,609 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. hi!,I really like your writing so much! percentage we be in contact extra approximately your post on AOL?
      I need an expert in this space to solve my problem. May
      be that’s you! Looking ahead to peer you.

    2. Hello everyone, it’s my first pay a visit at this web site,
      and article is actually fruitful in support of me, keep up posting these articles or
      reviews.

    3. mostbet qeydiyyat yoxlaması [url=http://mostbet4142.ru/]http://mostbet4142.ru/[/url]

      mostbet_ltSi

      8 Sep 25 at 11:28 am

    4. купить диплом с реестром о высшем образовании [url=www.educ-ua13.ru]купить диплом с реестром о высшем образовании[/url] .

      Diplomi_aepn

      8 Sep 25 at 11:28 am

    5. kraken 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

      8 Sep 25 at 11:32 am

    6. купить диплом о среднем образовании [url=https://educ-ua6.ru]купить диплом о среднем образовании[/url] .

      Diplomi_wsMl

      8 Sep 25 at 11:33 am

    7. Harlandtobia

      8 Sep 25 at 11:34 am

    8. darknet websites best darknet markets darknet market lists [url=https://privatedarknetmarket.com/ ]dark websites [/url]

      Robertalima

      8 Sep 25 at 11:34 am

    9. kraken darknet market 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

      8 Sep 25 at 11:34 am

    10. кривой рог купить диплом о высшем образовании [url=http://educ-ua4.ru]кривой рог купить диплом о высшем образовании[/url] .

      Diplomi_elPl

      8 Sep 25 at 11:34 am

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

      Diplomi_kkmi

      8 Sep 25 at 11:36 am

    12. купить диплом с проведением в [url=www.colonell.ru/support/forum/view_profile.php?UID=8612/]купить диплом с проведением в[/url] .

      Bistro kypit diplom lubogo instityta!_ipkt

      8 Sep 25 at 11:38 am

    13. seo и реклама блог [url=statyi-o-marketinge2.ru]statyi-o-marketinge2.ru[/url] .

    14. Thanks on your marvelous posting! I truly enjoyed reading it, you will be a great
      author.I will be sure to bookmark your blog and will
      eventually come back very soon. I want to encourage you to ultimately continue
      your great job, have a nice holiday weekend!

    15. Hello, yeah this post is truly pleasant and I have learned lot of things from it about blogging.

      thanks.

      mm99

      8 Sep 25 at 11:42 am

    16. купить легальный диплом техникума [url=https://educ-ua7.ru/]купить легальный диплом техникума[/url] .

      Diplomi_bkEr

      8 Sep 25 at 11:46 am

    17. веб-аналитика блог [url=http://statyi-o-marketinge2.ru]http://statyi-o-marketinge2.ru[/url] .

    18. Hello my friend! I wish to say that this article is awesome, nice written and include almost all important infos.
      I would like to look more posts like this .

    19. Joshuapep

      8 Sep 25 at 11:48 am

    20. мостбет вывод на карту [url=https://mostbet4173.ru/]https://mostbet4173.ru/[/url]

      mostbet_vpEt

      8 Sep 25 at 11:48 am

    21. I enjoy what you guys are up too. Such clever work and exposure!
      Keep up the terrific works guys I’ve incorporated you guys to blogroll.

      Meteor Profit

      8 Sep 25 at 11:51 am

    22. Lancehub

      8 Sep 25 at 11:53 am

    23. диплом техникума купить киев [url=http://www.educ-ua6.ru]http://www.educ-ua6.ru[/url] .

      Diplomi_joMl

      8 Sep 25 at 11:54 am

    24. Thank you, I have recently been looking for information about this subject for a while and yours
      is the greatest I’ve came upon so far. However, what
      about the bottom line? Are you certain concerning the supply?

    25. диплом бакалавра купить стоимость [url=www.educ-ua4.ru/]диплом бакалавра купить стоимость[/url] .

      Diplomi_qgPl

      8 Sep 25 at 11:56 am

    26. mostbet futbol mərcləri [url=https://www.mostbet4142.ru]mostbet futbol mərcləri[/url]

      mostbet_cgSi

      8 Sep 25 at 11:56 am

    27. наркологическая помощь [url=www.narkologicheskaya-klinika-13.ru/]наркологическая помощь[/url] .

    28. mostbet qeydiyyat olmadan giriş [url=www.mostbet4141.ru]www.mostbet4141.ru[/url]

      mostbet_bbPn

      8 Sep 25 at 11:57 am

    29. JamesAnamb

      8 Sep 25 at 11:59 am

    30. купить диплом в спб с занесением в реестр [url=https://4dkp.forum24.ru/?1-18-0-00005399-000-0-0-1752571103/]купить диплом в спб с занесением в реестр[/url] .

      Priobresti diplom lubogo yniversiteta!_trkt

      8 Sep 25 at 12:00 pm

    31. Good post. I am dealing with many of these issues as
      well..

    32. mostbet qeydiyyat pulsuz [url=https://mostbet4142.ru/]mostbet qeydiyyat pulsuz[/url]

      mostbet_eeSi

      8 Sep 25 at 12:01 pm

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

      Diplomi_tzPl

      8 Sep 25 at 12:02 pm

    34. Greetings! I recently came across this fantastic article on online casinos and simply pass
      up the chance to share it. If you’re someone who’s
      looking to explore more about the industry
      of online casinos, this is absolutely.

      I’ve always been interested in online gaming,
      and after reading this, I gained so much about how online casinos
      work.

      This post does a great job of explaining everything from game strategies.
      If you’re new to the whole scene, or even if you’ve been gambling for
      years, this article is an essential read. I highly recommend it for anyone who wants
      to get informed with casino game dynamics.

      Not only, the article covers some great advice about selecting a reliable online casino, which I think is
      extremely important. Many people overlook this aspect,
      but this post clearly shows you the best ways
      to gamble responsibly.

      What I liked most was the section on rewards and free
      spins, which I think is crucial when choosing a site to play on. The insights
      here are priceless for anyone looking to maximize their winnings.

      Furthermore, the guidelines about budgeting your gambling were very useful.
      The advice is clear and actionable, making
      it easy for gamblers to take control of their gambling habits and stay within their limits.

      The advantages and disadvantages of online gambling were
      also thoroughly discussed. If you’re thinking about trying your luck at an online casino, this article is a great starting
      point to understand both the excitement and the risks involved.

      If you’re into slots, you’ll find tons of valuable tips here.

      They really covers all the popular games in detail, giving you
      the tools you need to boost your skill level.

      Whether you’re into competitive games like
      poker or just enjoy a casual round of slots, this article
      has plenty for everyone.
      I also appreciated the discussion about payment options.

      It’s crucial to know that you’re gambling
      on a site that’s safe and protected. It’s really helps you make sure your personal information is in good hands when you
      bet online.
      If you’re wondering where to start, I highly recommend reading this post.
      It’s clear, informative, and packed with valuable insights.
      Without a doubt, one of the best articles I’ve come across in a
      while on this topic.
      If you haven’t yet, I strongly suggest checking it out and seeing for yourself.

      You won’t regret it! Trust me, you’ll walk away
      feeling like a more informed player in the online casino world.

      Whether you’re a beginner, this article is an excellent resource.
      It helps you avoid common mistakes and teaches you how to have a fun and safe gambling experience.
      Definitely worth checking out!
      I appreciate how well-researched and thorough this article is.

      I’ll definitely be coming back to it whenever I need a refresher on online gambling.

      Has anyone else read it yet? What do you think? Let me know your thoughts in the
      comments!

      casino article

      8 Sep 25 at 12:02 pm

    35. EverGreenRx USA [url=http://evergreenrxusas.com/#]cialis insurance coverage[/url] cialis side effects a wife’s perspective

      Gregoryaerof

      8 Sep 25 at 12:03 pm

    36. mostbet aviator qanday o‘ynash [url=https://mostbet4172.ru]mostbet aviator qanday o‘ynash[/url]

      mostbet_uuKa

      8 Sep 25 at 12:04 pm

    37. наркология клиника [url=www.narkologicheskaya-klinika-13.ru/]www.narkologicheskaya-klinika-13.ru/[/url] .

    38. купить легальный диплом техникума [url=www.educ-ua7.ru]купить легальный диплом техникума[/url] .

      Diplomi_goEr

      8 Sep 25 at 12:07 pm

    39. интернет по адресу
      inernetvkvartiru-ekaterinburg006.ru
      интернет домашний екатеринбург

      internetelini

      8 Sep 25 at 12:07 pm

    40. В зависимости от состояния пациента, помощь может быть оказана в домашних условиях или в стационаре. Вызов нарколога на дом особенно актуален при абстинентном синдроме или тяжелом алкогольном опьянении. Как отмечается в материалах НМИЦ психиатрии и наркологии, в таких ситуациях крайне важно избежать самолечения и довериться врачам, способным правильно подобрать препараты и дозировки.
      Углубиться в тему – [url=https://narkologicheskaya-pomoshh-arkhangelsk0.ru/]наркологическая помощь на дому в архангельске[/url]

      Walternup

      8 Sep 25 at 12:10 pm

    41. Врач самостоятельно оценивает тяжесть интоксикации и назначает необходимый курс инфузий, физиопроцедур и приём препаратов. Варианты терапии включают детокс-комплекс, коррекцию водно-электролитного баланса и витаминотерапию.
      Подробнее можно узнать тут – [url=https://narkologicheskaya-klinika-arkhangelsk0.ru/]бесплатная наркологическая клиника в архангельске[/url]

      Donaldnag

      8 Sep 25 at 12:10 pm

    42. Thiis is reallyy interesting, You’re ann overly skilled blogger.
      I’ve joined your fedd and sit upp for looking for extra of your wonderful post.
      Additionally, I’ve shared your web site
      in my social networks

      Anthropology

      8 Sep 25 at 12:11 pm

    43. You have made some really good points there. I checked on the internet to learn more about the issue and found most people will
      go along with your views on this site.

    44. купить диплом жд техникума [url=www.educ-ua7.ru]купить диплом жд техникума[/url] .

      Diplomi_maEr

      8 Sep 25 at 12:12 pm

    45. mostbet com site oficial [url=http://mostbet4173.ru/]mostbet com site oficial[/url]

      mostbet_dzEt

      8 Sep 25 at 12:12 pm

    46. Как распознать легальный центр:
      Ознакомиться с деталями – http://lechenie-narkomanii-yaroslavl0.ru

      ScottFut

      8 Sep 25 at 12:13 pm

    47. Критерии оценки профессионального уровня сотрудников:
      Исследовать вопрос подробнее – [url=https://lechenie-alkogolizma-yaroslavl0.ru/]клиника лечения алкоголизма[/url]

      Kennethwed

      8 Sep 25 at 12:13 pm

    48. darknet marketplace darknet markets url darknet market [url=https://darknetmarketsgate.com/ ]darknet market list [/url]

      Donaldfup

      8 Sep 25 at 12:14 pm

    49. статьи о маркетинге [url=https://statyi-o-marketinge2.ru/]статьи о маркетинге[/url] .

    Leave a Reply