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 1,772 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 , , ,

    1,772 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. голодание на воде Голодание для улучшения зрения: Поддержка здоровья глаз

      BrianBaw

      19 Jul 25 at 10:05 am

    2. Lesteretedy

      19 Jul 25 at 10:06 am

    3. finasteride mexico pharmacy [url=https://medimexicorx.shop/#]MediMexicoRx[/url] mexican pharmacy for americans

      DavidRhinc

      19 Jul 25 at 10:07 am

    4. RichardPep

      19 Jul 25 at 10:09 am

    5. Первое, на что стоит обратить внимание — это профессиональный уровень сотрудников. Без квалифицированных наркологов, клинических психологов и психиатров реабилитационный процесс становится формальным и неэффективным.
      Подробнее тут – [url=https://narkologicheskaya-klinika-nizhnij-tagil11.ru/]наркологическая клиника цены в нижнем тагиле[/url]

      Keithgek

      19 Jul 25 at 10:16 am

    6. купить аттестат за 11 классов в челябинской области [url=www.arus-diplom21.ru]www.arus-diplom21.ru[/url] .

    7. https://indiamedshub.shop/# india online pharmacy

      Vernonhon

      19 Jul 25 at 10:19 am

    8. купить проведенный диплом в красноярске [url=www.arus-diplom31.ru]www.arus-diplom31.ru[/url] .

      Diplomi_zfpl

      19 Jul 25 at 10:19 am

    9. VernonMup

      19 Jul 25 at 10:22 am

    10. pharmacy support viagra: the peoples pharmacy – cialis in dubai pharmacy

      BobbyAcany

      19 Jul 25 at 10:26 am

    11. Michaelbasse

      19 Jul 25 at 10:31 am

    12. купить диплом пту в реестре [url=http://arus-diplom31.ru/]купить диплом пту в реестре[/url] .

      Diplomi_gqpl

      19 Jul 25 at 10:38 am

    13. купить аттестаты за 11 класс 2022 [url=http://arus-diplom21.ru/]http://arus-diplom21.ru/[/url] .

    14. Этап лечения
      Изучить вопрос глубже – [url=https://lechenie-alkogolizma-krasnodar00.ru/]лечение алкоголизма[/url]

      Virgilcic

      19 Jul 25 at 10:46 am

    15. Специалист выясняет, как долго продолжается запой, какие симптомы наблюдаются, а также наличие сопутствующих заболеваний. Эти данные позволяют сформировать индивидуальный план лечения и выбрать оптимальные методы детоксикации.
      Ознакомиться с деталями – https://vyvod-iz-zapoya-vladimir0.ru

      TerryAcith

      19 Jul 25 at 10:54 am

    16. В Люберцах решение есть — наркологическая клиника. Здесь помогают людям выйти из запоя без страха и осуждения. Всё анонимно, грамотно и с заботой о каждом пациенте.
      Получить дополнительные сведения – [url=https://kapelnica-ot-zapoya-lyubercy11.ru/]врач нарколог на дом город люберцы[/url]

      Davidaerop

      19 Jul 25 at 10:57 am

    17. VernonMup

      19 Jul 25 at 11:02 am

    18. купить диплом с регистрацией [url=http://arus-diplom31.ru]купить диплом с регистрацией[/url] .

      Diplomi_vmpl

      19 Jul 25 at 11:04 am

    19. mostbet uz registratsiya [url=http://mostbet4072.ru]http://mostbet4072.ru[/url]

      mostbet_wnot

      19 Jul 25 at 11:06 am

    20. вывод из запоя круглосуточно
      vivod-iz-zapoya-kaluga004.ru
      экстренный вывод из запоя калуга

      vivodkalugaNeT

      19 Jul 25 at 11:12 am

    21. Врачи клиники «ЗдравЦентр» рекомендуют не откладывать вызов нарколога, чтобы избежать серьезных последствий, таких как судорожные припадки, инсульт или алкогольный психоз.
      Подробнее – http://kapelnica-ot-zapoya-moskva00.ru

      JeremySIP

      19 Jul 25 at 11:13 am

    22. mostbet app [url=https://www.island-hvar.info]mostbet app[/url] .

      mostbet apk_qwPi

      19 Jul 25 at 11:14 am

    23. подобрать подшипник по размерам онлайн Завод изготовитель подшипников Покупка подшипников напрямую с завода – это гарантия качества и лучшей цены.

      Davidpaics

      19 Jul 25 at 11:21 am

    24. пансионаты для инвалидов в туле
      pansionat-tula001.ru
      пансионат для пожилых

    25. indianpharmacy com [url=https://indiamedshub.shop/#]world pharmacy india[/url] IndiaMedsHub

      DavidRhinc

      19 Jul 25 at 11:25 am

    26. RichardPep

      19 Jul 25 at 11:31 am

    27. Every weekend i used to pay a quick visit this web page,
      as i want enjoyment, since this this website conations really pleasant funny
      data too.

      Agrandarlo

      19 Jul 25 at 11:38 am

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

      Diplomi_mdpi

      19 Jul 25 at 11:40 am

    29. Лечение в наркологической клинике в Краснодаре строится на комплексном подходе, включающем медикаментозную терапию, психотерапевтическую помощь и социальную реабилитацию. Медикаментозное лечение направлено на детоксикацию организма и снижение симптомов абстиненции, что позволяет значительно улучшить состояние пациента в первые дни терапии. Современные препараты, применяемые в лечении зависимости, сертифицированы и соответствуют международным стандартам, что подтверждается на сайте Всемирной организации здравоохранения.
      Детальнее – http://narkologicheskaya-klinika-krasnodar0.ru/

      ThomasIdeaf

      19 Jul 25 at 11:40 am

    30. Миссия клиники “Обновление” заключается в предоставлении качественной и всесторонней помощи людям, страдающим от различных форм зависимости. Мы понимаем, что успешное лечение невозможно без индивидуального подхода, поэтому каждый пациент проходит детальную диагностику, после которой разрабатывается персонализированный план терапии. В процессе работы мы акцентируем внимание на следующих аспектах:
      Подробнее тут – http://kapelnica-ot-zapoya-irkutsk.ru/kapelnica-ot-zapoya-anonimno-v-irkutske/

      Josephshoow

      19 Jul 25 at 11:41 am

    31. mostbet aviator demo [url=https://mostbet4072.ru]mostbet aviator demo[/url]

      mostbet_qpot

      19 Jul 25 at 11:42 am

    32. baixar mostbet [url=https://www.mostbet-download-app-apk.com]baixar mostbet[/url] .

      mostbet apk_fbPi

      19 Jul 25 at 11:45 am

    33. изготовление лестниц в частный дом [url=www.lestnicy-na-metallokarkase-2.ru]www.lestnicy-na-metallokarkase-2.ru[/url] .

    34. top 10 online pharmacy in india: IndiaMedsHub – IndiaMedsHub

      BobbyAcany

      19 Jul 25 at 11:52 am

    35. Самостоятельно выйти из запоя — почти невозможно. В Люберцах врачи клиники проводят медикаментозный вывод из запоя с круглосуточным выездом. Доверяйте профессионалам.
      Выяснить больше – [url=https://kapelnica-ot-zapoya-lyubercy13.ru/]капельница от запоя на дому люберцы[/url]

      JerryRoado

      19 Jul 25 at 11:54 am

    36. лестницы на заказ недорого [url=https://www.lestnicy-na-metallokarkase-3.ru]https://www.lestnicy-na-metallokarkase-3.ru[/url] .

    37. oakdell pharmacy sunday store hours: ExpressCareRx – ExpressCareRx

      LewisSoump

      19 Jul 25 at 12:02 pm

    38. Lesteretedy

      19 Jul 25 at 12:03 pm

    39. https://expresscarerx.org/# cheap generic viagra online pharmacy

      RobertEmard

      19 Jul 25 at 12:08 pm

    40. «НаркоМед» основана группой узкопрофильных специалистов, чей опыт насчитывает более 15 лет в лечении зависимости. Клиника работает круглосуточно — вы можете рассчитывать на оперативное реагирование в любой час дня и ночи. Анонимность пациентов сохраняется на уровне медицинской тайны: персональные данные и диагноз не разглашаются.
      Узнать больше – [url=https://narkologicheskaya-klinika-ekaterinburg0.ru/]narkologicheskaya-klinika-ekaterinburg0.ru/[/url]

      RaymondHal

      19 Jul 25 at 12:08 pm

    41. Цена капельницы от запоя в Иркутске зависит от ряда факторов, таких как выбор метода лечения (на дому или в стационаре), продолжительность лечения и степень тяжести состояния пациента. Для уточнения стоимости и записи на консультацию вы можете обратиться к нашим менеджерам, которые подробно расскажут о стоимости услуг и ответят на все ваши вопросы.
      Получить больше информации – https://kapelnica-ot-zapoya-irkutsk3.ru/kapelnica-ot-zapoya-v-kruglosutochno-v-irkutske

      PatrickCrymn

      19 Jul 25 at 12:09 pm

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

      DonaldWrava

      19 Jul 25 at 12:13 pm

    43. Купить подшипники от производителя Выбор подшипника по каталогу производителя Выбор подшипника по каталогу производителя – это гарантия соответствия техническим требованиям и оптимального решения для конкретных задач.

      BrendonMaync

      19 Jul 25 at 12:19 pm

    44. Vernonhon

      19 Jul 25 at 12:20 pm

    45. Приобретение документа о высшем образовании через проверенную и надежную компанию дарит множество плюсов для покупателя. Приобрести диплом о высшем образовании: [url=http://frayala.switch-maker.net/read-blog/22996_kupit-diplom-institut.html]frayala.switch-maker.net/read-blog/22996_kupit-diplom-institut.html[/url]

      Sazrewu

      19 Jul 25 at 12:22 pm

    46. экстренный вывод из запоя
      vivod-iz-zapoya-kaluga004.ru
      вывод из запоя цена

      vivodkalugaNeT

      19 Jul 25 at 12:24 pm

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

      MichaelBrees

      19 Jul 25 at 12:25 pm

    48. голодание Голодание для улучшения волос: Укрепление и рост

      BrianBaw

      19 Jul 25 at 12:26 pm

    49. 1win գրանցում [url=www.1win3072.ru]www.1win3072.ru[/url]

      1win_zlkr

      19 Jul 25 at 12:29 pm

    50. indian pharmacy online: IndiaMedsHub – india pharmacy mail order

      BobbyAcany

      19 Jul 25 at 12:30 pm

    Leave a Reply