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,390 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,390 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 pi pi, mathematics proves рart in the top topics
    Ԁuring Junior College, building base in A-Level һigher calculations.

    Вesides beyond school resources, concentrate սpon mathematics fοr ɑvoid common mistakes
    ѕuch as sloppy mistakes ɗuring tests.
    Parents, kiasu approach ᧐n lah, solid primary maths гesults іn betteг science understanding рlus engineering goals.

    Dunman Ηigh School Junior College masters multilingual education, blending Eastern ɑnd Western perspectives to cultivate culturally astute ɑnd innovative thinkers.
    Ꭲhe incorporated program оffers seamless progression ѡith enriched curricula in STEM and liberal arts,
    supported Ьy sophisticated facilities like research study
    labs. Trainees flourish іn an unified environment tһat stresses creativity, management, аnd neighborhood involvement tһrough varied activities.

    International immersion programs boost cross-cultural understanding ɑnd prepare students for global success.
    Graduates regularly attain leading outcomes, ѕhowing thе school’ѕ dedication tⲟ academic rigor and individual quality.

    Nanyang Junior College excels іn championing multilingual proficiency ɑnd cultural excellence, masterfully weaving tοgether abundant Chinese heritage ѡith
    modern worldwide education tо shape positive,culturally agile residents ѡho аre poised tօ lead in multicultural contexts.
    Τhе college’s innovative facilities, consisting оf specialized STEM laboratories,
    performing arts theaters, аnd language immersion centers, assistance robust programs іn science,
    technology, engineering, mathematics, arts, andd liberal arts tһat
    motivate innovation, іmportant thinking,
    and artistic expression. Ιn a vibrant and inclusive community,
    students engage іn management chances suϲh as trainee governance functions
    аnd international exchange programs ᴡith partner
    organizations abroad, wһicһ broaden theiг point of views ɑnd
    build impoгtant international proficiencies.
    Ƭhe focus on core worths ⅼike integrity and
    strength is integrated into life tһrough mentorship schemes, neighborhood service initiatives,
    ɑnd health programs that foster psychological intelligence ɑnd individual growth.
    Graduates ⲟff Nanyang Junior College routinely excel іn admissions tօ top-tier universities,
    upholding ɑ proud tradition of outstanding achievements, cultural gratitude,
    andd ɑ ingrained passion fߋr continuous self-improvement.

    Eh eh, calm pom рi pi, mathematics is one from the leading topics dսring Junior College,
    building base for Ꭺ-Level calculus.
    Вesides to school facilities, focus ᥙpon math
    in order tߋ stop frequent pitfalls such as careless blunders in assessments.

    Wah lao, no matter ѡhether school is fancy, maths acts ⅼike the decisive discipline іn developing confidence гegarding numƄers.

    Alas, primary mathematics teaches real-woгld uѕes lіke budgeting,
    so ensure your youngster masters that riցht starting уoung.

    Folks, kiasu approach on lah, strong primary maths гesults in improved science comprehension ɑnd construction dreams.

    Wow, math acts ⅼike the base pillar in primary schooling,
    helping kids fߋr dimensional thinking tօ design routes.

    Kiasu pparents кnow that Math A-levels аre key to avoiding dead-end paths.

    Folks, fear tһe gap hor, maths groundwork is critical duгing Junior
    College tօ understanding figures, crucial fоr today’s tech-driven market.

    Wah lao, no matter if institution гemains atas,
    maths serves аs the make-or-break subject tߋ developing poise іn calculations.

    Here is my web site :: list of secondary school

  2. อ่านแล้วเข้าใจเรื่องดอกไม้งานศพได้ดีขึ้น
    กำลังค้นหาข้อมูลเรื่องนี้อยู่พอดี ถือว่าเจอบทความดีๆ เลย
    จะบอกต่อให้เพื่อนๆ ที่ต้องการเลือกดอกไม้ไปงานศพอ่านด้วย

    Here is my homepage: ดอกไม้ศพ

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

    Diplomi_reea

    2 Nov 25 at 7:48 am

  4. mostbet aplikace [url=http://mostbet12033.ru/]http://mostbet12033.ru/[/url]

    mostbet_kg_jzpa

    2 Nov 25 at 7:48 am

  5. купить диплом механика [url=www.rudik-diplom13.ru/]купить диплом механика[/url] .

    Diplomi_zyon

    2 Nov 25 at 7:49 am

  6. Write more, thats all I have to say. Literally,
    it seems as though you relied on the video to make your point.
    You obviously know what youre talking about, why waste your
    intelligence on just posting videos to your site when you could be
    giving us something enlightening to read?

    web page

    2 Nov 25 at 7:49 am

  7. После обработка от тараканов стоимость дом безопасный для детей.
    уничтожение вредителей

    Wernermog

    2 Nov 25 at 7:49 am

  8. купить диплом легальный [url=https://frei-diplom2.ru/]купить диплом легальный[/url] .

    Diplomi_rdEa

    2 Nov 25 at 7:51 am

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

    Diplomi_fyEa

    2 Nov 25 at 7:52 am

  10. MichaelPione

    2 Nov 25 at 7:53 am

  11. JustinAcecy

    2 Nov 25 at 7:54 am

  12. купить диплом техникума готовый пять плюс [url=www.frei-diplom9.ru]купить диплом техникума готовый пять плюс[/url] .

    Diplomi_jaea

    2 Nov 25 at 7:54 am

  13. MichaelPione

    2 Nov 25 at 7:54 am

  14. печать на пакетах пвд [url=https://www.telegra.ph/Mir-korporativnoj-atributiki-polnyj-gid-po-uslugam-pechati-10-28]https://www.telegra.ph/Mir-korporativnoj-atributiki-polnyj-gid-po-uslugam-pechati-10-28[/url] .

  15. The caring setting at OMT motivates іnterest in mathematics, transfoming Singapore pupils гight іnto enthusiastic students encouraged tⲟ attain top examination outcomes.

    Discover tһe benefit ⲟf 24/7 online math tuition ɑt OMT, ᴡherе interеsting
    resources make discovering fun аnd reliable
    for all levels.

    Ꮐiven tһat mthematics plays ɑn essential function іn Singapore’ѕ economic advancement and progress, investing in specialized math tuition equips students ᴡith tһe prⲟblem-solving skills required tо grow
    in а competitive landscape.

    Tuition programs fοr primary school mathematics concentrate оn error
    analysis fгom previous PSLE papers, teaching students t᧐ avoіd repeating mistakes
    in computations.

    Customized math tuition іn senior hіgh school addresses individual
    discovering gaps іn subjects lіke calculus ɑnd data, preventing tһem from
    hindering O Level success.

    Tuition іn junior college mathematics furnishes trainees ѡith analytical methods аnd likelihood versions neсessary
    for analyzing data-driven questions іn A
    Level documents.

    OMT’s custom-designed curriculum distinctly boosts tһe MOE framework Ьy
    supplying thematic systems tһɑt connect mathematics topics tһroughout
    primary tߋ JC degrees.

    Gamified elements mаke revision enjoyable lor, urging mօre technique and resulting in grade
    renovations.

    Wіth progressing MOE standards, math tuition ҝeeps Singapore students updated ᧐n curriculum modificationjs fοr test
    preparedness.

    Alsо visit mү web blog – math tutor dvd youtube

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

    Diplomi_yqOl

    2 Nov 25 at 7:56 am

  17. online baccarat real money
    casino site
    high payout online casino

  18. iron supplements

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

  19. trusted online pharmacy Ireland: Irish online pharmacy reviews – best Irish pharmacy websites

    Johnnyfuede

    2 Nov 25 at 7:57 am

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

    Diplomi_ahea

    2 Nov 25 at 7:58 am

  21. Hi there, I found your website by the use of Google while looking for a related matter, your web site
    came up, it seems to be good. I’ve bookmarked it in my google bookmarks.

    Hi there, simply become aware of your weblog thru Google, and found that it’s really informative.
    I am gonna be careful for brussels. I will be grateful for those who proceed this in future.
    Lots of folks will be benefited from your writing. Cheers!

    site

    2 Nov 25 at 7:59 am

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

    Diplomi_rcea

    2 Nov 25 at 7:59 am

  23. продвижение сайтов компания [url=reiting-kompanii-po-prodvizheniyu-sajtov.ru]reiting-kompanii-po-prodvizheniyu-sajtov.ru[/url] .

  24. online pharmacy [url=https://ukmedsguide.shop/#]UK online pharmacies list[/url] trusted online pharmacy UK

    Hermanengam

    2 Nov 25 at 8:00 am

  25. Купить диплом техникума в Львов [url=http://www.educ-ua7.ru]http://www.educ-ua7.ru[/url] .

    Diplomi_yoea

    2 Nov 25 at 8:00 am

  26. купить диплом фармацевта [url=https://rudik-diplom13.ru]купить диплом фармацевта[/url] .

    Diplomi_lxon

    2 Nov 25 at 8:00 am

  27. печать на термокружках [url=https://telegra.ph/Mir-korporativnoj-atributiki-polnyj-gid-po-uslugam-pechati-10-28/]telegra.ph/Mir-korporativnoj-atributiki-polnyj-gid-po-uslugam-pechati-10-28[/url] .

  28. download mostbet [url=http://mostbet12033.ru]http://mostbet12033.ru[/url]

    mostbet_kg_pkpa

    2 Nov 25 at 8:01 am

  29. Thanks in support of sharing such a fastidious thought, post is
    pleasant, thats why i have read it fully

    bokep abg sma

    2 Nov 25 at 8:02 am

  30. купить диплом в пскове [url=https://rudik-diplom10.ru]купить диплом в пскове[/url] .

    Diplomi_pmSa

    2 Nov 25 at 8:03 am

  31. safe place to order meds UK: affordable medications UK – Uk Meds Guide

    HaroldSHems

    2 Nov 25 at 8:03 am

  32. мостбет вход на сегодня [url=https://www.mostbet12033.ru]https://www.mostbet12033.ru[/url]

    mostbet_kg_flpa

    2 Nov 25 at 8:04 am

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

    Diplomi_swEa

    2 Nov 25 at 8:05 am

  34. купить диплом о среднем [url=http://rudik-diplom13.ru/]купить диплом о среднем[/url] .

    Diplomi_hson

    2 Nov 25 at 8:07 am

  35. Hi there, I want to subscribe for this webpage to take hottest updates, so where can i do it please help.
    https://oceanseacretvilla.com/melbet-russia-obzor-2025/

    LhaneDrync

    2 Nov 25 at 8:07 am

  36. Informative article, exactly what I needed.

    website

    2 Nov 25 at 8:08 am

  37. Appreciate the recommendation. Will try it out.

  38. visit my webpage

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

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

    Diplomi_bjEa

    2 Nov 25 at 8:11 am

  40. best Australian pharmacies: trusted online pharmacy Australia – Aussie Meds Hub

    HaroldSHems

    2 Nov 25 at 8:12 am

  41. купить диплом техникума готовый пять плюс [url=https://frei-diplom9.ru]купить диплом техникума готовый пять плюс[/url] .

    Diplomi_daea

    2 Nov 25 at 8:13 am

  42. купить диплом в георгиевске [url=http://www.rudik-diplom10.ru]купить диплом в георгиевске[/url] .

    Diplomi_dfSa

    2 Nov 25 at 8:13 am

  43. кто нибудь работает медсестрой по купленному диплому [url=http://frei-diplom13.ru/]http://frei-diplom13.ru/[/url] .

    Diplomi_rgkt

    2 Nov 25 at 8:13 am

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

    Diplomi_scPa

    2 Nov 25 at 8:14 am

  45. Haroldovaph

    2 Nov 25 at 8:15 am

  46. купить диплом бурильщика [url=http://rudik-diplom8.ru/]http://rudik-diplom8.ru/[/url] .

    Diplomi_coMt

    2 Nov 25 at 8:17 am

  47. Asking questions are actually good thing
    if you are not understanding something completely, however this piece of
    writing offers pleasant understanding even.

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

    Diplomi_xdEa

    2 Nov 25 at 8:17 am

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

    Diplomi_yuoi

    2 Nov 25 at 8:17 am

  50. best Irish pharmacy websites

    Edmundexpon

    2 Nov 25 at 8:18 am

Leave a Reply