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 89,439 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 , , ,

89,439 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. купить диплом в вольске [url=http://www.rudik-diplom5.ru]http://www.rudik-diplom5.ru[/url] .

    Diplomi_dpma

    14 Oct 25 at 11:32 am

  2. тканевый натяжной потолок самара [url=natyazhnye-potolki-samara-1.ru]natyazhnye-potolki-samara-1.ru[/url] .

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

    Diplomi_utMi

    14 Oct 25 at 11:33 am

  4. Right now it sounds like Expression Engine is the top blogging platform available right now.
    (from what I’ve read) Is that what you are
    using on your blog?

    harga toto

    14 Oct 25 at 11:34 am

  5. купить свидетельство о браке [url=https://www.rudik-diplom3.ru]купить свидетельство о браке[/url] .

    Diplomi_ckei

    14 Oct 25 at 11:35 am

  6. Hello it’s me, I am also visiting this website regularly,
    this web page is genuinely pleasant and the users are in fact sharing good thoughts.

  7. тканевые электрожалюзи [url=http://www.zhalyuzi-s-elektroprivodom77.ru]http://www.zhalyuzi-s-elektroprivodom77.ru[/url] .

  8. аренда мини экскаватора с гидромолотом [url=arenda-mini-ekskavatora-v-moskve-2.ru]аренда мини экскаватора с гидромолотом[/url] .

  9. где купить диплом техникума одних [url=https://www.frei-diplom11.ru]где купить диплом техникума одних[/url] .

    Diplomi_zysa

    14 Oct 25 at 11:36 am

  10. электрокарниз [url=http://elektrokarnizy797.ru]электрокарниз[/url] .

  11. купить диплом в назрани [url=https://rudik-diplom5.ru]купить диплом в назрани[/url] .

    Diplomi_cema

    14 Oct 25 at 11:38 am

  12. потолочников натяжные потолки [url=http://natyazhnye-potolki-samara-1.ru]http://natyazhnye-potolki-samara-1.ru[/url] .

  13. Williamcoemy

    14 Oct 25 at 11:39 am

  14. Thanks for sharing your thoughts on casino med snabba uttag.
    Regards

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

    Diplomi_trOr

    14 Oct 25 at 11:39 am

  16. The trial of Bryan Kohberger – the man who brutally murdered four University of Idaho students inside their off-campus home – ended in July before it ever truly began when he accepted a plea deal that saw him sentenced to four consecutive life terms in prison without the possibility of an appeal or parole.

    Kohberger sat impassively throughout the hearing as the loved ones of each of the four students whose lives he so callously ended repeatedly asked him the same question: Why?
    [url=http://trip-skan45.cc]трипскан вход[/url]
    And when he was finally given the opportunity to answer their questions, he said, “I respectfully decline.”

    That decision further fueled the mystery around his motive for murdering Xana Kernodle, Madison Mogen, Ethan Chapin and Kaylee Goncalves.

    “There’s no reason for these crimes that could approach anything resembling rationality,” Idaho District Judge Steven Hippler said during Kohberger’s sentencing. “The more we try to extract a reason, the more power and control we give to him.”

    But, he added, investigators and researchers may wish to study his actions – if only to learn how to prevent similar crimes from occurring in the future.
    http://trip-skan45.cc
    trip scan
    Indeed, academics and former FBI profilers told CNN the challenge of unravelling the criminal mind of a man like Bryan Kohberger is enticing. And while his trial may be over, in many ways, the story of what can be learned from his crimes may have only just begun.

    “We want to squeeze any silver lining that we can out of these tragedies,” said Molly Amman, a retired profiler who spent years leading the FBI’s Behavioral Threat Assessment Center.

    “The silver lining is anything we can use to prevent another crime. It starts with learning absolutely, positively everything about the person and the crime that we possibly can.”

    CNN
    Only Kohberger knows
    Even seasoned police officers who arrived at 1122 King Road on November 13, 2022, struggled to process the brutality of the crime scene.

    All four victims had been ruthlessly stabbed to death before the attacker vanished through the kitchen’s sliding glass door and into the night.

    “The female lying on the left half of the bed … was unrecognizable,” one officer would later write of the attack that killed Kaylee Goncalves. “I was unable to comprehend exactly what I was looking at while trying to discern the nature of the injuries.”

    Initial interviews with the two surviving housemates gave investigators a loose timeline and a general description of the killer – an athletic, White male who wore a mask that covered most of his face – but little else.

    Police later found a Ka-Bar knife sheath next to Madison’s body that would prove to be critical in capturing her killer.

    One of the surviving housemates told police about a month before the attacks, Kaylee saw “a dark figure staring at her from the tree line when she took her dog Murphy out to pee.”

    “There has been lighthearted talk and jokes made about a stalker in the past,” the officer noted. “All the girls were slightly nervous about it being a fact, though.”

    But after years of investigating the murders, detectives told CNN they were never able to establish a connection between Kohberger and any of the victims, or a motive.

    Kohberger is far from the first killer to deny families and survivors the catharsis that comes with confessing, in detail, to his crimes. But that, former FBI profilers tell CNN, is part of what makes the prospect of studying him infuriating and intriguing.

    Wesleyzep

    14 Oct 25 at 11:39 am

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

    Diplomi_joOl

    14 Oct 25 at 11:39 am

  18. Добро пожаловать в Vodka Casino, где каждый найдет что-то для себя!
    Здесь вас ждут великолепные предложения, захватывающие слоты и
    огромные шансы на победу.

    Водка бонусы на пополнение.

    Почему стоит выбрать Vodka Casino?

    Простой в использовании сайт для всех игроков.

    Возможности для крупных побед с каждой ставкой.

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

    Множество способов оплаты.

    Начните играть в Vodka Casino и выиграйте
    прямо сейчас!

    casino vodka

    14 Oct 25 at 11:39 am

  19. Купить диплом колледжа в Днепр [url=http://educ-ua7.ru]http://educ-ua7.ru[/url] .

    Diplomi_zzea

    14 Oct 25 at 11:40 am

  20. электрокарнизы [url=https://karniz-shtor-elektroprivodom.ru/]электрокарнизы[/url] .

  21. LearnWithConfidence – Very approachable lessons, perfect for beginners wanting to improve efficiently.

    Autumn Edick

    14 Oct 25 at 11:42 am

  22. купить диплом зубного техника [url=http://www.rudik-diplom11.ru]купить диплом зубного техника[/url] .

    Diplomi_mzMi

    14 Oct 25 at 11:43 am

  23. This piece of writing will help the internet viewers for
    setting up new web site or even a weblog from start to end.

    dewascatter

    14 Oct 25 at 11:45 am

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

    Diplomi_deOr

    14 Oct 25 at 11:46 am

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

    Diplomi_emer

    14 Oct 25 at 11:46 am

  26. Hi there I am so glad I found your webpage, I really found you by error,
    while I was researching on Google for something else, Regardless I am here now and would just like to say kudos for a fantastic post and a all round interesting blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have
    bookmarked it and also added in your RSS
    feeds, so when I have time I will be back to read more, Please do keep up the superb b.

    Dornatrixel

    14 Oct 25 at 11:46 am

  27. купить диплом техникума спб в южно сахалинске [url=https://frei-diplom10.ru]купить диплом техникума спб в южно сахалинске[/url] .

    Diplomi_foEa

    14 Oct 25 at 11:47 am

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

    Diplomi_hmOl

    14 Oct 25 at 11:47 am

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

    Diplomi_ieei

    14 Oct 25 at 11:47 am

  30. перепланировка нежилого помещения в нежилом здании [url=https://www.pereplanirovka-nezhilogo-pomeshcheniya8.ru]https://www.pereplanirovka-nezhilogo-pomeshcheniya8.ru[/url] .

  31. Great work! This is the kind of information that
    are supposed to be shared around the internet. Disgrace on Google for not positioning this
    submit higher! Come on over and consult with my
    website . Thanks =)

    SODO

    14 Oct 25 at 11:48 am

  32. потолки самары [url=www.stretch-ceilings-samara.ru/]www.stretch-ceilings-samara.ru/[/url] .

  33. переустройство нежилого помещения [url=http://www.pereplanirovka-nezhilogo-pomeshcheniya9.ru]http://www.pereplanirovka-nezhilogo-pomeshcheniya9.ru[/url] .

  34. потолочкин потолки [url=http://stretch-ceilings-samara-1.ru/]http://stretch-ceilings-samara-1.ru/[/url] .

  35. купить диплом в уфе [url=https://rudik-diplom1.ru]купить диплом в уфе[/url] .

    Diplomi_uqer

    14 Oct 25 at 11:51 am

  36. легально купить диплом о [url=frei-diplom6.ru]легально купить диплом о[/url] .

    Diplomi_lxOl

    14 Oct 25 at 11:52 am

  37. электрические рулонные шторы на окна [url=https://rulonnaya-shtora-s-elektroprivodom.ru/]электрические рулонные шторы на окна[/url] .

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

    Diplomi_bgOl

    14 Oct 25 at 11:53 am

  39. электрокарнизы в москве [url=http://elektrokarnizy797.ru]электрокарнизы в москве[/url] .

  40. узаконивание перепланировки нежилого помещения [url=http://www.pereplanirovka-nezhilogo-pomeshcheniya8.ru]http://www.pereplanirovka-nezhilogo-pomeshcheniya8.ru[/url] .

  41. горизонтальные жалюзи с электроприводом [url=http://zhalyuzi-s-elektroprivodom77.ru]горизонтальные жалюзи с электроприводом[/url] .

  42. Good response in return of this query with solid arguments and describing the whole thing about that.

    ev99.com

    14 Oct 25 at 11:54 am

  43. купить диплом в назрани [url=www.rudik-diplom3.ru/]купить диплом в назрани[/url] .

    Diplomi_ucei

    14 Oct 25 at 11:55 am

  44. Just extended my $MTAUR vesting for that 10% bonus—smart play. The audited contracts and cliff mechanisms build trust. Can’t wait to battle crypto monsters in full release.
    mtaur token

    WilliamPargy

    14 Oct 25 at 11:55 am

  45. купить диплом в нижнекамске [url=https://rudik-diplom4.ru/]https://rudik-diplom4.ru/[/url] .

    Diplomi_lgOr

    14 Oct 25 at 11:56 am

  46. потолочкин натяжные потолки отзывы [url=https://stretch-ceilings-samara-1.ru/]потолочкин натяжные потолки отзывы[/url] .

  47. натяжные потолки самара [url=https://www.natyazhnye-potolki-samara-2.ru]натяжные потолки самара[/url] .

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

    Diplomi_jfMt

    14 Oct 25 at 11:57 am

  49. отзывы потолочкин натяжные потолки [url=https://stretch-ceilings-samara.ru/]stretch-ceilings-samara.ru[/url] .

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

    Diplomi_npOl

    14 Oct 25 at 12:00 pm

Leave a Reply