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 122,965 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 , , ,

122,965 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. Eh eh, composed pom pі pi, mathematics proves part in the leading subjects durіng
    Junior College, building groundwork tо A-Level advanced math.

    Αpart from institution resources, focus ᥙpon math to prevent common pitfalls including inattentive
    errors ɗuring assessments.
    Mums ɑnd Dads, fearful օf losing style ߋn lah, solid primary maths
    results for superior scientific understanding
    ɑѕ well as engineering goals.

    Tampines Meridian Junior College, fгom a vibrant merger,
    provides ingenious education іn drama and Malay
    language electives. Innovative facilities support varied streams, consisting οf commerce.

    Talent development and overseas programs foster management ɑnd cultural awareness.
    Ꭺ caring neighborhood motivates compassion ɑnd resilience.
    Students ɑre successful in holistic advancement,
    ɡotten ready for international challenges.

    Yishun Innova Junior College, formed ƅy the merger оf Yishun Junior College аnd Innova Junior College,
    harnesses combined strengths tо champion digital literacy аnd exemplary management, preparing
    students fоr quality in a technology-driven period tһrough forward-focused education. Updated centers, ѕuch as wise class, media production studios,
    аnd innovation labs, promote hands-᧐n learning in emerging fields ⅼike digital media, languages,
    ɑnd computational thinking, promoting imagination ɑnd technical proficiency.
    Varied scholastic ɑnd co-curricular programs, including language immersion courses аnd digital arts cluЬѕ,
    encourage expedition ߋf personal іnterests whiⅼe constructing citizenship worths аnd global awareness.
    Neighborhood engagement activities, fгom regional service projects tο
    worldwide collaborations, cultivate compassion, collective skills, аnd а sense of social duty ɑmongst students.
    As confident ɑnd tech-savvy leaders, Yishun Innova Junior College’ѕ graduates аre
    primed fߋr the digital age, excelling іn college and innovative professions tһɑt require
    versatility ɑnd visionary thinking.

    Alas, minus strong mathematics ԁuring Junior College, regardleѕѕ leading institution youngsters mіght stumble wіth neⲭt-level algebra, thеrefore cultivate tһіs ⲣromptly leh.

    Oi oi, Singapore moms and dads, maths гemains ⅼikely the highly impߋrtant primary discipline, promoting imagination іn issue-resolving іn creative jobs.

    Oi oi, Singapore moms ɑnd dads, mathematics іs ⅼikely tһe extremely essential primary topic,
    promoting innovation tһrough challenge-tackling іn creative jobs.

    Listen uⲣ, Singapore moms and dads, mathematics proves likely the highly crucial primary topic,
    fostering creativity tһrough prօblem-solving іn creative careers.

    Α-level excellence showcases yօur potential tߋ mentors and future bosses.

    Listen ᥙp, Singapore parents, mathematics proves ⅼikely the extremely essential primary subject, promoting
    imagination іn challenge-tackling to groundbreaking jobs.

    Feel free tⲟ ssurf tto my web site: Bartley Secondary School Singapore

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

    Diplomi_auSa

    2 Nov 25 at 9:32 am

  3. WARRIORS88 adalah platform hiburan digital terpercaya yang menghadirkan pengalaman bermain terbaik.
    Akses instan, terlindungi, dan mudah digunakan dengan sistem terbaru.
    Daftar sekarang dan rasakan dunia permainan online bareng komunitas WARRIORS88!

    warriors88

    2 Nov 25 at 9:33 am

  4. екатеринбург купить диплом в реестр [url=http://frei-diplom2.ru/]екатеринбург купить диплом в реестр[/url] .

    Diplomi_fkEa

    2 Nov 25 at 9:33 am

  5. купить диплом с занесением в реестр в спб [url=https://frei-diplom6.ru/]https://frei-diplom6.ru/[/url] .

    Diplomi_syOl

    2 Nov 25 at 9:33 am

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

    Diplomi_roEa

    2 Nov 25 at 9:34 am

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

  8. 1xbet g?ncel [url=https://www.1xbet-giris-2.com]https://www.1xbet-giris-2.com[/url] .

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

    Diplomi_caoi

    2 Nov 25 at 9:36 am

  10. Langsung klik daftar dan login! Warriors88 adalah
    solusi terbaik buat kamu yang cari tempat main slot dan taruhan bola.
    Akses resmi yang valid, proses login instan, dan kesempatan menang tinggi!
    Wajib dicoba!

    warriors88

    2 Nov 25 at 9:36 am

  11. seo news [url=www.reiting-seo-kompaniy.ru/]seo news[/url] .

  12. Excelente resumen sobre las tragamonedas favoritas en Pin Up Casino México.
    Es impresionante cómo juegos como Gates of Olympus, Sweet
    Bonanza y Book of Dead continúan siendo los preferidos.
    Me gustó mucho cómo detallaron las mecánicas de cada juego y sus
    bonificaciones.

    Recomiendo leer el artículo completo si quieres descubrir qué juegos están marcando tendencia en Pin Up Casino.

    La inclusión de juegos clásicos y modernos muestra la variedad del catálogo de Pin-Up Casino.

    No dudes en leer la nota completa y
    descubrir por qué estos juegos son tendencia en los casinos online de México.

    information

    2 Nov 25 at 9:39 am

  13. 1xbwt giri? [url=https://1xbet-giris-5.com/]1xbet-giris-5.com[/url] .

  14. купить диплом для техникума цена [url=educ-ua7.ru]educ-ua7.ru[/url] .

    Diplomi_gkea

    2 Nov 25 at 9:40 am

  15. купить речной диплом [url=rudik-diplom14.ru]купить речной диплом[/url] .

    Diplomi_ssea

    2 Nov 25 at 9:41 am

  16. купить вкладыш с оценками к диплому техникума [url=https://www.frei-diplom10.ru]купить вкладыш с оценками к диплому техникума[/url] .

    Diplomi_ybEa

    2 Nov 25 at 9:41 am

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

    Diplomi_epoi

    2 Nov 25 at 9:43 am

  18. можно купить легальный диплом [url=http://frei-diplom6.ru]http://frei-diplom6.ru[/url] .

    Diplomi_ajOl

    2 Nov 25 at 9:44 am

  19. купить диплом в крыму [url=http://rudik-diplom2.ru/]купить диплом в крыму[/url] .

    Diplomi_xjpi

    2 Nov 25 at 9:44 am

  20. Aussie Meds Hub: Aussie Meds Hub Australia – compare pharmacy websites

    Johnnyfuede

    2 Nov 25 at 9:45 am

  21. купить диплом о среднем специальном образовании с занесением в реестр [url=http://frei-diplom2.ru]купить диплом о среднем специальном образовании с занесением в реестр[/url] .

    Diplomi_qdEa

    2 Nov 25 at 9:46 am

  22. где купить диплом мед колледжа [url=http://www.frei-diplom8.ru]http://www.frei-diplom8.ru[/url] .

    Diplomi_gisr

    2 Nov 25 at 9:46 am

  23. как купить диплом проведенный [url=www.frei-diplom1.ru/]как купить диплом проведенный[/url] .

    Diplomi_zrOi

    2 Nov 25 at 9:46 am

  24. 714428.com – Bookmarked this immediately, planning to revisit for updates and inspiration.

    Renaldo Seay

    2 Nov 25 at 9:47 am

  25. Irish Pharma Finder

    Edmundexpon

    2 Nov 25 at 9:47 am

  26. рейтинг seo студий [url=www.reiting-seo-kompaniy.ru/]рейтинг seo студий[/url] .

  27. диплом медсестры с аккредитацией купить [url=frei-diplom13.ru]диплом медсестры с аккредитацией купить[/url] .

    Diplomi_qkkt

    2 Nov 25 at 9:49 am

  28. кинешемский педагогический колледж диплом 1998 года купить [url=http://frei-diplom9.ru/]http://frei-diplom9.ru/[/url] .

    Diplomi_ciea

    2 Nov 25 at 9:49 am

  29. seo компания москва [url=http://www.reiting-seo-kompaniy.ru]http://www.reiting-seo-kompaniy.ru[/url] .

  30. купить диплом в белово [url=rudik-diplom14.ru]rudik-diplom14.ru[/url] .

    Diplomi_blea

    2 Nov 25 at 9:51 am

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

    Diplomi_exPa

    2 Nov 25 at 9:51 am

  32. купить диплом техникума с занесением в реестр [url=http://educ-ua7.ru/]http://educ-ua7.ru/[/url] .

    Diplomi_jxea

    2 Nov 25 at 9:51 am

  33. купить диплом в армавире [url=https://www.rudik-diplom8.ru]купить диплом в армавире[/url] .

    Diplomi_bdMt

    2 Nov 25 at 9:53 am

  34. Ищу обработка участков от клещей с выездом в область.
    дезинфекция после умерших

    Wernermog

    2 Nov 25 at 9:54 am

  35. купить диплом техникума ссср в минске [url=http://frei-diplom9.ru]купить диплом техникума ссср в минске[/url] .

    Diplomi_wvea

    2 Nov 25 at 9:54 am

  36. купить диплом о высшем образовании с занесением в реестр [url=https://www.frei-diplom2.ru]купить диплом о высшем образовании с занесением в реестр[/url] .

    Diplomi_vhEa

    2 Nov 25 at 9:54 am

  37. a0133.com – Color palette felt calming, nothing distracting, just focused, thoughtful design.

    Mario Gode

    2 Nov 25 at 9:55 am

  38. 19j090.com – Appreciate the typography choices; comfortable spacing improved my reading experience.

    Kiara Kuchta

    2 Nov 25 at 9:56 am

  39. купить проведенный диплом техникума [url=https://www.frei-diplom8.ru]купить проведенный диплом техникума[/url] .

    Diplomi_lnsr

    2 Nov 25 at 9:56 am

  40. seo marketing agency ranking [url=https://reiting-seo-kompaniy.ru/]reiting-seo-kompaniy.ru[/url] .

  41. купить диплом в комсомольске-на-амуре [url=https://www.rudik-diplom13.ru]купить диплом в комсомольске-на-амуре[/url] .

    Diplomi_weon

    2 Nov 25 at 9:57 am

  42. mastersaita.com – Found practical insights today; sharing this article with colleagues later.

    Tristan Staff

    2 Nov 25 at 9:57 am

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

  44. купить диплом с занесением в реестры [url=http://frei-diplom4.ru/]купить диплом с занесением в реестры[/url] .

    Diplomi_ilOl

    2 Nov 25 at 9:58 am

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

    Diplomi_ymkt

    2 Nov 25 at 9:59 am

  46. диплом купить с занесением в реестр рязань [url=http://frei-diplom2.ru]http://frei-diplom2.ru[/url] .

    Diplomi_iiEa

    2 Nov 25 at 9:59 am

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

  48. Mantap, saya sangat suka dengan situs ini.

    Warriors88 menawarkan akses cepat ke berbagai permainan online seperti slot,
    live casino, dan taruhan olahraga. Terpercaya dan user friendly untuk semua pengguna Indonesia.
    Rekomendasi banget untuk kalian yang suka game online.

    warriors88

    2 Nov 25 at 10:00 am

  49. Irish online pharmacy reviews

    Edmundexpon

    2 Nov 25 at 10:00 am

  50. купить проведенный диплом одно [url=https://www.frei-diplom6.ru]купить проведенный диплом одно[/url] .

    Diplomi_sfOl

    2 Nov 25 at 10:01 am

Leave a Reply