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 107,163 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 , , ,

107,163 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. WilliamJet

    25 Oct 25 at 5:06 am

  2. I think this is among the most important info for me.

    And i’m glad reading your article. But should remark on few general
    things, The website style is wonderful, the articles is
    really excellent : D. Good job, cheers

    Earn Matrix Pro

    25 Oct 25 at 5:07 am

  3. WilliamJet

    25 Oct 25 at 5:07 am

  4. купить диплом в коврове [url=http://rudik-diplom14.ru/]купить диплом в коврове[/url] .

    Diplomi_llea

    25 Oct 25 at 5:09 am

  5. Hello There. I found your weblog the usage of msn. That is an extremely neatly written article.

    I’ll be sure to bookmark it and return to read extra of your useful information. Thank you for
    the post. I’ll definitely comeback.

    Centre Finrivo

    25 Oct 25 at 5:10 am

  6. 1x bet [url=https://1xbet-7.com/]https://1xbet-7.com/[/url] .

    1xbet_aool

    25 Oct 25 at 5:11 am

  7. moeinclub.com – The content covers a wide range of topics which can appeal to many interests.

    Jed Owenby

    25 Oct 25 at 5:11 am

  8. xbet giri? [url=https://1xbet-9.com/]1xbet-9.com[/url] .

    1xbet_ajSn

    25 Oct 25 at 5:12 am

  9. birxbet [url=http://1xbet-4.com]http://1xbet-4.com[/url] .

    1xbet_olol

    25 Oct 25 at 5:15 am

  10. 1xbet tr [url=http://1xbet-9.com]1xbet tr[/url] .

    1xbet_udSn

    25 Oct 25 at 5:18 am

  11. WilliamJet

    25 Oct 25 at 5:19 am

  12. куплю диплом высшего образования [url=https://www.rudik-diplom14.ru]куплю диплом высшего образования[/url] .

    Diplomi_frea

    25 Oct 25 at 5:21 am

  13. bahis sitesi 1xbet [url=http://1xbet-4.com]http://1xbet-4.com[/url] .

    1xbet_lyol

    25 Oct 25 at 5:21 am

  14. Как купить Клад в Усть-Луге?Нашел сайт https://xbanners.ru
    – судя по отзывам ок. Цены адекватные, доставка быстрая. Кто-нибудь заказывал? Как с чистотой?

    Stevenref

    25 Oct 25 at 5:24 am

  15. Discover everyday swaps that cut plastic, save money, and help the planet https://ecofriendlystore.ru/

    EcoFriendNeuct

    25 Oct 25 at 5:26 am

  16. 1xbet lite [url=https://1xbet-9.com/]1xbet-9.com[/url] .

    1xbet_caSn

    25 Oct 25 at 5:30 am

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

    1xbet_ziol

    25 Oct 25 at 5:33 am

  18. 1xbet tr giri? [url=https://1xbet-7.com]https://1xbet-7.com[/url] .

    1xbet_zdol

    25 Oct 25 at 5:34 am

  19. купить диплом косметолога [url=rudik-diplom14.ru]купить диплом косметолога[/url] .

    Diplomi_eeea

    25 Oct 25 at 5:35 am

  20. Goodness, no matter ԝhether establishment proves fancy,
    mathematics serves аs thе decisive topic іn developing assurance
    in figures.
    Οh no, primary maths teaches real-ԝorld implementations including money management, tһus makе sure yoᥙr
    youngster masters tһis right starting уoung.

    Millennia Institute оffers аn unique thгee-year
    pathway tߋ A-Levels, offering flexibility ɑnd depth in commerce, arts, аnd sciences for varied students.
    Іts centralised approach guarantees customised support ɑnd
    holistic advancement thrоugh innovative programs.
    Ⴝtate-of-the-art facilities and dedicated staff develop ɑn engaging environment for academic and personal growth.
    Students benefit fгom partnerships ԝith industries for real-wоrld
    experiences ɑnd scholarships. Alumni prosper іn universities аnd professions,
    highlighting tһe institute’ѕ commitment to lifelong learning.

    Anderson Serangoon Junior College, гesulting from
    tһe strategic merger of Anderson Jubior College ɑnd Serangoon Junior College, produces ɑ
    dynamic and inclusive learning community that prioritizes Ьoth academic
    rigor ɑnd detailed individual development, ensuring students receive
    individualized attention іn a nurturing atmosphere.
    Τһe organization features аn range of advanced facilities, ѕuch as specialized science
    labs equipped ѡith tһe most rеcent innovation,
    interactive class developed fοr group partnership, ɑnd substantial libraries stocked ԝith digital resources, ɑll of ᴡhich empower trainees tߋ dig іnto innovative
    projects іn science, innovation, engineering, ɑnd mathematics.

    Bу positioning a strong focus oon management training аnd character education tһrough structured programs ⅼike
    student councils and mentorship initiatives, students cultivate
    іmportant qualities such ɑs strength, empathy, аnd efficient team effort
    tһat extend bеyond scholastic achievements. Additionally, tһe college’s commitment to
    promoting international awareness appears іn itѕ reputable global exchange programs аnd partnerships ԝith overseas institutions, enabling students tо gain invaluable cross-cultural
    experiences аnd broaden tһeir worldview in preparation fօr a globally linked future.
    Ꭺs a testimony tо its efficiency, graduates fгom Anderson Serangoon Junior College regularlyy acquire admission tߋ
    distinguished universities ƅoth locally and internationally, embodying tһе institution’s unwavering commitment tо producing positive, adaptable, ɑnd complex individuals
    ready tо master diverse fields.

    Αpart Ьeyond school facilities, focus upon mathematics to prevent
    common pitfalls including inattentive errors Ԁuring
    tests.
    Parents, fearful оf losing style engaged lah, robust primary mathematics leads іn ƅetter science grasp аnd tech dreams.

    Oh, mathematics serves аs the groundwork stone for primary education, aiding children ԝith
    geometric thinking іn architecture careers.

    Parents, worry about the difference hor, mathematics groundwork proves vital Ԁuring Junior College t᧐
    understanding figures, essential ᴡithin current digital economy.

    Wah lao, no matter іf institution remains һigh-end, mathematics serves аs the critical topic tο cultivates confidence regarding numƄers.

    Strong A-level performance leads to bettеr mental health post-exams,
    knowing уοu’re ѕet.

    Parents, competitive mode engaged lah, strong primary maths гesults for improved science understanding аs well aas tech dreams.

    Feel free t᧐ visit my web sikte list of secondary school

  21. 1xbet t?rkiye [url=https://1xbet-7.com/]https://1xbet-7.com/[/url] .

    1xbet_wwol

    25 Oct 25 at 5:37 am

  22. В Нижнем Тагиле выездные бригады дежурят 24/7. Координатор уже при первичном звонке собирает ключевые сведения: аллергии, хронические заболевания, список постоянных препаратов, эпизоды судорог или алкогольных психозов в прошлом, последние значения давления и пульса, возможность обеспечить тишину на 2–3 часа, доступ к питьевой воде, особенности подъезда. Вся эта информация помогает врачу подготовить стартовую схему — от выбора профиля инфузии до темпа введения. По запросу организуем немаркированный визит и сдержанные формулировки в документах, чтобы не создавать лишнего внимания со стороны соседей и коллег.
    Изучить вопрос глубже – [url=https://vyvod-iz-zapoya-nizhnij-tagil0.ru/]вывод из запоя нижний тагил[/url]

    ClaudeTwilm

    25 Oct 25 at 5:38 am

  23. certainly like your website however you need to take
    a look at the spelling on quite a few of your posts.
    A number of them are rife with spelling problems and I in finding it very
    troublesome to tell the reality then again I’ll certainly come again again.

  24. Yes! Finally something about Montgomery Roofing – Waco Roofers.

    roofers

    25 Oct 25 at 5:39 am

  25. 1xbet [url=http://1xbet-9.com/]1xbet[/url] .

    1xbet_rdSn

    25 Oct 25 at 5:41 am

  26. centensports.com – Would like to see more user-feedback or community stories in future.

    Doyle Every

    25 Oct 25 at 5:43 am

  27. 1xbet yeni giri? [url=https://1xbet-4.com]https://1xbet-4.com[/url] .

    1xbet_heol

    25 Oct 25 at 5:44 am

  28. 1xbet t?rkiye giri? [url=https://www.1xbet-7.com]https://www.1xbet-7.com[/url] .

    1xbet_ufol

    25 Oct 25 at 5:45 am

  29. купить диплом в иркутске [url=rudik-diplom6.ru]купить диплом в иркутске[/url] .

    Diplomi_bcKr

    25 Oct 25 at 5:45 am

  30. Hello, Neat post. There’s a problem together with your website in internet explorer, might
    test this? IE still is the market leader and a huge element of folks
    will omit your fantastic writing due to this problem.

  31. WilliamJet

    25 Oct 25 at 5:48 am

  32. 1xbet resmi [url=http://1xbet-9.com/]http://1xbet-9.com/[/url] .

    1xbet_hpSn

    25 Oct 25 at 5:50 am

  33. WilliamJet

    25 Oct 25 at 5:50 am

  34. 1xbet com giri? [url=https://www.1xbet-4.com]https://www.1xbet-4.com[/url] .

    1xbet_vcol

    25 Oct 25 at 5:52 am

  35. Как купить Меф в Геленджике?Посоветуйте, стоит ли заказывать на https://lemoon89.ru
    ? Цены привлекательные, доставка есть. Но хочется узнать про фактическое качество.

    Stevenref

    25 Oct 25 at 5:53 am

  36. Hey there! Do you use Twitter? I’d like to follow you if
    that would be ok. I’m undoubtedly enjoying your blog and
    look forward to new updates.

    join jihad

    25 Oct 25 at 5:53 am

  37. Мы работаем без пауз и очередей, принимая пациентов в любое время суток. В распоряжении бригад — немаркированный транспорт для выезда на дом, портативная диагностика (ЭКГ, пульсоксиметрия, экспресс-анализаторы), а в стационаре — палаты с регулируемым микроклиматом и круглосуточный мониторинг жизненных показателей. Вся документация оформляется в нейтральной терминологии, доступ к данным разграничен по ролям, что защищает вашу анонимность.
    Исследовать вопрос подробнее – [url=https://narcologicheskaya-klinika-stavropol0.ru/]наркологическая клиника клиника помощь[/url]

    RonaldEralf

    25 Oct 25 at 5:54 am

  38. 1xbet giri? adresi [url=http://1xbet-7.com]http://1xbet-7.com[/url] .

    1xbet_qlol

    25 Oct 25 at 5:55 am

  39. Кровь на гепатит C Гепатит C, или, как его иногда называют, «ласковый убийца», – это вирусное заболевание печени, которое, к сожалению, часто протекает незаметно в течение многих лет, прежде чем проявиться серьезными осложнениями. Возбудителем является вирус гепатита C (HCV), поражающий клетки печени (гепатоциты) и вызывающий хроническое воспаление. Без своевременной диагностики и лечения хронический гепатит C может привести к циррозу печени, печеночной недостаточности и гепатоцеллюлярной карциноме (раку печени), что делает его одной из главных причин трансплантации печени во всем мире.

    Alonzolep

    25 Oct 25 at 5:58 am

  40. 1xbet yeni giri? [url=https://1xbet-9.com/]1xbet yeni giri?[/url] .

    1xbet_niSn

    25 Oct 25 at 5:59 am

  41. seenministries.com – Visuals are modern and bright, which helps make the message more engaging.

    Sherrell Tarascio

    25 Oct 25 at 6:00 am

  42. J’adore l’ame soul de BassBet Casino, c’est une plateforme qui groove comme une voix soul. La selection de jeux est harmonieuse, comprenant des jeux adaptes aux cryptos. Avec des depots ultra-rapides. L’assistance est rapide et pro, toujours pret a chanter. Les gains arrivent sans attendre, neanmoins des recompenses supplementaires seraient vibrantes. Pour conclure, BassBet Casino est une plateforme qui groove pour les joueurs en quete d’adrenaline ! Par ailleurs la navigation est simple et rythmee, ce qui rend chaque session plus groovy. A souligner les tournois reguliers pour la competition, offre des recompenses continues.
    bassbetcasinopromocodefr.com|

    SoulSpinnerJ2zef

    25 Oct 25 at 6:00 am

Leave a Reply