Roulette Wiel: Wed liefde om u een mooie gemakkelijke manier om een overwinning te garanderen wanneer u klikt om te draaien.
  • 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.
  • 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 7,580 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 , , ,

    7,580 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. Одним из ключевых аспектов является определение стадии зависимости, что можно подробнее изучить на официальном портале Министерства здравоохранения РФ. Там представлена актуальная информация о современных стандартах диагностики и лечения.
      Ознакомиться с деталями – https://narkologicheskaya-klinika-krasnodar0.ru/chastnaya-narkologicheskaya-klinika-v-krasnodare/

      ThomasIdeaf

      19 Jul 25 at 3:48 pm

    2. MediMexicoRx: tadalafil mexico pharmacy – MediMexicoRx

      LewisSoump

      19 Jul 25 at 3:48 pm

    3. купить диплом с занесением реестра [url=http://arus-diplom35.ru/]купить диплом с занесением реестра[/url] .

      Diplomi_hkOn

      19 Jul 25 at 3:50 pm

    4. вывод из запоя
      vivod-iz-zapoya-kaluga005.ru
      лечение запоя калуга

    5. Because the admin of this website is working, no uncertainty very shortly it will be
      well-known, due to its quality contents.

      quickratey.com

      19 Jul 25 at 3:55 pm

    6. онлайн оценка дорогих часов [url=https://ocenka-chasov-onlajn9.ru/]ocenka-chasov-onlajn9.ru[/url] .

    7. https://expresscarerx.online/# health rx pharmacy

      RobertEmard

      19 Jul 25 at 3:59 pm

    8. лестницы на второй этаж на заказ [url=lestnicy-na-metallokarkase-4.ru]лестницы на второй этаж на заказ[/url] .

    9. После вашего звонка диспетчер фиксирует заявку и передаёт её свободному специалисту. Нарколог связывается для уточнения симптомов, времени начала запоя и наличия сопутствующих заболеваний, чтобы привезти нужные препараты.
      Исследовать вопрос подробнее – [url=https://kapelnica-ot-zapoya-voronezh.ru/]kapelnicza-ot-zapoya-na-domu voronezh[/url]

      Patricktip

      19 Jul 25 at 4:05 pm

    10. Excellent beat ! I wish to apprentice while you amend your web site,
      how could i subscribe for a blog site? The
      account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright
      clear idea

    11. Lesteretedy

      19 Jul 25 at 4:10 pm

    12. построить дом в области [url=http://www.stroitelstvo-doma-1.ru]построить дом в области[/url] .

    13. купить диплом занесенный в реестр [url=https://www.arus-diplom35.ru]купить диплом занесенный в реестр[/url] .

      Diplomi_edOn

      19 Jul 25 at 4:12 pm

    14. mostbet sport [url=https://mostbet4073.ru/]mostbet sport[/url]

      mostbet_bsot

      19 Jul 25 at 4:22 pm

    15. дом для проживания под ключ [url=https://www.stroitelstvo-doma-1.ru]дом для проживания под ключ[/url] .

    16. частный пансионат для пожилых людей
      pansionat-tula002.ru
      пансионат для лежачих пожилых

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

      Diplomi_bmpi

      19 Jul 25 at 4:31 pm

    18. строительство дома под ключ область [url=www.stroitelstvo-doma-1.ru/]строительство дома под ключ область[/url] .

    19. melbet mobile [url=melbet3004.com]melbet mobile[/url]

      melbet_cvMt

      19 Jul 25 at 4:32 pm

    20. Стандартная процедура включает внутривенное введение растворов, которые эффективно выводят токсины, восстанавливают электролитный баланс и устраняют обезвоживание. Дополнительно врач назначает медикаменты для защиты сердца, печени и нервной системы, а также, при необходимости, седативные препараты для стабилизации психического состояния.
      Получить больше информации – http://kapelnica-ot-zapoya-moskva00.ru/kapelnicza-ot-zapoya-czena-msk/

      JeremySIP

      19 Jul 25 at 4:36 pm

    21. Как подчёркивает заведующая отделением клинической психологии ФГБУН «НМИЦ психиатрии и наркологии» Минздрава России, наличие в команде специалистов с опытом работы в области зависимости — это основа качественной помощи.
      Углубиться в тему – https://narkologicheskaya-klinika-nizhnij-tagil11.ru/narkologicheskaya-klinika-telefon-v-nizhnem-tagile

      Keithgek

      19 Jul 25 at 4:36 pm

    22. cheapest online pharmacy india [url=http://indiamedshub.com/#]reputable indian online pharmacy[/url] world pharmacy india

      DavidRhinc

      19 Jul 25 at 4:38 pm

    23. Проблема зависимости от алкоголя, наркотиков и азартных игр остается одной из наиболее острых в современном обществе. Эти состояния оказывают значительное воздействие не только на здоровье самого человека, но и на его семью, друзей и общественные связи. Наркологическая клиника “Восстановление души” предлагает широкий спектр услуг для тех, кто борется с различными формами зависимости, такими как алкоголизм, наркомания и игромания. Наша цель — предоставить комплексный подход к лечению, что обеспечивает высокие показатели успешности среди наших пациентов.
      Исследовать вопрос подробнее – [url=https://kapelnica-ot-zapoya-irkutsk2.ru/]вызвать капельницу от запоя на дому иркутск[/url]

      GarlandVop

      19 Jul 25 at 4:40 pm

    24. купить диплом с проводкой одно [url=https://arus-diplom35.ru]купить диплом с проводкой одно[/url] .

      Diplomi_hsOn

      19 Jul 25 at 4:44 pm

    25. Awesome breakdown, Ryan! Scalping definitely requires the
      fastest execution and tightest spreads, and it’s great
      to see brokers like IG and IC Markets leading the pack in 2025.
      I’ve tried a few platforms, but the smart
      routing on Interactive Brokers sounds like a game-changer for quick trades.
      Thanks for the detailed review — can’t wait to test
      out some of these brokers on demo accounts!

    26. онлайн оценка часов по фото для скупки [url=https://ocenka-chasov-onlajn8.ru/]ocenka-chasov-onlajn8.ru[/url] .

    27. Острая алкогольная интоксикация — запой — может привести к серьёзным осложнениям: дегидратации, сбою сердечного ритма, ухудшению функций печени и почек. Клиника «ВоронежДоктор» предлагает инфузионную терапию на дому и в условиях стационара с полным соблюдением анонимности. Опытные специалисты проводят детоксикацию по индивидуальной программе, используя современные растворы и аппаратуру, что позволяет максимально быстро и безопасно вернуть пациента к нормальной жизни.
      Ознакомиться с деталями – https://kapelnica-ot-zapoya-voronezh2.ru/

      JerryRag

      19 Jul 25 at 4:47 pm

    28. дома под ключ москва области [url=https://stroitelstvo-doma-1.ru/]дома под ключ москва области[/url] .

    29. построить дом с отделкой под ключ цена [url=stroitelstvo-doma-1.ru]построить дом с отделкой под ключ цена[/url] .

    30. RichardPep

      19 Jul 25 at 5:02 pm

    31. Во-первых, мы фокусируемся на медицинской детоксикации, которая является первоочередной задачей при лечении зависимостей. Этот процесс позволяет удалить токсические вещества из организма и улучшить общее состояние пациента. Мы применяем современные методики, которые помогают минимизировать симптомы абстиненции и обеспечить комфортное пребывание в клинике.
      Выяснить больше – [url=https://kapelnica-ot-zapoya-irkutsk.ru/]вызвать капельницу от запоя[/url]

      Josephshoow

      19 Jul 25 at 5:04 pm

    32. вывод из запоя цена
      vivod-iz-zapoya-kaluga005.ru
      вывод из запоя круглосуточно калуга

    33. «СочиМед» предлагает комплексный подход: диагностика, детоксикация, терапия сопутствующих состояний, психологическая и социальная поддержка. В стационаре доступны:
      Подробнее можно узнать тут – [url=https://narkologicheskaya-klinika-sochi00.ru/]бесплатная наркологическая клиника сочи[/url]

      MichaelCrumn

      19 Jul 25 at 5:08 pm

    34. Hi there I am so happy I found your website, I really found you by error, while I was looking on Google for
      something else, Anyhow I am here now and would just like to say many thanks for a fantastic post and a
      all round entertaining blog (I also love the theme/design), I don’t have time to go through it all at the minute
      but I have saved it and also included your RSS feeds, so when I have time I will
      be back to read a lot more, Please do keep up the superb jo.

    35. В клинике применяются разнообразные психотерапевтические техники, позволяющие адаптировать лечение под индивидуальные особенности пациента.
      Получить больше информации – http://

      WilliamToort

      19 Jul 25 at 5:16 pm

    36. Психолог оценили 6567 раз

      Психолог

      19 Jul 25 at 5:19 pm

    37. строительство дома без ипотеки [url=https://www.stroitelstvo-doma-1.ru]строительство дома без ипотеки[/url] .

    38. Дополнительно выясняются аллергические реакции, приём других препаратов и предпочтения пациента по времени визита врача.
      Детальнее – [url=https://kapelnica-ot-zapoya-voronezh3.ru/]капельница от запоя[/url]

      RobertThons

      19 Jul 25 at 5:26 pm

    39. Whoa! This blog looks just like my old one! It’s on a completely different subject but it has pretty much the same layout and design. Superb choice of colors!

      tahitian中文

      19 Jul 25 at 5:27 pm

    40. можно ли купить аттестат за 11 [url=https://arus-diplom25.ru]https://arus-diplom25.ru[/url] .

      Diplomi_tpot

      19 Jul 25 at 5:31 pm

    41. I loved as much as you’ll receive carried out right here.
      The sketch is attractive, your authored material stylish.
      nonetheless, you command get got an edginess over that
      you wish be delivering the following. unwell unquestionably
      come more formerly again since exactly the same nearly very often inside case you shield this increase.

    42. Основной этап, направленный на очищение организма от продуктов распада алкоголя и нормализацию функций внутренних органов. Применяются современные препараты с антиоксидантным и гепатопротекторным эффектом.
      Подробнее можно узнать тут – http://lechenie-alkogolizma-krasnodar0.ru

      DonaldWrava

      19 Jul 25 at 5:33 pm

    43. DavidFoogs

      19 Jul 25 at 5:38 pm

    44. GerardobaR

      19 Jul 25 at 5:45 pm

    45. С психологом онлайн вы найдете выход из кризиса. Детский психолог онлайн поможет в адаптации к детсаду.
      ваш психолог онлайн

      Ernestpoive

      19 Jul 25 at 5:48 pm

    46. Наткнулся на полезную статью, думаю, вам тоже пригодится:

      Зацепил материал про detoxa.ru.

      Вот, делюсь ссылкой:

      [url=https://detoxa.ru]https://detoxa.ru[/url]

      Буду признателен за ваши отзывы.

      rusPoito

      19 Jul 25 at 5:50 pm

    47. купить аттестат за 11 класс в казахстане [url=https://www.arus-diplom25.ru]купить аттестат за 11 класс в казахстане[/url] .

      Diplomi_vdot

      19 Jul 25 at 5:51 pm

    48. mostbet indir android [url=http://island-hvar.info]mostbet indir android[/url] .

      mostbet apk_gmPi

      19 Jul 25 at 5:56 pm

    49. ExpressCareRx [url=https://expresscarerx.org/#]ExpressCareRx[/url] non prescription cialis online pharmacy

      DavidRhinc

      19 Jul 25 at 5:57 pm

    50. Системы автоматизированного дозирования обеспечивают точное введение медикаментов, что минимизирует риск побочных эффектов. Постоянный мониторинг жизненно важных показателей позволяет врачу корректировать терапию в режиме реального времени, гарантируя безопасность процедуры.
      Подробнее тут – [url=https://vyvod-iz-zapoya-vladimir0.ru/]вывод из запоя цена владимир[/url]

      TerryAcith

      19 Jul 25 at 5:58 pm

    Leave a Reply