Wanneer casino weer open South Holland

  1. Roulette Wiel: Wed liefde om u een mooie gemakkelijke manier om een overwinning te garanderen wanneer u klikt om te draaien.
  2. 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.
  3. 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 109,755 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 , , ,

109,755 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. ExploreAmazingIdeas – Customer support responded quickly, very helpful and polite throughout the process.

    Earl Botz

    26 Oct 25 at 5:53 pm

  2. клиника наркологическая москва [url=https://narkologicheskaya-klinika-23.ru/]https://narkologicheskaya-klinika-23.ru/[/url] .

  3. sportwetten ohne oasis paysafecard

    Feel free to visit my blog post … live wetten anbieter (Dillon)

    Dillon

    26 Oct 25 at 5:55 pm

  4. kraken РФ
    кракен 2025

    JamesDaync

    26 Oct 25 at 5:55 pm

  5. платный наркологический диспансер москва [url=https://narkologicheskaya-klinika-24.ru/]https://narkologicheskaya-klinika-24.ru/[/url] .

  6. Wow, this post is pleasant, my younger sister is analyzing these things, so I am going to tell her.

  7. 1xbet ?ye ol [url=1xbet-14.com]1xbet-14.com[/url] .

    1xbet_fvet

    26 Oct 25 at 5:57 pm

  8. Henryamerb

    26 Oct 25 at 5:58 pm

  9. FrancisRag

    26 Oct 25 at 5:59 pm

  10. Ukrainian President Volodymyr Zelensky condemned Russian attacks on the Ukrainian regions of Kharkiv, Zaporizhzhia and Sumy on Monday, saying that the Kremlin intends to “humiliate diplomatic efforts” just hours before European leaders visit the White House.
    [url=https://kra41-at.net]kra37[/url]
    “The Russian war machine continues to destroy lives despite everything,” Zelensky said in a statement, hours before he’s due to meet US President Donald Trump in the Oval Office. “That is precisely why we are seeking assistance to put an end to the killings. That is why reliable security guarantees are required. That is why Russia should not be rewarded for its participation in this war.”
    [url=https://kra41—cc.ru]kra37 at[/url]
    “Everyone seeks dignified peace and true security,” the Ukrainian president said. “And at this very moment, the Russians are attacking Kharkiv, Zaporizhzhia, the Sumy region, and Odesa, destroying residential buildings and our civilian infrastructure.”
    [url=https://kra-41at.net]kra42[/url]
    At least seven people were killed in Russia’s attack? on Kharkiv and a further three killed in the ballistic missile strike on the city of Zaporizhzhia, with scores more injured, according to Ukrainian authorities.
    [url=https://kra42-at.cc]kra38 сс[/url]
    “This was a demonstrative and cynical Russian strike,” Zelensky added.
    kra40 cc
    https://kra—42-at.ru

    Ronniefluem

    26 Oct 25 at 6:00 pm

  11. FrancisRag

    26 Oct 25 at 6:00 pm

  12. gratis bonus ohne einzahlung strategien sportwetten – https://Www.kompster.com

  13. Вызвать дезинфекция школы дешево, где?
    уничтожение клещей на даче

    KennethceM

    26 Oct 25 at 6:03 pm

  14. 1xbetgiri? [url=http://1xbet-17.com]1xbetgiri?[/url] .

    1xbet_wlpl

    26 Oct 25 at 6:04 pm

  15. поставка медицинского оборудования [url=www.medoborudovanie-postavka.ru]поставка медицинского оборудования[/url] .

  16. sfdh10.pw – Navigation felt smooth, found everything quickly without any confusing steps.

  17. It’s a pity you don’t have a donate button! I’d without a doubt donate to this outstanding blog!
    I suppose for now i’ll settle for bookmarking and adding your
    RSS feed to my Google account. I look forward to fresh updates and will share this website with
    my Facebook group. Talk soon!

  18. 1x bet [url=http://1xbet-17.com]1x bet[/url] .

    1xbet_lhpl

    26 Oct 25 at 6:05 pm

  19. поставка медоборудования [url=www.medoborudovanie-postavka.ru/]www.medoborudovanie-postavka.ru/[/url] .

  20. кракен даркнет маркет
    kraken darknet

    Henryamerb

    26 Oct 25 at 6:06 pm

  21. Editor’s Choice here: https://www.elboomeran.com

    CedricSyday

    26 Oct 25 at 6:07 pm

  22. Henryamerb

    26 Oct 25 at 6:07 pm

  23. The most valuable is here: https://cascadeclimbers.com

    JasonEmait

    26 Oct 25 at 6:08 pm

  24. I’ve been exploring for a little for any high quality articles or weblog
    posts in this sort of area . Exploring in Yahoo I ultimately stumbled upon this
    website. Studying this information So i’m satisfied to convey that I’ve an incredibly excellent uncanny feeling I
    found out just what I needed. I such a lot
    definitely will make sure to don?t overlook this website and provides it a glance on a continuing basis.

    kra32 at

    26 Oct 25 at 6:09 pm

  25. кракен актуальная ссылка
    kraken ios

    Henryamerb

    26 Oct 25 at 6:11 pm

  26. поставка медицинского оборудования [url=https://medoborudovanie-postavka.ru/]поставка медицинского оборудования[/url] .

  27. one x bet [url=https://www.1xbet-17.com]one x bet[/url] .

    1xbet_owpl

    26 Oct 25 at 6:13 pm

  28. Quality articles or reviews is the secret to interest the visitors
    to go to see the site, that’s what this site is providing.

    Find Out More

    26 Oct 25 at 6:13 pm

  29. To ensure maximum performance of the 1xbet application for iOS, OS is required.Three either more later [url=https://a9c.c91.myftpupload.com/1bet5/ultimate-guide-to-1xbet-casino-malaysia-your/]https://a9c.c91.myftpupload.com/1bet5/ultimate-guide-to-1xbet-casino-malaysia-your/[/url] and iPod touch.

    Rosehaise

    26 Oct 25 at 6:14 pm

  30. кракен даркнет маркет
    кракен маркет

    JamesDaync

    26 Oct 25 at 6:15 pm

  31. Yoga for back and cervical pain

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

  32. Ukrainian President Volodymyr Zelensky condemned Russian attacks on the Ukrainian regions of Kharkiv, Zaporizhzhia and Sumy on Monday, saying that the Kremlin intends to “humiliate diplomatic efforts” just hours before European leaders visit the White House.
    [url=https://kra–42—cc.ru]kra36 сс[/url]
    “The Russian war machine continues to destroy lives despite everything,” Zelensky said in a statement, hours before he’s due to meet US President Donald Trump in the Oval Office. “That is precisely why we are seeking assistance to put an end to the killings. That is why reliable security guarantees are required. That is why Russia should not be rewarded for its participation in this war.”
    [url=https://kra-41-cc.net]kra41 сс[/url]
    “Everyone seeks dignified peace and true security,” the Ukrainian president said. “And at this very moment, the Russians are attacking Kharkiv, Zaporizhzhia, the Sumy region, and Odesa, destroying residential buildings and our civilian infrastructure.”

    At least seven people were killed in Russia’s attack? on Kharkiv and a further three killed in the ballistic missile strike on the city of Zaporizhzhia, with scores more injured, according to Ukrainian authorities.

    “This was a demonstrative and cynical Russian strike,” Zelensky added.
    kra38
    https://kra41-cc.com

    Jamessew

    26 Oct 25 at 6:16 pm

  33. Henryamerb

    26 Oct 25 at 6:17 pm

  34. поставка медоборудования [url=https://medoborudovanie-postavka.ru/]https://medoborudovanie-postavka.ru/[/url] .

  35. Поделитесь отзывами о дезинфекция после потопа! Как качество и цена?
    травля тараканов

    KennethceM

    26 Oct 25 at 6:18 pm

  36. sportwetten online seriös

    Here is my site Pferderennen wetten

  37. 1xbet t?rkiye giri? [url=www.1xbet-14.com/]1xbet t?rkiye giri?[/url] .

    1xbet_iyet

    26 Oct 25 at 6:20 pm

  38. Hello there! I know this is kinda off topic but I was wondering
    if you knew where I could find a captcha plugin for my comment form?

    I’m using the same blog platform as yours and I’m having
    trouble finding one? Thanks a lot!

  39. https://herengezondheid.shop/# Viagra online kopen Nederland

    Hermanereli

    26 Oct 25 at 6:21 pm

  40. I got this web site from my pal who shared with me on the topic of this web site and now
    this time I am visiting this web page and reading very informative
    posts at this place.

  41. Как купить A-PVP в Тайге?Смотрите, что нашел – сайт https://hossevenhome.ru
    . Цены порадовали, доставка заявлена. Кто-то покупал у них? Как у них с надежностью?

    Stevenref

    26 Oct 25 at 6:22 pm

  42. Ukrainian President Volodymyr Zelensky condemned Russian attacks on the Ukrainian regions of Kharkiv, Zaporizhzhia and Sumy on Monday, saying that the Kremlin intends to “humiliate diplomatic efforts” just hours before European leaders visit the White House.
    [url=https://kra—41cc.ru]kra40 сс[/url]
    “The Russian war machine continues to destroy lives despite everything,” Zelensky said in a statement, hours before he’s due to meet US President Donald Trump in the Oval Office. “That is precisely why we are seeking assistance to put an end to the killings. That is why reliable security guarantees are required. That is why Russia should not be rewarded for its participation in this war.”
    [url=https://kra-41at.net]kra41 cc[/url]
    “Everyone seeks dignified peace and true security,” the Ukrainian president said. “And at this very moment, the Russians are attacking Kharkiv, Zaporizhzhia, the Sumy region, and Odesa, destroying residential buildings and our civilian infrastructure.”

    At least seven people were killed in Russia’s attack? on Kharkiv and a further three killed in the ballistic missile strike on the city of Zaporizhzhia, with scores more injured, according to Ukrainian authorities.

    “This was a demonstrative and cynical Russian strike,” Zelensky added.
    kra41 at
    https://kra42-at.com

    Kennethtip

    26 Oct 25 at 6:22 pm

  43. клиника наркологическая платная [url=http://www.narkologicheskaya-klinika-24.ru]http://www.narkologicheskaya-klinika-24.ru[/url] .

  44. поставщик медоборудования [url=https://medoborudovanie-postavka.ru/]medoborudovanie-postavka.ru[/url] .

  45. InspireEverydayLife – Navigation is smooth, layout is clean and visually very appealing overall.

    Bess Reusch

    26 Oct 25 at 6:24 pm

  46. Ich freue mich riesig uber Cat Spins Casino, es bietet eine dynamische Erfahrung. Die Auswahl ist einfach unschlagbar, mit Spielen, die Krypto unterstutzen. Er steigert das Spielvergnugen sofort. Die Mitarbeiter sind schnell und kompetent. Gewinne kommen ohne Verzogerung, dennoch mehr Bonusoptionen waren top. Zusammengefasst, Cat Spins Casino sorgt fur ununterbrochenen Spa?. Daruber hinaus die Oberflache ist benutzerfreundlich, was jede Session spannender macht. Ein super Vorteil ist das VIP-Programm mit besonderen Vorteilen, das die Motivation steigert.
    Vertiefen|

    WildFirear1zef

    26 Oct 25 at 6:24 pm

  47. наркологическая клиника trezviy vibor [url=www.narkologicheskaya-klinika-23.ru]www.narkologicheskaya-klinika-23.ru[/url] .

  48. кракен ссылка
    кракен маркетплейс

    Henryamerb

    26 Oct 25 at 6:25 pm

  49. Henryamerb

    26 Oct 25 at 6:26 pm

  50. Ich schatze die Energie bei Cat Spins Casino, es ladt zu unvergesslichen Momenten ein. Das Spieleportfolio ist unglaublich breit, mit Spielen, die Krypto unterstutzen. Mit einfachen Einzahlungen. Der Kundensupport ist top. Transaktionen laufen reibungslos, manchmal gro?zugigere Angebote waren klasse. Kurz gesagt, Cat Spins Casino ist ein Ort fur pure Unterhaltung. Au?erdem die Navigation ist einfach und klar, das Spielerlebnis steigert. Ein tolles Feature sind die zuverlassigen Krypto-Zahlungen, zuverlassige Transaktionen sichern.
    Eintauchen|

    GlobalTigeron6zef

    26 Oct 25 at 6:26 pm

Leave a Reply