Example #1
0
 /**
  * Connects a callable to an event
  * @param string|\Nimbles\Core\Event|\Nimbles\Core\Event\SelfConnectInterface $event
  * @param mixed                                                                 $callable
  * @return void
  * @throws \Nimbles\Core\Event\Exception\InvalidConnections
  */
 public function connect($event, $callable = null)
 {
     if ($event instanceof SelfConnectInterface) {
         // self connect the object
         if (!is_array($connections = $event->getConnections())) {
             throw new Exception\InvalidConnections('Nimbles\\Core\\Event\\SelfConnectInterface::getConnections should return an array');
         }
         foreach ($connections as $event => $callable) {
             $this->connect($event, $callable);
         }
         return;
     }
     $name = $event instanceof Event ? $event->getName() : $event;
     if (!is_callable($callable) && is_array($callable)) {
         // if we have an array of callables, add each
         foreach ($callable as $call) {
             $this->connect($name, $call);
         }
         return;
     }
     if (!$this->offsetExists($name)) {
         $this[$name] = new Event(array($callable), array('name' => $name));
     } else {
         $this[$name][] = $callable;
     }
 }