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 82,782 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 , , ,

    82,782 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=https://sportivnye-novosti-1.ru/]sportivnye-novosti-1.ru[/url] .

    2. При регистрации аккаунта клиент может рассчитывать на
      получение бонуса для новичков.

      вулкан

      8 Oct 25 at 3:35 pm

    3. generic ivermectin online pharmacy: generic ivermectin online pharmacy – order Stromectol discreet shipping USA

      Morrisluh

      8 Oct 25 at 3:36 pm

    4. Greate article. Keep writing such kind of information on your page.

      Im really impressed by your site.
      Hi there, You’ve done a fantastic job. I’ll certainly
      digg it and individually suggest to my friends. I’m
      sure they’ll be benefited from this web site.

    5. самые точные прогнозы на футбол [url=www.kompyuternye-prognozy-na-futbol24.ru]самые точные прогнозы на футбол[/url] .

    6. Hi to all, it’s in fact a good for me to visit this website, it contains priceless Information.

      text to image

      8 Oct 25 at 3:39 pm

    7. 1win casino скачать [url=http://1win5516.ru]1win casino скачать[/url]

      1win_ycOa

      8 Oct 25 at 3:40 pm

    8. I enjoy what you guys are usually up too. Such clever work and reporting!

      Keep up the great works guys I’ve included you guys to blogroll.

    9. точный прогнозы на футбол [url=http://www.kompyuternye-prognozy-na-futbol23.ru]http://www.kompyuternye-prognozy-na-futbol23.ru[/url] .

    10. Если самостоятельные попытки выйти из запоя не даются, в стационаре «Частного Медика 24» в Воронеже оказывают помощь профессионально: круглосуточное наблюдение, дозированные капельницы, поддержка сердечно-сосудистой системы, нормализация сна и работы внутренних органов.
      Получить дополнительные сведения – [url=https://vyvod-iz-zapoya-v-stacionare-voronezh23.ru/]стационар вывод из запоя в воронеже[/url]

      WilliamDef

      8 Oct 25 at 3:41 pm

    11. Thank you for the good writeup. It in fact was a amusement account it.

      Look advanced to far added agreeable from you! By the way,
      how could we communicate?

    12. вывод из запоя на дому в москве [url=http://vyvod-iz-zapoya-9.ru]http://vyvod-iz-zapoya-9.ru[/url] .

    13. новости олимпиады [url=www.sportivnye-novosti-1.ru]новости олимпиады[/url] .

    14. обложки вайлдберрис Нейросеть для создания карточки товара Вайлдберриз – это специализированная нейросеть, обученная на данных о товарах, представленных на платформе Вайлдберриз (Wildberries). Она способна анализировать фотографии, описания, характеристики и отзывы покупателей, чтобы автоматически генерировать качественные и привлекательные карточки товаров, которые соответствуют требованиям Вайлдберриз и привлекают внимание потенциальных покупателей.

      JeromeThatt

      8 Oct 25 at 3:45 pm

    15. Экскурсии по Казани — обзор маршрутов и лучших туров по Казани
      Казань — жемчужина Поволжья с богатой историей и неповторимой культурой. Если вы ищете интересные экскурсии по Казани, на нашем сайте представлены лучшие маршруты — от обзорных программ до авторских прогулок.
      [url=https://to-kazan.ru/tours/bolgar/avtobus-b]экскурсии в болгар из казани на автобусе[/url]
      Экскурсии Казань — автобусные, пешеходные и тематические туры
      Мы предлагаем разнообразные экскурсии Казань: обзорные автобусные маршруты (включают Кремль, Баумана, Кабан и Старо-Татарскую Слободу), пешеходные прогулки, гастрономические экскурсии, квесты и семейные форматы.

      Что такое обзорная экскурсия по Казани
      Отзывы туристов подтверждают: «Казань за 4 часа — экскурсия Казань за 4 часа + Кремль… экскурсовод Елена увлекла рассказом».
      Программа включает:

      посещение Казанского Кремля и мечети Кул-Шариф;
      знакомство с озером Кабан, ул. Баумана и памятниками города .
      https://to-kazan.ru/tours/ekskursii-kazan/obzornaya-avtobus
      обзорные экскурсии по казани
      Экскурсии в Казани — вечерние и ночные маршруты
      Если вы хотите увидеть город в другом свете, выбирайте экскурсии в Казани вечером. Самый популярный формат — ночная экскурсия Казань, когда подсветка архитектурных объектов — Кремль, ЗАГС, мост Миллениум — создаёт невероятные впечатления.

      Обзорные экскурсии Казань по ночному городу
      Тур длится около 2–3 часов и включает: заезд к ключевым смотровым точкам, прогулку по набережной Казанки с иллюминацией, катание на колесе обозрения «Вокруг света».

      Почему выбрать именно экскурсию Казань от нас?
      Лицензированные гиды с живым, эмоциональным стилем (отзывы: «гид Марсель — просто супер-гид!»)
      Малые группы для комфортного восприятия и безопасных остановок
      Современный и удобный транспорт, радиогиды, подогрев зимний-зимний сезон
      Возможность онлайн бронирования и подтверждение через сайт
      Казань экскурсия — что входит и сколько длится
      Автобус от центра Казани (чаще всего — район метро «Кремлёвская»)
      Гид ведет экскурсию как в автобусе, так и при остановках
      Основные объекты: Кремль, мечеть Кул-Шариф, улица Баумана, озеро Кабан, Старо-Татарская слобода, теcатр Камала
      В вечерних версиях: мост Миллениум, дворец земледельцев, стадион «Казань Арена» ночью; плюс колесо обозрения
      Сколько стоят экскурсии в Казани.

      BrianRhype

      8 Oct 25 at 3:49 pm

    16. новости олимпиады [url=http://www.sportivnye-novosti-1.ru]новости олимпиады[/url] .

    17. Статья посвящена анализу текущих трендов в медицине и их влиянию на жизнь людей. Мы рассмотрим новые технологии, методы лечения и значение профилактики в обеспечении долголетия и здоровья.
      Эксклюзивная информация – https://mediry.ru/category/zdorove/page/5

      DamonDouse

      8 Oct 25 at 3:51 pm

    18. Minotaurus ICO’s whitepaper highlights balanced token release. $MTAUR holders shape via DAO—democratic and cool. Casual market entry is spot on.
      minotaurus coin

      WilliamPargy

      8 Oct 25 at 3:52 pm

    19. Wow, this paragraph is pleasant, my younger sister is analyzing these things, thus I am going to convey her.

    20. Great article! I’ve been using Nitric Boost for a while now,
      and it has made a noticeable difference in my energy levels.
      If you’re serious about your fitness goals, you should definitely check it out.

      Visit https://nitricboost–usa.us for details!

    21. Hello! Quick question that’s completely off topic. Do you know
      how to make your site mobile friendly? My weblog looks weird when viewing
      from my iphone4. I’m trying to find a template or plugin that might
      be able to correct this issue. If you have any recommendations, please share.
      With thanks!

    22. прогноз игр по футболу [url=https://kompyuternye-prognozy-na-futbol24.ru/]kompyuternye-prognozy-na-futbol24.ru[/url] .

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

    24. diamondescort18 – I keep coming back, this layout just feels right somehow.

      Fonda Sopha

      8 Oct 25 at 3:55 pm

    25. Excited for $MTAUR coin’s role in personalizing characters—fancy outfits via tokens? Yes please. Presale’s low barrier ($10 min) opens it to everyone. Community events sound epic.
      mtaur coin

      WilliamPargy

      8 Oct 25 at 3:56 pm

    26. Ahaa, its pleasant conversation regarding this article
      here at this webpage, I have read all that,
      so at this time me also commenting here.

      Opulatrix

      8 Oct 25 at 3:56 pm

    27. На стороне Чилийского государства у подножия вулкана находится Национальный парк с аналогичным названием – Льюльяйльяко, поэтому окрестности горы
      очень живописные.

    28. Great post! Thanks for sharing your thoughts on this topic.
      I found it particularly interesting how you discussed the impact of community engagement
      in today’s world. You might also like to explore [Completethyroid](https://info-completethyroid.us/)

    29. 100 прогнозы на футбол [url=www.kompyuternye-prognozy-na-futbol24.ru/]www.kompyuternye-prognozy-na-futbol24.ru/[/url] .

    30. Richardwap

      8 Oct 25 at 4:00 pm

    31. Если домашние методы не помогают, в «Частном Медике 24» обеспечат профессиональный вывод из запоя в стационаре.
      Получить больше информации – [url=https://vyvod-iz-zapoya-v-stacionare21.ru/]нарколог вывод из запоя в стационаре нижний новгород[/url]

      CharlesElage

      8 Oct 25 at 4:03 pm

    32. For the reason that the admin of this web page is working, no hesitation very shortly it will be renowned, due to its quality contents.

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

      Diplomi_qpOr

      8 Oct 25 at 4:03 pm

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

      Diplomi_ilei

      8 Oct 25 at 4:03 pm

    35. Игрок может выводить в неделю до RUB, а сформировать заявку получится только после пополнения депозитного баланса на сумму от тысячи рублей.

    36. Контроль
      Подробнее тут – https://narkologicheskaya-klinika-lyubercy0.ru/

      JerryIcelf

      8 Oct 25 at 4:07 pm

    37. самые точные прогнозы на футбол [url=www.kompyuternye-prognozy-na-futbol23.ru/]www.kompyuternye-prognozy-na-futbol23.ru/[/url] .

    38. This piece of writing gives clear idea designed for the new viewers of blogging, that
      genuinely how to do blogging and site-building.

    39. анонимный. вывод. из. запоя. москва. [url=https://vyvod-iz-zapoya-9.ru/]vyvod-iz-zapoya-9.ru[/url] .

    40. Формат
      Ознакомиться с деталями – https://narkologicheskaya-klinika-serpuhov0.ru/platnaya-narkologicheskaya-klinika-v-serpuhove/

      Donaldgug

      8 Oct 25 at 4:11 pm

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

      Diplomi_jlPl

      8 Oct 25 at 4:13 pm

    42. This post is really a good one it assists new
      net people, who are wishing for blogging.

    43. прогнозы на футбол сегодня с анализом [url=https://kompyuternye-prognozy-na-futbol23.ru/]https://kompyuternye-prognozy-na-futbol23.ru/[/url] .

    44. Гарантия качества на все купленные велосипеды kraken официальные ссылки кракен онион тор кракен онион зеркало кракен даркнет маркет

      RichardPep

      8 Oct 25 at 4:16 pm

    45. как купить диплом в колледже [url=http://frei-diplom9.ru]как купить диплом в колледже[/url] .

      Diplomi_ryea

      8 Oct 25 at 4:18 pm

    46. вывод из запоя бесплатно москва [url=http://www.vyvod-iz-zapoya-9.ru]http://www.vyvod-iz-zapoya-9.ru[/url] .

    47. [url=https://gracie.digital/]digital агентство[/url]

      SpencerDal

      8 Oct 25 at 4:19 pm

    48. Пациентам в Самаре предлагается анонимное лечение в стационаре с круглосуточным уходом и безопасными условиями.
      Выяснить больше – [url=https://vyvod-iz-zapoya-v-stacionare-samara24.ru/]нарколог вывод из запоя в стационаре в самаре[/url]

      AndrewGoape

      8 Oct 25 at 4:19 pm

    49. Выездная наркологическая помощь в Нижнем Новгороде — капельница от запоя с выездом на дом. Мы обеспечиваем быстрое и качественное лечение без необходимости посещения клиники.
      Получить дополнительную информацию – [url=https://vyvod-iz-zapoya-nizhnij-novgorod11.ru/]врач вывод из запоя[/url]

      CarsonNed

      8 Oct 25 at 4:20 pm

    50. Экстренная помощь при запое в Нижнем Новгороде — капельница на дому от опытных врачей-наркологов.
      Получить дополнительные сведения – [url=https://vyvod-iz-zapoya-nizhnij-novgorod13.ru/]вывод из запоя капельница на дому в нижний новгороде[/url]

      AaronDum

      8 Oct 25 at 4:22 pm

    Leave a Reply