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,423 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,423 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. I do agree with all the ideas you have presented to your post.
    They are very convincing and can definitely work.

    Still, the posts are too quick for novices.
    Could you please extend them a little from next time?
    Thank you for the post.

    kra41 cc

    24 Oct 25 at 9:29 am

  2. 1xbetgiri? [url=https://www.1xbet-giris-7.com]https://www.1xbet-giris-7.com[/url] .

    1xbet giris_naKn

    24 Oct 25 at 9:31 am

  3. купить диплом дизайнера [url=rudik-diplom9.ru]купить диплом дизайнера[/url] .

    Diplomi_atei

    24 Oct 25 at 9:33 am

  4. 1 win официальный регистрация [url=https://www.1win5519.ru]https://www.1win5519.ru[/url]

    1win_kg_miEr

    24 Oct 25 at 9:34 am

  5. 1xbet yeni giri? [url=http://www.1xbet-giris-8.com]1xbet yeni giri?[/url] .

    1xbet giris_udPn

    24 Oct 25 at 9:37 am

  6. pastillas de potencia masculinas: pastillas de potencia masculinas – pastillas de potencia masculinas

    RandySkync

    24 Oct 25 at 9:38 am

  7. BrockNeima

    24 Oct 25 at 9:39 am

  8. Капитальный ремонт бензиновых двигателей в Москве [url=http://dzen.ru/a/aPkGhHYePCku9uSe]http://dzen.ru/a/aPkGhHYePCku9uSe[/url] .

  9. BrockNeima

    24 Oct 25 at 9:40 am

  10. 1x bet [url=https://1xbet-giris-8.com]1x bet[/url] .

    1xbet giris_ycPn

    24 Oct 25 at 9:41 am

  11. Эта статья освещает различные аспекты освобождения от зависимости и пути к выздоровлению. Мы обсуждаем важность осознания своей проблемы и обращения за помощью. Читатели получат практические советы о том, как преодолевать трудности и строить новую жизнь без зависимости.
    Подробнее можно узнать тут – https://smartchoices.ru/2024-narkologicheskaya-klinika-istochnik-zhizni-v-omske-am

    PeggyVop

    24 Oct 25 at 9:44 am

  12. Двиговичкофф автосервис [url=dzen.ru/a/aPkGhHYePCku9uSe]dzen.ru/a/aPkGhHYePCku9uSe[/url] .

  13. 1win официальный сайт войти зеркало [url=1win5519.ru]1win5519.ru[/url]

    1win_kg_qnEr

    24 Oct 25 at 9:44 am

  14. Dragon Money – онлайн-казино с слотами,
    рулеткой и лайв-дилерами. Удобный интерфейс, безопасные
    платежи и бонусы для игроков.
    dragon money казино

    WalterDemia

    24 Oct 25 at 9:45 am

  15. куплю диплом младшей медсестры [url=www.frei-diplom14.ru]www.frei-diplom14.ru[/url] .

    Diplomi_zooi

    24 Oct 25 at 9:46 am

  16. 1xbet mobi [url=https://www.1xbet-giris-7.com]https://www.1xbet-giris-7.com[/url] .

    1xbet giris_ayKn

    24 Oct 25 at 9:48 am

  17. купить диплом в железногорске [url=https://rudik-diplom9.ru/]https://rudik-diplom9.ru/[/url] .

    Diplomi_paei

    24 Oct 25 at 9:48 am

  18. 1xbet guncel [url=http://1xbet-giris-9.com/]1xbet guncel[/url] .

    1xbet giris_pwon

    24 Oct 25 at 9:49 am

  19. BrockNeima

    24 Oct 25 at 9:49 am

  20. 1xbet guncel [url=https://1xbet-giris-8.com/]1xbet guncel[/url] .

    1xbet giris_xxPn

    24 Oct 25 at 9:50 am

  21. birxbet giri? [url=https://1xbet-giris-9.com/]https://1xbet-giris-9.com/[/url] .

    1xbet giris_ooon

    24 Oct 25 at 9:52 am

  22. В шляпных коробках «Флорион» раскрывает цветы как ювелирные миниатюры: гармоничные сочетания роз, орхидей, эустомы и гортензии выглядят современно и безупречно держат форму. Удобная подача, продуманная палитра и авторские названия композиций помогают точно передать эмоцию, а заказать легко на https://www.florion.ru/catalog/cvety-v-shlyapnoy-korobke — от лаконичных боксов до эффектных премиум-версий. Доставка по Москве и внимательная сборка — как в лучших ателье флористики.

    gokenamFab

    24 Oct 25 at 9:54 am

  23. You are so awesome! I don’t suppose I’ve truly read through something like this before.
    So good to discover another person with some original thoughts on this subject.
    Seriously.. many thanks for starting this up. This website
    is one thing that’s needed on the internet, someone with
    some originality!

    abortion

    24 Oct 25 at 9:56 am

  24. 1 xbet giri? [url=http://1xbet-4.com/]http://1xbet-4.com/[/url] .

    1xbet_vnol

    24 Oct 25 at 9:57 am

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

    Diplomi_usoi

    24 Oct 25 at 9:57 am

  26. Dragon Money – онлайн-казино с слотами,
    рулеткой и лайв-дилерами. Удобный интерфейс, безопасные
    платежи и бонусы для игроков.
    dragon money официальный сайт

    WalterDemia

    24 Oct 25 at 9:58 am

  27. 1 x bet [url=http://1xbet-giris-8.com]1 x bet[/url] .

    1xbet giris_cdPn

    24 Oct 25 at 10:01 am

  28. В этом интересном тексте собраны обширные сведения, которые помогут вам понять различные аспекты обсуждаемой темы. Мы разбираем детали и факты, делая акцент на важности каждого элемента. Не упустите возможность расширить свои знания и взглянуть на мир по-новому!
    Откройте для себя больше – https://www.innosons.nl/waarom-internet-zon-effectief-middel-is

    RalphCig

    24 Oct 25 at 10:01 am

  29. handicap wetten bedeutung

    Look into my blog post: Wettstar Sportwetten

  30. bahis siteler 1xbet [url=http://www.1xbet-giris-9.com]bahis siteler 1xbet[/url] .

    1xbet giris_fron

    24 Oct 25 at 10:02 am

  31. 1x lite [url=https://1xbet-giris-10.com]1x lite[/url] .

    1xbet giris_ouka

    24 Oct 25 at 10:05 am

  32. 1win телефон приложение [url=1win5518.ru]1win телефон приложение[/url]

    1win_kg_mukl

    24 Oct 25 at 10:05 am

  33. try these guys out

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

  34. Клубника Казино – это место, где каждый игрок найдет что-то особенное для себя.
    В Клубника Казино собрано множество
    развлечений: слоты, рулетки, покер и уникальные игры с живыми
    дилерами. Наша приоритетная цель – обеспечение безопасности и честности игр, чтобы
    каждый игрок мог наслаждаться игрой без лишних забот.

    Почему клубничка казино – это лучший
    выбор? Мы предлагаем выгодные бонусы для новых игроков,
    фриспины и регулярные акции, которые
    помогут вам увеличить шансы на победу.

    Кроме того, мы обеспечиваем быстрые выплаты и круглосуточную техническую поддержку, чтобы ваше время в казино было комфортным.

    Когда стоит начать играть в Клубника Казино?
    Начать играть можно прямо сейчас, чтобы сразу
    получить бонусы и бесплатные вращения.

    Вот что ждет вас в Клубника Казино:

    Выгодные бонусы и бесплатные спины для новичков.

    Участие в турнирах и акциях с крупными призами.

    Каждый месяц Клубника Казино пополняет свою коллекцию новыми играми,
    чтобы вы всегда могли найти что-то
    новое и интересное.

    Клубника Казино – это место, где ваша удача будет на вашей стороне.

  35. В этой публикации мы предлагаем подробные объяснения по актуальным вопросам, чтобы помочь читателям глубже понять их. Четкость и структурированность материала сделают его удобным для усвоения и применения в повседневной жизни.
    Узнать напрямую – https://dhanak.org/blog/prayas-second-home-for-underprivileged-kids

    Davidgrori

    24 Oct 25 at 10:07 am

  36. 1xbet yeni adresi [url=http://www.1xbet-giris-7.com]1xbet yeni adresi[/url] .

    1xbet giris_lbKn

    24 Oct 25 at 10:07 am

  37. I enjoy, cause I found just what I was taking a look for.
    You’ve ended my 4 day lengthy hunt! God Bless you
    man. Have a nice day. Bye

  38. 1xbet g?ncel [url=http://www.1xbet-giris-10.com]1xbet g?ncel[/url] .

    1xbet giris_obka

    24 Oct 25 at 10:09 am

  39. купить диплом в ялте [url=https://rudik-diplom9.ru]купить диплом в ялте[/url] .

    Diplomi_nhei

    24 Oct 25 at 10:09 am

  40. 1xbet resmi giri? [url=http://1xbet-giris-8.com/]1xbet resmi giri?[/url] .

    1xbet giris_zpPn

    24 Oct 25 at 10:09 am

  41. The best is only here: https://www.colehardware.com

    Billyrob

    24 Oct 25 at 10:11 am

  42. 유흥알바는 술집, 클럽, 노래방 등 유흥업소에서 하는 다양한 아르바이트를 통칭합니다.

    주로 야간에 이뤄지며 룸알바, 밤알바, 여성알바
    등 여러 이름으로 불립니다. 높은

    유흥알바

    24 Oct 25 at 10:13 am

  43. 1xbet ?yelik [url=https://1xbet-giris-9.com]1xbet ?yelik[/url] .

    1xbet giris_yoon

    24 Oct 25 at 10:14 am

  44. Dragon Money – онлайн-казино с слотами,
    рулеткой и лайв-дилерами. Удобный интерфейс, безопасные
    платежи и бонусы для игроков.
    как внести депозит dragon money

    WalterDemia

    24 Oct 25 at 10:15 am

  45. Двиговичкофф автосервис [url=http://www.dzen.ru/a/aPkGhHYePCku9uSe]http://www.dzen.ru/a/aPkGhHYePCku9uSe[/url] .

  46. Dragon Money – онлайн-казино с слотами,
    рулеткой и лайв-дилерами. Удобный интерфейс, безопасные
    платежи и бонусы для игроков.
    https://sofiyskiy-monastyr.ru/

    WalterDemia

    24 Oct 25 at 10:16 am

  47. The latest is here: https://www.ielts-mentor.com

    Michaellusia

    24 Oct 25 at 10:17 am

  48. 1xbet turkey [url=1xbet-giris-8.com]1xbet turkey[/url] .

    1xbet giris_bjPn

    24 Oct 25 at 10:17 am

  49. Visit our website: https://superweb.de

    Shawnmip

    24 Oct 25 at 10:18 am

  50. http://mannensapotek.com/# apotek online utan recept

    Hermanereli

    24 Oct 25 at 10:18 am

Leave a Reply