Пример #1
0
 /**
  * Send the object and originator to the observer
  * 
  * Run it past the filter and if we meet success, then fire off
  * the handler
  * 
  * @param Falcraft\Patterns\Resource\PublisherInterface &$subject
  *              The originator of the event
  * @param Falcraft\Patterns\Resource\StateInterface &$state The
  *              originating event object
  * 
  * @return false if state doesn't cause a notification
  * 
  */
 public function notify(PatternsResource\PublisherInterface &$subject, PatternsResource\StateInterface &$state)
 {
     if ($state instanceof EventResource\AbstractEvent) {
         if ($this->filter->isApplicable($state)) {
             $this->handler->notify($subject, $state);
             return true;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * Set the state of the aggregator, causes announce
  * 
  * We run the state through the filter, if present, and if it makes it
  * we change the state and announce it to all our listeners
  * 
  * @param Falcraft\Patterns\Resource\StateInterface $state
  * 
  * @return bool True if event is handled
  * 
  */
 public function setStateObject(PatternsResource\StateInterface $state)
 {
     if ($state instanceof EventResource\AbstractEvent) {
         if ($this->filter && $this->filter->isApplicable($state)) {
             $this->state = $state;
             $this->announce();
         } else {
             if (!$this->filter) {
                 $this->state = $state;
                 $this->announce();
             }
         }
         return true;
     } else {
         return false;
     }
 }