/** * 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()); } } }
public function testCanGetBinding() { $listener = new Listener(); $listener->onCreate(function () { return 'foo'; }); $bindings = $listener->getBindings('create'); $this->assertEquals('foo', $bindings[0]()); }