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 105,302 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 , , ,

105,302 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. kraken сайт
    кракен тор

    kraken ссылка

    24 Oct 25 at 7:56 am

  2. I’m extremely inspired together with your writing skills as
    smartly as with the structure for your weblog. Is this a paid theme or did you modify it yourself?
    Anyway keep up the nice high quality writing, it is uncommon to look a nice
    weblog like this one nowadays..

    new casino sites

    24 Oct 25 at 7:56 am

  3. 1xbet guncel [url=1xbet-giris-8.com]1xbet guncel[/url] .

    1xbet giris_zcPn

    24 Oct 25 at 7:57 am

  4. https://hottips.click/

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

  5. где можно купить диплом медсестры [url=http://frei-diplom14.ru/]где можно купить диплом медсестры[/url] .

    Diplomi_ifoi

    24 Oct 25 at 8:00 am

  6. Где купить Мяу-Мяу в Северобайкальске?Друзья, подскажите с выбором – нашел https://burn-credite.ru
    . Цены вроде ок, доставка заявлена. Кто-нибудь знаком с ними? Насколько надежно?

    Stevenref

    24 Oct 25 at 8:00 am

  7. купить диплом техникума отзывы [url=https://frei-diplom11.ru]купить диплом техникума отзывы[/url] .

    Diplomi_aksa

    24 Oct 25 at 8:02 am

  8. кракен тор
    кракен онлайн

    JamesDaync

    24 Oct 25 at 8:02 am

  9. купить диплом в петрозаводске [url=http://rudik-diplom9.ru/]купить диплом в петрозаводске[/url] .

    Diplomi_flei

    24 Oct 25 at 8:03 am

  10. Эта обзорная заметка содержит ключевые моменты и факты по актуальным вопросам. Она поможет читателям быстро ориентироваться в теме и узнать о самых важных аспектах сегодня. Получите краткий курс по современной информации и оставайтесь в курсе событий!
    Жми сюда — получишь ответ – https://pinstore.com.vn/pinstore-ha-noi-nhung-dieu-thu-vi-ve-linen

    Bobbyfam

    24 Oct 25 at 8:03 am

  11. Useful information. Fortunate me I found your website accidentally, and I am stunned why this twist
    of fate did not came about in advance! I bookmarked it.

  12. farmaci per potenza maschile: Viagra generico online Italia – comprare Sildenafil senza ricetta

    RandySkync

    24 Oct 25 at 8:09 am

  13. great points altogether, you just received a emblem new reader.
    What might you recommend about your publish that you simply
    made some days in the past? Any sure?

    exhaust system

    24 Oct 25 at 8:10 am

  14. 1xbet giri? linki [url=http://www.1xbet-giris-9.com]1xbet giri? linki[/url] .

    1xbet giris_npon

    24 Oct 25 at 8:10 am

  15. промокод для 1win [url=http://1win5519.ru/]промокод для 1win[/url]

    1win_kg_ehEr

    24 Oct 25 at 8:10 am

  16. кракен vk6
    кракен клиент

    kraken ссылка

    24 Oct 25 at 8:12 am

  17. Very rapidly this website will be famous among all
    blog people, due to it’s pleasant articles or reviews

    Viral photo tips

    24 Oct 25 at 8:12 am

  18. Pretty nice post. I just stumbled upon your blog and wanted to say that I have truly enjoyed surfing around your blog posts.
    In any case I will be subscribing to your rss
    feed and I hope you write again very soon!

  19. kraken market
    kraken market

    кракен вход

    24 Oct 25 at 8:13 am

  20. 1xbet tr [url=https://1xbet-giris-7.com/]1xbet tr[/url] .

    1xbet giris_vsKn

    24 Oct 25 at 8:14 am

  21. It’s a pity you don’t have a donate button! I’d definitely donate to this brilliant blog!
    I guess for now i’ll settle for book-marking
    and adding your RSS feed to my Google account. I look forward to new updates and will
    share this site with my Facebook group. Talk soon!

    webpage

    24 Oct 25 at 8:14 am

  22. Saved as a favorite, I really like your web site!

    MV88

    24 Oct 25 at 8:15 am

  23. 1xbet yeni adresi [url=http://1xbet-giris-10.com/]1xbet yeni adresi[/url] .

    1xbet giris_jmka

    24 Oct 25 at 8:15 am

  24. one x bet [url=www.1xbet-giris-7.com/]www.1xbet-giris-7.com/[/url] .

    1xbet giris_dsKn

    24 Oct 25 at 8:17 am

  25. xbet [url=1xbet-7.com]xbet[/url] .

    1xbet_lgol

    24 Oct 25 at 8:17 am

  26. 1win ссылка [url=https://1win5519.ru/]https://1win5519.ru/[/url]

    1win_kg_paEr

    24 Oct 25 at 8:17 am

  27. Ищете просторное такси для семьи, команды или багажа? Minivan Online подаст 8 местный минивэн вовремя, с детскими креслами без доплат и фиксированными тарифами на трансферы в аэропорты Москвы. В автопарке только свежие HYUNDAI Grand Starex, VW Caravelle, Mercedes V Class и другие — чистые, комфортные, с климат контролем. Подробности и онлайн заказ — https://minivan.online Вежливые водители со стажем 20+ лет и большой багажник решат задачу любой сложности.

    kijesupum

    24 Oct 25 at 8:18 am

  28. В этой публикации мы предлагаем подробные объяснения по актуальным вопросам, чтобы помочь читателям глубже понять их. Четкость и структурированность материала сделают его удобным для усвоения и применения в повседневной жизни.
    Изучить эмпирические данные – https://ttechsolutions.lk/16/a-step-by-step-guide-to-creating-a-blog-on-wordpress

    LloydNal

    24 Oct 25 at 8:19 am

  29. кракен актуальная ссылка
    kraken вход

    JamesDaync

    24 Oct 25 at 8:19 am

  30. 1win ставка [url=1win5518.ru]1win5518.ru[/url]

    1win_kg_gdkl

    24 Oct 25 at 8:20 am

  31. купить диплом в оренбурге [url=http://rudik-diplom9.ru]купить диплом в оренбурге[/url] .

    Diplomi_ynei

    24 Oct 25 at 8:21 am

  32. I have learn some good stuff here. Certainly price bookmarking for revisiting.

    I wonder how a lot attempt you put to create this type of excellent informative website.

  33. 신용카드현금화 – 급전이 필요할 때, 신용카드 한도를 안전하고 간편하게
    현금으로 바꿔드립니다. 낮은 수수료, 신용등급
    걱정 없이 즉시 입금, 모든 카드사 이용
    가능

  34. 1win как вывести деньги [url=www.1win5518.ru]www.1win5518.ru[/url]

    1win_kg_zmkl

    24 Oct 25 at 8:22 am

  35. 1xbet spor bahislerinin adresi [url=https://1xbet-giris-8.com]1xbet spor bahislerinin adresi[/url] .

    1xbet giris_eqPn

    24 Oct 25 at 8:22 am

  36. kraken обмен
    кракен онлайн

    kraken сайт

    24 Oct 25 at 8:24 am

  37. Статья содержит практические рекомендации и полезные советы, которые можно легко применить в повседневной жизни. Мы делаем акцент на реальных примерах и проверенных методиках, которые способствуют личностному развитию и улучшению качества жизни.
    Что скрывают от вас? – https://www.johanterlouw.nl/recept-en-recepten/bananen-ijs

    RalphCig

    24 Oct 25 at 8:25 am

  38. скачать 1win на пк [url=www.1win5519.ru]www.1win5519.ru[/url]

    1win_kg_qlEr

    24 Oct 25 at 8:25 am

  39. 1xbet yeni adresi [url=https://1xbet-giris-7.com/]1xbet yeni adresi[/url] .

    1xbet giris_chKn

    24 Oct 25 at 8:27 am

  40. Где купить Лирику в Ермолиное?Ваше мнение о https://zingshoes.ru
    ? Цены привлекательные, доставка быстрая. Кто-то покупал? Хочу знать о качестве?

    Stevenref

    24 Oct 25 at 8:27 am

  41. speed n cash лайфак [url=https://1win5519.ru]https://1win5519.ru[/url]

    1win_kg_slEr

    24 Oct 25 at 8:28 am

  42. Ремонт двигателей Джип [url=https://dzen.ru/a/aPkGhHYePCku9uSe]https://dzen.ru/a/aPkGhHYePCku9uSe[/url] .

  43. Hey there! I’m at work browsing your blog from my new iphone!

    Just wanted to say I love reading through your
    blog and look forward to all your posts! Carry on the great work!

  44. 1xbet t?rkiye [url=http://1xbet-giris-7.com]1xbet t?rkiye[/url] .

    1xbet giris_waKn

    24 Oct 25 at 8:32 am

  45. 1x giri? [url=www.1xbet-giris-9.com/]www.1xbet-giris-9.com/[/url] .

    1xbet giris_wwon

    24 Oct 25 at 8:33 am

  46. Hello my loved one! I wish to say that this post is amazing, nice written and include almost all significant infos.
    I’d like to see more posts like this .

    tritium disposal

    24 Oct 25 at 8:33 am

  47. kraken ios
    kraken onion

    JamesDaync

    24 Oct 25 at 8:34 am

  48. Turn your cleaning into a game with Roomsy. A cozy way to clean your home with Roomsy. https://getroomsy.com/ Roomsy offers a simple, guided checklist that organizes chores and makes keeping a tidy home feel effortless. Cute virtual pet companion. Your pet lives in a tiny version of your home and joins you during cleaning sessions to make tidying more fun and engaging. Level up each room and watch your virtual pet grow happier as your real space gets cleaner, turning daily chores into a rewarding habit.

    syqomsRax

    24 Oct 25 at 8:35 am

  49. Hi it’s me, I am also visiting this web site daily, this site is actually nice and the users are actually sharing good thoughts.

  50. Этот краткий обзор предлагает сжатую информацию из области медицины, включая ключевые факты и последние новости. Мы стремимся сделать информацию доступной и понятной для широкой аудитории, что позволит читателям оставаться в курсе актуальных событий в здравоохранении.
    Детальнее – https://vitalady.ru/novoe/pomoshh-pri-alkogolnoj-zavisimosti-v-permi.html

    Barbaracoege

    24 Oct 25 at 8:37 am

Leave a Reply