Пример #1
0
 public function testDetermineEventBinding()
 {
     $resource = m::mock('JasonLewis\\ResourceWatcher\\Resource\\ResourceInterface');
     $listener = new Listener();
     $event = new Event($resource, Event::RESOURCE_CREATED);
     $this->assertEquals('create', $listener->determineEventBinding($event));
     $event = new Event($resource, Event::RESOURCE_MODIFIED);
     $this->assertEquals('modify', $listener->determineEventBinding($event));
     $event = new Event($resource, Event::RESOURCE_DELETED);
     $this->assertEquals('delete', $listener->determineEventBinding($event));
 }
Пример #2
0
 /**
  * Call the bindings on the listener for a given event.
  *
  * @param  \JasonLewis\ResourceWatcher\Listener  $listener
  * @param  \JasonLewis\ResourceWatcher\Event  $event
  * @return void
  */
 protected function callListenerBindings(Listener $listener, Event $event)
 {
     $binding = $listener->determineEventBinding($event);
     if ($listener->hasBinding($binding)) {
         foreach ($listener->getBindings($binding) as $callback) {
             $resource = $event->getResource();
             call_user_func($callback, $resource, $resource->getPath());
         }
     }
     // If a listener has a binding for anything we'll also spin through
     // them and call each of them.
     if ($listener->hasBinding('*')) {
         foreach ($listener->getBindings('*') as $callback) {
             $resource = $event->getResource();
             call_user_func($callback, $event, $resource, $resource->getPath());
         }
     }
 }