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 111,685 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 , , ,

111,685 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. Davidjealp

    27 Oct 25 at 8:03 pm

  2. куплю диплом медсестры в москве [url=https://frei-diplom15.ru]куплю диплом медсестры в москве[/url] .

    Diplomi_qjoi

    27 Oct 25 at 8:05 pm

  3. услуги гидроизоляции подвала [url=www.gidroizolyaciya-cena-7.ru/]www.gidroizolyaciya-cena-7.ru/[/url] .

  4. В городе и пригороде организован круглосуточный приём с возможностью выезда на дом. Координатор уточняет только клинически значимые данные: регулярные препараты и дозировки, аллергии, недавние эпизоды судорог/психозов, доступ к розетке, возможность обеспечить «тихое окно» на 2–3 часа. Если в квартире многолюдно или идёт ремонт, предложим «тихий» стационар с отдельным входом и тем же ведущим врачом; после стабилизации зеркально перенесём маршрут обратно домой, чтобы не терять темп и доверие.
    Детальнее – [url=https://narkologicheskaya-klinika-v-nizhnem-novgorode16.ru/]наркологическая клиника цены нижний новгород[/url]

    Prestonned

    27 Oct 25 at 8:08 pm

  5. кракен qr код
    kraken зеркало

    Henryamerb

    27 Oct 25 at 8:11 pm

  6. kraken vk5
    kraken

    Henryamerb

    27 Oct 25 at 8:12 pm

  7. В первые два часа после прибытия бригады важно не «сделать побольше», а принять наименьшее количество решений, которое реально меняет картину. Команда фиксирует базовую линию (ЧСС, АД, SpO?, температура, шкала тошноты/тремора), даёт антиеметический мост и запускает регидратацию. При тахикардии — добавляет антивегетативный контур. Семья получает сценарий ночи: когда приглушить свет, когда предложить воду, какие цифры на тонометре считать нормой и при каких — звонить. Такой протокол экономит время и силы, а главное — превращает вечер из хаотичного в управляемый, снижая риск ночных экстренных вызовов и «эмоциональных качелей».
    Получить дополнительные сведения – [url=https://kapelnicza-ot-zapoya-v-chelyabinske16.ru/]капельница от запоя недорого в челябинске[/url]

    Craigtic

    27 Oct 25 at 8:12 pm

  8. I absolutely love your blog and find almost all of your post’s
    to be what precisely I’m looking for. Would you offer guest writers to write content in your case?
    I wouldn’t mind writing a post or elaborating on a lot
    of the subjects you write with regards to here. Again,
    awesome weblog!

    webpage

    27 Oct 25 at 8:13 pm

  9. MiguelActic

    27 Oct 25 at 8:14 pm

  10. Наркологическая клиника в клинике в Казани — это современный медицинский центр, специализирующийся на лечении алкогольной и наркотической зависимости. Основное направление деятельности заключается в проведении детоксикации, восстановлении работы нервной системы и формировании устойчивой мотивации к отказу от употребления психоактивных веществ. Все процедуры проводятся в условиях полной анонимности и медицинского контроля, что обеспечивает безопасность и доверие со стороны пациентов. Программа терапии строится по принципам доказательной медицины и индивидуального подбора лечебных средств.
    Разобраться лучше – https://narkologicheskaya-clinika-v-kazani16.ru/chastnaya-narkologicheskaya-klinika-kazan/

    WyattHag

    27 Oct 25 at 8:16 pm

  11. kraken официальный
    кракен vpn

    Henryamerb

    27 Oct 25 at 8:17 pm

  12. купить диплом в северодвинске [url=www.rudik-diplom1.ru/]купить диплом в северодвинске[/url] .

    Diplomi_user

    27 Oct 25 at 8:18 pm

  13. наркологические клиники в москве частные [url=http://narkologicheskaya-klinika-25.ru/]http://narkologicheskaya-klinika-25.ru/[/url] .

  14. Капельницы в «ЧелМед Детокс» — это модульная конструкция, а не «микс на удачу». База — регидратация и коррекция электролитов. По показаниям добавляются антиэметики, антивегетативные средства, поддержка метаболизма, витамины группы B, магний. Отдельным блоком идёт ночной модуль: задача — собрать восстановительный сон, не «перелечивая» пациента. Каждый модуль имеет свою цель и стоп-критерий. Врач избегает одновременного запуска нескольких новых элементов, чтобы видеть причинно-следственную связь и точно понимать, что именно работает у конкретного человека.
    Получить больше информации – [url=https://vyvod-iz-zapoya-v-chelyabinske16.ru/]вывод из запоя вызов[/url]

    MichaelPix

    27 Oct 25 at 8:19 pm

  15. наркология клиника [url=https://narkologicheskaya-klinika-27.ru/]наркология клиника[/url] .

  16. Hey there I am so excited I found your webpage, I really found you by error, while I was looking
    on Google for something else, Anyways I am here now and would just like to say cheers for a incredible post and a all round
    entertaining blog (I also love the theme/design), I don’t have
    time to look over it all at the minute but I have bookmarked
    it and also included your RSS feeds, so when I have time I will be back
    to read more, Please do keep up the fantastic work.

    Visit This Link

    27 Oct 25 at 8:21 pm

  17. купить диплом техникума с реестром [url=www.frei-diplom10.ru]купить диплом техникума с реестром[/url] .

    Diplomi_vuEa

    27 Oct 25 at 8:21 pm

  18. анонимная наркология [url=https://narkologicheskaya-klinika-25.ru/]анонимная наркология[/url] .

  19. kraken онлайн
    kraken 2025

    Henryamerb

    27 Oct 25 at 8:24 pm

  20. наркологические услуги москвы [url=http://www.narkologicheskaya-klinika-27.ru]http://www.narkologicheskaya-klinika-27.ru[/url] .

  21. Получить диплом о высшем образовании можем помочь. Куплю диплом техникума недорого в Волжском – [url=http://diplomybox.com/kupit-diplom-tekhnikuma-v-volzhskom/]diplomybox.com/kupit-diplom-tekhnikuma-v-volzhskom[/url]

    Cazrsvm

    27 Oct 25 at 8:31 pm

  22. кракен онлайн
    kraken зеркало

    Henryamerb

    27 Oct 25 at 8:32 pm

  23. MiguelActic

    27 Oct 25 at 8:33 pm

  24. кракен обмен
    кракен 2025

    Henryamerb

    27 Oct 25 at 8:33 pm

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

  26. Hi there, constantly i used to check website posts
    here in the early hours in the daylight, for the reason that i like to
    find out more and more.

    GPT +9A Plus

    27 Oct 25 at 8:35 pm

  27. Quality posts is the secret to be a focus for the users to pay a visit the site,
    that’s what this website is providing.

  28. ремонт подвала в частном доме [url=gidroizolyaciya-cena-7.ru]gidroizolyaciya-cena-7.ru[/url] .

  29. кракен даркнет
    кракен vpn

    Henryamerb

    27 Oct 25 at 8:38 pm

  30. платный наркологический стационар [url=https://narkologicheskaya-klinika-25.ru/]narkologicheskaya-klinika-25.ru[/url] .

  31. Hello there! This post could not be written any
    better! Reading this post reminds me of my previous room mate!
    He always kept talking about this. I will forward this article to
    him. Pretty sure he will have a good read.
    Thanks for sharing!

  32. диплом мед колледжа купить москва [url=www.frei-diplom10.ru]www.frei-diplom10.ru[/url] .

    Diplomi_apEa

    27 Oct 25 at 8:40 pm

  33. лечение зависимостей в москве [url=www.narkologicheskaya-klinika-25.ru/]www.narkologicheskaya-klinika-25.ru/[/url] .

  34. kraken
    kraken

    Henryamerb

    27 Oct 25 at 8:45 pm

  35. Georgerah

    27 Oct 25 at 8:47 pm

  36. Georgerah

    27 Oct 25 at 8:50 pm

  37. Для наглядности приведена таблица, отражающая распространённые методы лечения и их цели:
    Подробнее тут – [url=https://narkologicheskaya-clinika-v-samare16.ru/]наркологическая клиника лечение алкоголизма в самаре[/url]

    ThomasMew

    27 Oct 25 at 8:52 pm

  38. conorjmurphy – Excellent resource, practical guides make home projects feel stress-free always.

    Allen Bidstrup

    27 Oct 25 at 8:52 pm

  39. кракен обмен
    kraken зеркало

    Henryamerb

    27 Oct 25 at 8:53 pm

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

  41. Kamagra Oral Jelly Deutschland [url=https://vitalpharma24.shop/#]vitalpharma24[/url] Kamagra Oral Jelly Deutschland

    MichaelRen

    27 Oct 25 at 8:53 pm

  42. кракен маркетплейс
    kraken

    Henryamerb

    27 Oct 25 at 8:54 pm

  43. MiguelActic

    27 Oct 25 at 8:56 pm

  44. наркология лечение [url=www.narkologicheskaya-klinika-27.ru/]наркология лечение[/url] .

  45. MiguelActic

    27 Oct 25 at 8:57 pm

  46. You’re so interesting! I don’t believe I’ve read through anything like that before.
    So wonderful to find someone with a few unique thoughts on this subject.
    Seriously.. thank you for starting this up. This web site is something that is required on the web, someone with some originality!

    our website

    27 Oct 25 at 8:59 pm

  47. kraken сайт
    kraken vpn

    Henryamerb

    27 Oct 25 at 8:59 pm

  48. Простая подготовка уменьшает стресс, повышает переносимость капельницы и делает оценку состояния более точной. Попросите одного ответственного взрослого быть на связи с врачом — так решения будут приниматься быстрее, а ночной интервал пройдёт спокойнее и предсказуемее.
    Выяснить больше – http://vyvod-iz-zapoya-v-chelyabinske16.ru

    MichaelPix

    27 Oct 25 at 9:00 pm

  49. MiguelActic

    27 Oct 25 at 9:00 pm

  50. анонимная наркологическая помощь в москве [url=https://narkologicheskaya-klinika-25.ru/]анонимная наркологическая помощь в москве[/url] .

Leave a Reply