public function raise($behavior, $sender, $args)
 {
     if (is_string($behavior)) {
         $behavior = new Behavior($behavior);
     }
     $behavior->_target = $behavior->_target ? $behavior->_target : $sender;
     foreach ($this->_value as $c) {
         if ($c->name() == $behavior->name()) {
             $c->raise($behavior, $args);
         }
     }
 }
Esempio n. 2
0
 public function perform()
 {
     $args = func_get_args();
     $behavior = array_shift($args);
     if (is_string($behavior)) {
         $behavior = new Behavior($behavior);
     }
     if (!$behavior instanceof Behavior) {
         throw new InvalidArgumentException("Invalid Behavior Type");
     }
     $behaviorName = $behavior->name();
     if ($this->can($behaviorName)) {
         $this->dispatch($behavior, $args);
         $this->_history->add($behaviorName, $behaviorName);
         if ($this->_behaviors->has($behaviorName) && $this->_behaviors->get($behaviorName)->is_persistent()) {
             if (!$this->_multistate) {
                 $this->_state->clear();
             }
             $this->_state->add($behaviorName, $behaviorName);
         }
     } else {
         throw new NotImplementedException("Behavior '{$behaviorName}' is not implemented");
     }
 }
Esempio n. 3
0
 public function route($senderName, $recipientName, $behavior, $callback = null)
 {
     if (\is_string($behavior)) {
         $behavior = new Behavior($behavior);
     }
     $handlers = $this->_handlers->get($behavior->name());
     $new_broadcast = true;
     $broadcaster = array($this, 'broadcast');
     foreach ($handlers as $handler) {
         if ($handler->callback() == $broadcaster && $handler->name() == $behavior->name()) {
             $new_broadcast = false;
         }
     }
     if ($this->name() == $senderName) {
         if ($new_broadcast) {
             $this->behavior($behavior, $broadcaster);
         }
     } elseif (!$this->_services->has($senderName)) {
         throw new Exception("The service {$senderName} is not registered", 1);
     } elseif ($callback) {
         // echo $senderName ." | ". $behavior . "\n";
         $this->register($senderName, $behavior, array($this, 'boost'));
     }
     if (!$this->_services->has($recipientName) && $this->name() != $recipientName) {
         throw new Exception("The service {$recipientName} is not registered", 1);
     }
     $this->_routes[$behavior->name()][$senderName][] = array('recipient' => $recipientName, 'callback' => $callback);
     return $this;
 }