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 23,102 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 , , ,

    23,102 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. Heya this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have
      to manually code with HTML. I’m starting a blog soon but have no coding know-how
      so I wanted to get guidance from someone with experience.
      Any help would be enormously appreciated!

    2. Hello, I do think your site may be having browser compatibility issues.
      Whenever I look at your website in Safari, it looks fine
      however, if opening in Internet Explorer, it has some overlapping issues.
      I merely wanted to give you a quick heads up! Other than that, great website!

      Powell's Plumbing

      21 Aug 25 at 3:44 am

    3. qpfeof3162

      21 Aug 25 at 3:50 am

    4. СтавкиПрогнозы [url=stavki-prognozy-one.ru]stavki-prognozy-one.ru[/url] .

    5. Magnificent goods from you, man. I have understand your stuff
      previous to and you’re just too wonderful. I actually like what
      you have acquired here, certainly like what you are saying and the way in which you say it.
      You make it enjoyable and you still care for to keep it wise.

      I cant wait to read much more from you. This is actually a terrific site.

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

      TimothyKam

      21 Aug 25 at 3:56 am

    7. My relatives every time say that I am wasting my time here at net, except I know I am getting experience every day by reading
      such nice content.

      macauslot88

      21 Aug 25 at 3:57 am

    8. These are really impressive ideas in concerning blogging. You have touched some nice factors here.
      Any way keep up wrinting.

      Source

      21 Aug 25 at 3:57 am

    9. you are in point of fact a good webmaster. The website loading pace is
      incredible. It sort of feels that you are doing any
      unique trick. In addition, The contents are masterwork.
      you have done a fantastic task on this matter!

    10. ставки прогнозы [url=http://www.stavki-prognozy-one.ru]http://www.stavki-prognozy-one.ru[/url] .

    11. Charleswar

      21 Aug 25 at 3:59 am

    12. ArturoVoift

      21 Aug 25 at 4:03 am

    13. свидетельство о разводе купить недорого [url=educ-ua4.ru]educ-ua4.ru[/url] .

      Diplomi_nuPl

      21 Aug 25 at 4:05 am

    14. 20
      Получить больше информации – [url=https://nazalnyj.ru/]нарколог вывод из запоя в москве[/url]

      DonaldFUP

      21 Aug 25 at 4:11 am

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

      StevenGuirl

      21 Aug 25 at 4:12 am

    16. I think this is one of the most significant information for me.
      And i’m glad reading your article. But want to remark on few general things, The web site style is wonderful, the
      articles is really excellent : D. Good job, cheers

      Voltryzapex

      21 Aug 25 at 4:12 am

    17. Neat blog! Is your theme custom made or did you download
      it from somewhere? A design like yours with a few simple
      adjustements would really make my blog shine. Please let me know where you got your theme.
      Thank you

      macauslot88

      21 Aug 25 at 4:15 am

    18. Everything is very open with a really clear clarification of the challenges.
      It was truly informative. Your site is very helpful. Many
      thanks for sharing!

      site

      21 Aug 25 at 4:21 am

    19. ArturoVoift

      21 Aug 25 at 4:24 am

    20. Hi there it’s me, I am also visiting this website daily, this site is
      truly nice and the visitors are really sharing good thoughts.

    21. купить диплом в одессе [url=http://educ-ua4.ru/]купить диплом в одессе[/url] .

      Diplomi_ojPl

      21 Aug 25 at 4:29 am

    22. Do you mind if I quote a couple of your articles as long as I
      provide credit and sources back to your weblog?
      My website is in the very same area of interest as
      yours and my users would genuinely benefit from some of the information you
      present here. Please let me know if this ok with you.
      Thanks a lot!

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

    24. It’s difficult to find knowledgeable people for this subject, but
      you sound like you know what you’re talking about! Thanks

    25. Сильно ценный программа для пользователей, кто часто передвигается населенными пунктами и городами.
      Планировщик маршрутов
      способен сберечь время и установить эффективный путь.
      Очень нравится функция
      принимать во внимание несколько
      видов транспорта. Советую каждому, кто обращает
      внимание на комфорт и эффективность во время поездок.

    26. Charleswar

      21 Aug 25 at 4:38 am

    27. оценка недвижимости Москва оценочная компания

    28. https://kamameds.com/# Kamagra oral jelly USA availability

      Danielchumn

      21 Aug 25 at 4:38 am

    29. купить диплом о средне специальном образовании реестр [url=http://arus-diplom31.ru]купить диплом о средне специальном образовании реестр[/url] .

    30. Hey I know this is off topic but I was wondering
      if you knew of any widgets I could add to my blog that automatically tweet my
      newest twitter updates. I’ve been looking for a
      plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
      Please let me know if you run into anything. I truly enjoy reading
      your blog and I look forward to your new updates.

      adubo

      21 Aug 25 at 4:39 am

    31. можно купить аттестат об окончании 11 классов [url=http://arus-diplom23.ru]http://arus-diplom23.ru[/url] .

      Diplomi_ltSr

      21 Aug 25 at 4:42 am

    32. I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire
      someone to do it for you? Plz reply as I’m looking to design my own blog
      and would like to know where u got this from.
      thank you

      Stahlwandpools

      21 Aug 25 at 4:42 am

    33. Heya! I just wanted to ask if you ever have any trouble with hackers?
      My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due
      to no data backup. Do you have any solutions to stop
      hackers?

      xing

      21 Aug 25 at 4:44 am

    34. I constantly spent my half an hour to read this blog’s articles or reviews
      everyday along with a cup of coffee.

      Track Dexair Sys

      21 Aug 25 at 4:44 am

    35. Hi there, everything is going nicely here and ofcourse every one is sharing facts, that’s genuinely
      excellent, keep up writing.

    36. ArturoVoift

      21 Aug 25 at 4:46 am

    37. где купить аттестат за 11 класс [url=www.arus-diplom22.ru]где купить аттестат за 11 класс[/url] .

      Diplomi_pesl

      21 Aug 25 at 4:48 am

    38. RichardPep

      21 Aug 25 at 4:48 am

    39. Tremendous things here. I’m very happy to look your
      article. Thanks a lot and I am having a look ahead to contact you.
      Will you kindly drop me a e-mail?

    40. Stavki Prognozy [url=www.stavki-prognozy-one.ru]www.stavki-prognozy-one.ru[/url] .

    41. WOW just what I was searching for. Came
      here by searching for มวยเว็บตรง

    42. Extreme heat is a killer. A recent heat wave shows how much more deadly it’s becoming
      [url=https://tripscan.xyz]трипскан вход[/url]
      Extreme heat is a killer and its impact is becoming far, far deadlier as the human-caused climate crisis supercharges temperatures, according to a new study, which estimates global warming tripled the number of deaths in the recent European heat wave.

      For more than a week, temperatures in many parts of Europe spiked above 100 degrees Fahrenheit. Tourist attractions closed, wildfires ripped through several countries, and people struggled to cope on a continent where air conditioning is rare.
      https://tripscan.xyz
      трипскан вход
      The outcome was deadly. Thousands of people are estimated to have lost their lives, according to a first-of-its-kind rapid analysis study published Wednesday.

      A team of researchers, led by Imperial College London and the London School of Hygiene and Tropical Medicine, looked at 10 days of extreme heat between June 23 and July 2 across 12 European cities, including London, Paris, Athens, Madrid and Rome.

      They used historical weather data to calculate how intense the heat would have been if humans had not burned fossil fuels and warmed the world by 1.3 degrees Celsius. They found climate change made Europe’s heat wave 1 to 4 degrees Celsius (1.8 to 7.2 Fahrenheit) hotter.

      The scientists then used research on the relationship between heat and daily deaths to estimate how many people lost their lives.

      They found approximately 2,300 people died during ten days of heat across the 12 cities, around 1,500 more than would have died in a world without climate change. In other words, global heating was responsible for 65% of the total death toll.

      “The results show how relatively small increases in the hottest temperatures can trigger huge surges in death,” the study authors wrote.

      Heat has a particularly pernicious impact on people with underlying health conditions, such as heart disease, diabetes and respiratory problems.

      People over 65 years old were most affected, accounting for 88% of the excess deaths, according to the analysis. But heat can be deadly for anyone. Nearly 200 of the estimated deaths across the 12 cities were among those aged 20 to 65.

      Climate change was responsible for the vast majority of heat deaths in some cities. In Madrid, it accounted for about 90% of estimated heat wave deaths, the analysis found.

      Davidcob

      21 Aug 25 at 5:00 am

    43. It’s really a nice and useful piece of info. I am glad that you just shared this useful information with us.
      Please keep us informed like this. Thanks for sharing.

      toto togel online

      21 Aug 25 at 5:00 am

    44. Московская Академия Медицинского Образования – https://mosamo.ru/ это возможность пройти переподготовку и повышение квалификации по медицине. Мы проводим дистанционное обучение врачей и медицинских работников по 260 направлениям и выдаем документы установленного образца, сертификат дополнительного образования. Узнайте подробнее на сайте.

      newaxhychari

      21 Aug 25 at 5:02 am

    45. Do you mind if I quote a couple of your articles as long
      as I provide credit and sources back to your blog? My blog site is
      in the exact same niche as yours and my visitors would definitely benefit from
      a lot of the information you present here. Please let me know
      if this ok with you. Appreciate it!

      Pink salt trick

      21 Aug 25 at 5:05 am

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

      plinko_kz_qcEr

      21 Aug 25 at 5:07 am

    47. ArturoVoift

      21 Aug 25 at 5:07 am

    48. Процедура всегда начинается с личной консультации. Врач-нарколог выясняет анамнез, оценивает физическое и психическое состояние, рассказывает о возможных методиках и противопоказаниях. После выбора оптимального метода пациенту объясняются все нюансы, отвечают на вопросы, выдают письменные рекомендации по поведению в период действия кодировки.
      Подробнее – [url=https://kodirovanie-ot-alkogolizma-kolomna6.ru/]metody-kodirovaniya-ot-alkogolizma[/url]

      JamesFrupe

      21 Aug 25 at 5:09 am

    49. кашпо для цветов с автополивом [url=http://www.kashpo-s-avtopolivom-spb.ru]кашпо для цветов с автополивом[/url] .

      gorshok s avtopolivom_zysr

      21 Aug 25 at 5:13 am

    50. купить диплом внесенный в реестр [url=https://www.arus-diplom31.ru]купить диплом внесенный в реестр[/url] .

    Leave a Reply