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 112,555 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 , , ,

112,555 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. usaonlinecasinos.org – Navigation felt smooth, found everything quickly without any confusing steps.

    Trent Virula

    26 Oct 25 at 5:11 am

  2. birxbet giri? [url=http://www.1xbet-13.com]http://www.1xbet-13.com[/url] .

    1xbet_ujKa

    26 Oct 25 at 5:14 am

  3. 1xbet spor bahislerinin adresi [url=http://www.1xbet-10.com]1xbet spor bahislerinin adresi[/url] .

    1xbet_rwea

    26 Oct 25 at 5:14 am

  4. 1x giri? [url=www.1xbet-16.com/]www.1xbet-16.com/[/url] .

    1xbet_ljOn

    26 Oct 25 at 5:14 am

  5. Объяснения на https://mr-master.com.ua/ru/ помогли выбрать шторы вместо дверей.

    mr-master-662

    26 Oct 25 at 5:15 am

  6. kraken vk4
    kraken vk5

    JamesDaync

    26 Oct 25 at 5:15 am

  7. По сторінці https://siviagmen.com обрав ремонт самокатів Черкаси.

    siviagmen-763

    26 Oct 25 at 5:16 am

  8. Підібрала фікус mr-master.com.ua за фото, назвами й описом.

    mr-master-190

    26 Oct 25 at 5:17 am

  9. Как крепить ветровую https://buybuyviamen.com планку на профнастил — объяснено чётко.

    buybuyviamen-641

    26 Oct 25 at 5:17 am

  10. дезинфекция медицинских учреждений с гарантией – это важно, нашли такую фирму.
    уничтожение рыжих тараканов

    KennethceM

    26 Oct 25 at 5:19 am

  11. 1xbwt giri? [url=http://www.1xbet-15.com]http://www.1xbet-15.com[/url] .

    1xbet_dfpl

    26 Oct 25 at 5:20 am

  12. mostbet download [url=https://mostbet12032.ru]https://mostbet12032.ru[/url]

    mostbet_kg_fcmt

    26 Oct 25 at 5:20 am

  13. Спасибо за обработка квартиры от клопов! Всё чисто и безопасно.
    уничтожение тараканов на кухне

    KennethceM

    26 Oct 25 at 5:21 am

  14. hopeandlace – They seem to focus on weddings/events with style and flair, good fit if you like design-forward work.

    Kenyatta Ahrent

    26 Oct 25 at 5:23 am

  15. Варианты на https://mr-master.com.ua/uk/ помогли выбрать шторы на балкон от солнца.

    mr-master-606

    26 Oct 25 at 5:23 am

  16. 1xbet giri? linki [url=https://1xbet-15.com]1xbet giri? linki[/url] .

    1xbet_wbpl

    26 Oct 25 at 5:26 am

  17. 1xbet giri? adresi [url=http://1xbet-13.com/]1xbet giri? adresi[/url] .

    1xbet_beKa

    26 Oct 25 at 5:26 am

  18. kraken зеркало
    кракен 2025

    JamesDaync

    26 Oct 25 at 5:27 am

  19. скачать mostbet casino [url=http://mostbet12032.ru/]http://mostbet12032.ru/[/url]

    mostbet_kg_yemt

    26 Oct 25 at 5:27 am

  20. Target is in trouble. And while it’s easy to get lost in the company’s recent (poor) handling of American culture war narratives that cast it as too “woke” or too willing to cave to online fascists, the root of Target’s problems runs deep.
    [url=https://tripsca43.win]трипскан[/url]
    Don’t get me wrong – the massive consumer boycotts from Black organizers have done damage. And there are probably folks on the far right who think even Target’s toned-down, overwhelmingly beige Pride merch this year was still too loud.
    https://tripsca43.win
    tripskan
    But its stock is in the gutter and sales have been falling for two years because of good ol’ business fundamentals. It overstocked. It lost the pulse of its customers. It went up against Amazon Prime with… actually, does anyone know what Target’s Amazon Prime competitor is called?
    The brand we petite bourgeoisie once playfully referred to as Tar-zhay has lost its spark. The company reported a decline in sales for a third-straight quarter, part of a broader trend of falling or flat sales for two years. Employees have lost confidence in the company’s direction. And 2025 has been a particularly rough financially, as Black shoppers organized a boycott over Target’s decision to cave to right-wing pressure on diverse hiring goals.
    Shares were down 10% Wednesday.

    It’s not to say the new guy, Michael Fiddelke, is unqualified. He’s been at Target since he started as an intern more than 20 years ago, after all. But Wall Street is clearly concerned that Target’s leadership is underestimating the severity of the need for a significant change— just as President Donald Trump’s tariffs on imported goods threaten the entire retail industry.

    Appointing a company lifer “does not necessarily remedy the problems of entrenched groupthink and the inward-looking mindset that have plagued Target for years,” Neil Saunders, an analyst at GlobalData Retail, said in a note to clients Wednesday.

    Missing the mark
    In its 2010s heyday, Target became a go-to for consumers who liked a bargain but didn’t necessarily like bargain-hunting. The shelves felt well-curated. You’d go to Target because it had one thing you needed and 12 things you didn’t know you needed. It was stocked with Millennial cringe long before Gen Z gave us the term Millennial cringe.

    Target’s sales held strong through the pandemic as remote workers set up home offices and stocked up on essentials. Months of lockdown also benefited the store as people began refreshing their spaces because they didn’t really have much else to do and they were staring at the same walls all the time.

    Michaelgidge

    26 Oct 25 at 5:31 am

  21. Hello there, You have done an excellent job.
    I’ll definitely digg it and personally recommend to my friends.
    I am sure they’ll be benefited from this
    site.

  22. Appreciate the recommendation. Will try it out.

  23. farmacia online para hombres [url=https://confiafarmacia.com/#]Confia Farmacia[/url] Viagra sin prescripción médica

    Davidduese

    26 Oct 25 at 5:32 am

  24. 今は言えない理由があって……付け加えれば大英帝国の利益のためにも……大尉の悲劇的な死は当分のあいだ、新聞から隠しておかねばなりません.もちろん死亡の状況については伏せるということです.ミニ ラブドール

    ラブドール

    26 Oct 25 at 5:33 am

  25. После обработка от клопов стоимость насекомые исчезли навсегда!
    дезинсекция цена

    KennethceM

    26 Oct 25 at 5:33 am

  26. В кафе тараканы? Вызовите обработка от клопов!
    дезинфекция медицинских учреждений

    KennethceM

    26 Oct 25 at 5:34 am

  27. trabas007hoki – I’d like to see more about what they offer—info seems light so far.

  28. купить медицинский диплом медсестры [url=https://frei-diplom15.ru/]купить медицинский диплом медсестры[/url] .

    Diplomi_ncoi

    26 Oct 25 at 5:36 am

  29. 1xbet tr [url=www.1xbet-15.com]1xbet tr[/url] .

    1xbet_hepl

    26 Oct 25 at 5:36 am

  30. мостбет ставки [url=http://mostbet12032.ru]мостбет ставки[/url]

    mostbet_kg_bzmt

    26 Oct 25 at 5:36 am

  31. We stumbled over here by a different web page and thought I
    may as well check things out. I like what I see so now
    i am following you. Look forward to checking out
    your web page for a second time.

  32. 1xbet t?rkiye giri? [url=http://1xbet-10.com]1xbet t?rkiye giri?[/url] .

    1xbet_hxea

    26 Oct 25 at 5:38 am

  33. 1xbet turkey [url=https://1xbet-12.com/]1xbet-12.com[/url] .

    1xbet_jySr

    26 Oct 25 at 5:38 am

  34. кракен клиент
    kraken marketplace

    JamesDaync

    26 Oct 25 at 5:40 am

  35. 1xbet turkey [url=http://1xbet-10.com/]http://1xbet-10.com/[/url] .

    1xbet_xqea

    26 Oct 25 at 5:40 am

  36. and spectacles,ラブドール 女性 用in order to make a prey of incautious strangers.

    ラブドール

    26 Oct 25 at 5:41 am

  37. 1xbet g?ncel [url=https://1xbet-12.com/]1xbet g?ncel[/url] .

    1xbet_rvSr

    26 Oct 25 at 5:41 am

  38. 1xbet g?ncel giri? [url=https://www.1xbet-15.com]1xbet g?ncel giri?[/url] .

    1xbet_wypl

    26 Oct 25 at 5:43 am

  39. 1xbet giri? [url=http://1xbet-13.com/]1xbet giri?[/url] .

    1xbet_zrKa

    26 Oct 25 at 5:44 am

  40. motivilovesmusic – I checked the site and didn’t find much clear info about the team or purpose behind it.

    Benjamin Dest

    26 Oct 25 at 5:44 am

  41. Hello to all, for the reason that I am truly keen of reading this blog’s post to be updated daily. It contains fastidious data.
    kra42 cc

    Timsothydet

    26 Oct 25 at 5:45 am

  42. MannensApotek [url=https://mannensapotek.shop/#]Viagra utan läkarbesök[/url] apotek online utan recept

    Davidduese

    26 Oct 25 at 5:45 am

  43. скачать официальный сайт мостбет [url=http://mostbet12032.ru/]http://mostbet12032.ru/[/url]

    mostbet_kg_ljmt

    26 Oct 25 at 5:46 am

  44. 1xbwt giri? [url=https://1xbet-16.com/]1xbet-16.com[/url] .

    1xbet_fdOn

    26 Oct 25 at 5:51 am

  45. Ресторан чистый после профессиональная дератизация.
    уничтожение клопов

    KennethceM

    26 Oct 25 at 5:52 am

  46. bznpjzw

    26 Oct 25 at 5:52 am

  47. Где вызвать уничтожение вредителей круглосуточно? Время позднее.
    уничтожение рыжих тараканов

    KennethceM

    26 Oct 25 at 5:52 am

  48. 1xbet yeni giri? adresi [url=http://www.1xbet-12.com]http://www.1xbet-12.com[/url] .

    1xbet_uySr

    26 Oct 25 at 5:53 am

  49. Нужна дезинфекция квартиры после умершего для автомобиля, посоветуйте.
    вывести тараканов

    KennethceM

    26 Oct 25 at 5:53 am

  50. 1xbet g?ncel [url=https://www.1xbet-10.com]1xbet g?ncel[/url] .

    1xbet_lcea

    26 Oct 25 at 5:53 am

Leave a Reply