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 99,727 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 , , ,

99,727 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://frei-diplom4.ru/]http://frei-diplom4.ru/[/url] .

    Diplomi_adOl

    19 Oct 25 at 6:03 am

  2. согласование [url=www.soglasovanie-pereplanirovki-kvartiry4.ru/]согласование[/url] .

  3. Hi there would you mind letting me know which hosting company you’re
    utilizing? I’ve loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot quicker then most.
    Can you recommend a good web hosting provider at a reasonable price?
    Thanks, I appreciate it!

    Paito HK Lotto

    19 Oct 25 at 6:04 am

  4. нужен проект перепланировки квартиры [url=proekt-pereplanirovki-kvartiry17.ru]нужен проект перепланировки квартиры[/url] .

  5. Hey there! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up
    losing several weeks of hard work due to no back up. Do you have any solutions
    to prevent hackers?

    NH 88

    19 Oct 25 at 6:05 am

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

    Diplomi_qfkt

    19 Oct 25 at 6:05 am

  7. JamesDaync

    19 Oct 25 at 6:05 am

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

    Diplomi_nhOr

    19 Oct 25 at 6:06 am

  9. купить диплом энергетика [url=http://www.rudik-diplom10.ru]купить диплом энергетика[/url] .

    Diplomi_aiSa

    19 Oct 25 at 6:07 am

  10. Tourists fined and banned from Venice for swimming in canal
    [url=https://tripscan44.cc]trip scan[/url]
    A couple from the United Kingdom had to cut their vacation in Venice short after being caught swimming in the Grand Canal.

    The 35-year-old British man and his 25-year-old Romanian girlfriend were forced to return to their home in the UK on Thursday, the same day they arrived in the city, after gondoliers reported them to local police for taking a dip in the canal.

    The pair were fined €450 ($529) each and expelled from Venice for 48 hours, marking the 1,136th such sanction to be handed down to badly behaved tourists in the city so far this year, according to the Venice City Police.

    The unnamed couple took the plunge near the Accademia bridge near St. Mark’s Square and gondoliers at the Rio San Vidal kiosk immediately called authorities, who removed them from the water.

    “I thank the gondoliers for their cooperation and timely reporting,” said Venice Security Councillor Elisabetta Pesce in a statement published by city authorities on Friday.
    https://tripscan44.cc
    tripscan
    “Venice must be defended from those who disrespect it: protecting the city means ensuring decorum for residents and visitors who experience it with civility.”

    Swimming in the Venice canals is prohibited for a variety of reasons, including the intense boat traffic and the cleanliness — or lack thereof — of the water, according to the city’s tourism ministry.

    Of the 1,136 orders of expulsion from the city so far this year, about 10 were for swimming.

    Related article
    Tourists take photographs on the Rialto Bridge in Venice, Italy, on Saturday, April 8, 2023. Italy’s upcoming budget outlook will probably incorporate a higher growth forecast for 2023 followed by a worsened outlook for subsequent years, according to people familiar with the matter. Photographer: Andrea Merola/Bloomberg via Getty Images
    Rising waters and overtourism are killing Venice. Now the fight is on to save its soul

    “Since the beginning of the year, we have issued a total of 1,136 orders of expulsion for incidents of degradation and uncivilized behavior,” Venice local police deputy commander Gianni Franzoi said in a statement shared with CNN.

    Poor visitor behavior is one of the worst byproducts of overtourism, Franzoi said, and incidents are on the rise.

    In July 2024, an Australian man was fined and expelled for diving off the Rialto Bridge after his friends posted about it on social media.

    The year before, two French tourists were fined and expelled for skinny dipping in the canal under the moonlight. In August 2022, a German man was fined and expelled for surfing in the canal.

    Related article
    Aerial view of the plagued ghost island of Poveglia in the Venetian lagoon
    ‘Haunted’ Venice island to become a locals-only haven where tourists are banned

    Venice’s authorities have been trying to balance the need for visitor income with residents’ demands for a city that works for them.

    Day trippers now pay a €10 entrance fee on summer weekends and during busy periods throughout the year.

    The city has also banned tour groups of more than 25 people, loudspeakers and megaphones, and even standing on narrow streets to listen to tour guides.

    “It was necessary to establish a system of penalties that would effectively deter potential violations,” Pesce said when the ordinance was passed in February.

    “Our goal remains to combat all forms of irregularities related to overtourism in the historic lagoon city center,” she added.

    “The new rules for groups accompanied by guides encourage a more sustainable form of tourism, while also ensuring greater protection and safety in the city and better balancing the needs of Venice residents and visitors.”

    Donnellbut

    19 Oct 25 at 6:07 am

  11. купить диплом техникума [url=https://www.educ-ua7.ru]https://www.educ-ua7.ru[/url] .

    Diplomi_gyea

    19 Oct 25 at 6:07 am

  12. https://potenzvital.shop/# cialis generika

    MickeySum

    19 Oct 25 at 6:07 am

  13. Hmm is anyone else having problems with the pictures on this blog loading?
    I’m trying to find out if its a problem on my end
    or if it’s the blog. Any feedback would be greatly appreciated.

  14. Adoro o brilho de BetorSpin Casino, oferece uma aventura de cassino que orbita como um cometa reluzente. A selecao de titulos do cassino e um buraco negro de diversao, com jogos de cassino perfeitos pra criptomoedas. O atendimento ao cliente do cassino e uma estrela-guia, garantindo suporte de cassino direto e sem buracos negros. Os saques no cassino sao velozes como uma viagem interestelar, as vezes as ofertas do cassino podiam ser mais generosas. No fim das contas, BetorSpin Casino garante uma diversao de cassino que e uma supernova para os apaixonados por slots modernos de cassino! De bonus a navegacao do cassino e facil como uma orbita lunar, adiciona um toque de brilho estelar ao cassino.
    bГіnus betorspin|

    glimmerfizzytoad7zef

    19 Oct 25 at 6:08 am

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

    Diplomi_eqPa

    19 Oct 25 at 6:10 am

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

    Diplomi_uiei

    19 Oct 25 at 6:11 am

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

    Diplomi_nwOl

    19 Oct 25 at 6:12 am

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

    Diplomi_hoOl

    19 Oct 25 at 6:15 am

  19. Kaizenaire.ϲom stands аⲣart ᴡith curated shopping
    promotions fоr Singapore customers.

    Promotions illuminate Singapore’ѕ shopping paradise, wherе locals chase handle іnterest and
    accuracy.

    Hosting film marathons іn your home entertains cinephile Singaporeans,
    ɑnd кeep iin mind tο remain updated οn Singapore’ѕ newеst promotions ɑnd shopping deals.

    CapitaLand Investment develops аnd handles properties, treasured
    Ьy Singaporeans for tһeir legendary malls аnd residential spaces.

    Watsons offers health andd wellness аnd appeal products
    leh, enjoyed Ьy Singaporeans for their lɑrge option ᧐f skin care and wellness tһings one.

    Tee Yih Jia ices up spring roll wrappers аnd dark ѕum, favored for top
    quality frozen products іn supermarkets.

    Aunties understand lah, Kaizenaire.ϲom hɑs the moѕt սp tо
    date deals leh.

    my blog post :: Personal Loans

    Personal Loans

    19 Oct 25 at 6:15 am

  20. купить диплом во всеволожске [url=rudik-diplom5.ru]rudik-diplom5.ru[/url] .

    Diplomi_gema

    19 Oct 25 at 6:15 am

  21. где согласовать перепланировку квартиры [url=www.soglasovanie-pereplanirovki-kvartiry4.ru]www.soglasovanie-pereplanirovki-kvartiry4.ru[/url] .

  22. купить дипломы о высшем цены [url=https://www.rudik-diplom3.ru]купить дипломы о высшем цены[/url] .

    Diplomi_ykei

    19 Oct 25 at 6:17 am

  23. купить диплом в пензе [url=rudik-diplom10.ru]rudik-diplom10.ru[/url] .

    Diplomi_btSa

    19 Oct 25 at 6:17 am

  24. https://stream2watch.ink
    Great site wow

    stream2watch

    19 Oct 25 at 6:17 am

  25. проект на перепланировку квартиры цена [url=http://www.proekt-pereplanirovki-kvartiry17.ru]http://www.proekt-pereplanirovki-kvartiry17.ru[/url] .

  26. Цветочные венки — тренд, который возвращает естественность образу. «Флорион» предлагает варианты для свадьбы, фотосессии и праздников: живые и искусственные, в пастели и насыщенных палитрах, с точной посадкой и комфортной посадкой на голове. Консультация флориста поможет подобрать форму под прическу и овал лица. Исследуйте коллекцию на https://www.florion.ru/catalog/venok-iz-cvetov — удобные фильтры, фото и цены сделают выбор простым, доставка по Москве — вовремя.

    caziwalbat

    19 Oct 25 at 6:21 am

  27. купить диплом в сызрани [url=https://www.rudik-diplom4.ru]купить диплом в сызрани[/url] .

    Diplomi_voOr

    19 Oct 25 at 6:21 am

  28. Just bought $MTAUR; seamless swap. Vesting extensions smart. Maze treasures tempting. minotaurus token

    WilliamPargy

    19 Oct 25 at 6:24 am

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

    Diplomi_qgkt

    19 Oct 25 at 6:24 am

  30. купить диплом для иностранцев [url=https://rudik-diplom8.ru/]купить диплом для иностранцев[/url] .

    Diplomi_tvMt

    19 Oct 25 at 6:25 am

  31. план перепланировки квартиры для согласования [url=http://proekt-pereplanirovki-kvartiry17.ru/]http://proekt-pereplanirovki-kvartiry17.ru/[/url] .

  32. Anthonycam

    19 Oct 25 at 6:27 am

  33. In the globe of forex trading, non-farm payroll (NFP) records
    serve as a substantial financial indicator that influences market movements.

    On the other hand, disappointing numbers can lead to volatility
    in the forex market, creating investors to reassess their strategies.
    Successful traders not just maintain an eye on NFP records yet likewise check how such releases
    communicate with other financial data points to shape their
    total market sight.

    market com

    19 Oct 25 at 6:28 am

  34. http://intimisante.com/# cialis sans ordonnance

    MickeySum

    19 Oct 25 at 6:28 am

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

    Diplomi_dmOr

    19 Oct 25 at 6:29 am

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

    Diplomi_pfSa

    19 Oct 25 at 6:35 am

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

    Diplomi_ojMt

    19 Oct 25 at 6:36 am

  38. acquistare Cialis online Italia: PilloleVerdi – pillole verdi

    RaymondNit

    19 Oct 25 at 6:37 am

  39. нужен проект перепланировки квартиры [url=https://proekt-pereplanirovki-kvartiry17.ru/]нужен проект перепланировки квартиры[/url] .

  40. Dived into Minotaurus presale; the 60B total supply with 60% allocated smartly. $MTAUR’s vesting prevents dumps. Loving the endless runner mechanics.
    mtaur coin

    WilliamPargy

    19 Oct 25 at 6:38 am

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

    Diplomi_crPa

    19 Oct 25 at 6:40 am

  42. купить диплом техникума в реестре цена [url=https://frei-diplom4.ru/]https://frei-diplom4.ru/[/url] .

    Diplomi_qdOl

    19 Oct 25 at 6:41 am

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

    Diplomi_hzOr

    19 Oct 25 at 6:42 am

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

    Diplomi_upkt

    19 Oct 25 at 6:42 am

  45. everydaytrendshop.bond – Fast loading site and content feels relevant and engaging always.

    Fletcher Tewani

    19 Oct 25 at 6:43 am

  46. connectforprogress.cfd – Site loads quickly and content feels relevant and fresh.

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

    Diplomi_qder

    19 Oct 25 at 6:44 am

  48. Thanks very interesting blog!

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

    Diplomi_nxon

    19 Oct 25 at 6:45 am

  50. согласование проекта перепланировки [url=http://soglasovanie-pereplanirovki-kvartiry4.ru/]согласование проекта перепланировки[/url] .

Leave a Reply