public function setEventEmitter(EventEmitterInterface $emitter)
 {
     $emitter->on('phantestic.test.failresult', [$this, 'handleFail']);
     $emitter->on('phantestic.test.passresult', [$this, 'handlePass']);
     $emitter->on('phantestic.tests.before', [$this, 'beforeTests']);
     $emitter->on('phantestic.tests.after', [$this, 'afterTests']);
 }
 public function __construct(EventEmitterInterface $stream)
 {
     $this->lines = new \SplQueue();
     $this->promisedLines = new \SplQueue();
     $stream->on('data', function ($data) {
         $newline_count = substr_count($data, "\n");
         $this->buf .= $data;
         if ($newline_count > 0) {
             $lines = explode("\n", $this->buf);
             $this->buf = array_pop($lines);
             foreach ($lines as $line) {
                 $line .= "\n";
                 if ($this->onLine) {
                     $onLine = $this->onLine;
                     $onLine($line);
                 }
                 if ($this->promisedLines->count() > 0) {
                     $this->promisedLines->dequeue()->resolve($line);
                 } else {
                     $this->lines->enqueue($line);
                 }
             }
         }
     });
 }
 /**
  * @return DoctrineEntityManager
  * @throws \Doctrine\ORM\ORMException
  */
 public function createEntityManager()
 {
     $this->eventEmitter->emit('doctrine.entityManager.preCreate', []);
     $entityManager = $this->buildEntityManager();
     $this->eventEmitter->emit('doctrine.entityManager.postCreate', [$entityManager]);
     return $entityManager;
 }
 /**
  * Register the reporters.
  *
  * @return $this
  */
 public function register()
 {
     $this->eventEmitter->on('peridot.start', [$this, 'onPeridotStart']);
     $this->eventEmitter->on('peridot.execute', [$this, 'onPeridotExecute']);
     $this->eventEmitter->on('peridot.reporters', [$this, 'onPeridotReporters']);
     return $this;
 }
 public function inherit(array $events, BaseEmitterInterface $emitter)
 {
     foreach ($events as $event) {
         $emitter->on($event, function () use($event) {
             $this->emit($event, func_get_args());
         });
     }
 }
Exemple #6
0
 static function forwardEvents(EventEmitterInterface $to, EventEmitterInterface $from, array $events)
 {
     foreach ($events as $event) {
         $from->on($event, function () use($event, $to) {
             $event_args = func_get_args();
             call_user_func_array(array($to, 'emit'), array($event, $event_args));
         });
     }
 }
 /**
  * Register the Yo plugin
  *
  * @param EventEmitterInterface $emitter
  * @param $token
  * @param array $users
  * @param null $link
  * @return static
  */
 public static function register(EventEmitterInterface $emitter, $token, array $users, $link = null)
 {
     $request = new Request($token, $users);
     if (!is_null($link)) {
         $request->setLink($link);
     }
     $plugin = new static($request);
     $emitter->on('peridot.end', [$plugin, 'onPeridotEnd']);
     return $plugin;
 }
 /**
  *
  * @param EventEmitterInterface $emitter
  * @param string[] $events
  * @param callable $callback
  * @return callable[]
  */
 protected static function registerCallbacks(EventEmitterInterface $emitter, array $events, callable $callback)
 {
     if (empty($events)) {
         return [];
     }
     $wrappedCallback = function () use($callback) {
         return $callback(func_get_args());
     };
     $listeners = array_fill_keys($events, $wrappedCallback);
     foreach ($listeners as $event => $callback) {
         $emitter->on($event, $callback);
     }
     return $listeners;
 }
 /**
  * Tests a successful poll with a custom formatter.
  */
 public function testSuccessfulPollWithCustomFormatter()
 {
     // Configure plugin with formatter
     $this->plugin = new Plugin(array('urls' => array($this->url), 'targets' => array('nick!user@host' => array('#channel')), 'formatter' => new TestFormatter()));
     $this->plugin->setLogger($this->logger);
     $this->plugin->setEventEmitter($this->emitter);
     // Simulate the Http plugin response for the first poll
     $feed = $this->getFeed();
     $feedString = $this->getFeedString($feed);
     $this->emitter->once('http.request', function ($request) use($feedString) {
         $request->callResolve($feedString, array(), 200);
     });
     // Invoke the first poll
     $this->plugin->setLoop($this->loop);
     $this->plugin->setEventQueue($this->event, $this->queue);
     // Verify the next poll is queued
     Phake::verify($this->loop)->addTimer(300, Phake::capture($callback));
     // Simulate the Http plugin response for the next poll
     $this->addFeedEntry($feed);
     $feedString = $this->getFeedString($feed);
     $this->emitter->once('http.request', function ($request) use($feedString) {
         $request->callResolve($feedString, array(), 200);
     });
     // Invoke the next poll
     $callback();
     // Verify that the new item is sent using the custom formatter
     Phake::verify($this->queue, Phake::times(1))->ircPrivmsg('#channel', 'Title 2');
 }
 /**
  * @return \ArrayIterator
  */
 public function getIterator()
 {
     $classmap = $this->getClassmap();
     $filter = $this->filter;
     $generator = $this->generator;
     foreach ($classmap as $class => $file) {
         $reflector = new \ReflectionClass($class);
         $methods = array_map(function ($method) {
             return $method->name;
         }, $reflector->getMethods(\ReflectionMethod::IS_PUBLIC & ~\ReflectionMethod::IS_STATIC));
         foreach ($methods as $method) {
             if (!$filter($file, $class, $method)) {
                 continue;
             }
             $case = $generator($class, $method);
             if ($this->emitter) {
                 $this->emitter->emit('phantestic.loader.loaded', [$case, $class, $method]);
             }
             (yield $case);
         }
     }
 }
 /**
  * @param EventEmitterInterface $emitter
  */
 public function __construct(EventEmitterInterface $emitter)
 {
     $this->emitter = $emitter;
     $this->emitter->on('peridot.start', [$this, 'onPeridotStart']);
     $this->emitter->on('peridot.execute', [$this, 'onPeridotExecute']);
     $this->emitter->on('peridot.load', [$this, 'onPeridotLoad']);
     $this->emitter->on('peridot.configure', [$this, 'onPeridotConfigure']);
     $this->emitter->on('peridot.reporters', [$this, 'onPeridotReporters']);
 }
Exemple #12
0
 /**
  * Deletes a Document instance for the given RequestInfo
  *
  * @param RequestInfo $requestInfo
  * @return HandlerResultInterface
  */
 public function delete(RequestInfo $requestInfo)
 {
     $database = $this->getDatabaseForRequestInfo($requestInfo);
     if (!$database) {
         throw new InvalidRequestParameterException(sprintf('Database with identifier "%s" not found', $requestInfo->getDatabaseIdentifier()), 1413035859);
     }
     //		if (!$requestInfo->getDataIdentifier()) throw new InvalidRequestParameterException('Document identifier is missing', 1413035855);
     if ($requestInfo->getDataIdentifier()) {
         $document = $this->getDataForRequest($requestInfo);
         if (!$document) {
             throw new InvalidRequestParameterException(sprintf('Document with identifier "%s" not found in database "%s"', $requestInfo->getDataIdentifier(), $requestInfo->getDatabaseIdentifier()), 1413035855);
         }
         $database->remove($document);
         $this->eventEmitter->emit(Event::DOCUMENT_DELETED, array($document));
         return new HandlerResult(204, sprintf('Document "%s" deleted', $requestInfo->getDataIdentifier()));
     }
     $databaseIdentifier = $database->getIdentifier();
     $this->coordinator->dropDatabase($databaseIdentifier);
     $this->eventEmitter->emit(Event::DATABASE_DELETED, array($database));
     return new HandlerResult(204, sprintf('Database "%s" deleted', $databaseIdentifier));
 }
 /**
  * Attach the necessary events for this plugin to work.
  */
 public function listen()
 {
     $this->emitter->on('suite.start', [$this, 'onSuiteStart']);
 }
 /**
  * Constructor.
  *
  * @param EventEmitterInterface $eventEmitter
  */
 public function __construct(EventEmitterInterface $eventEmitter)
 {
     $eventEmitter->on('code-coverage.start', [$this, 'onCodeCoverageStart']);
 }
 public function registerTo(EventEmitterInterface $emitter)
 {
     $emitter->on(self::START_EVENT, [$this, 'onStart']);
     $emitter->on(self::SUITE_START_EVENT, [$this, 'onSuiteStart']);
 }
 /**
  * Listen for message events.
  *
  * @param EventEmitterInterface $emitter
  * @return void
  */
 protected function listen(EventEmitterInterface $emitter)
 {
     $emitter->on('suite.start', [$this, 'onSuiteStart']);
     $emitter->on('suite.end', [$this, 'onSuiteEnd']);
     $emitter->on('test.passed', [$this, 'onTestPassed']);
     $emitter->on('test.failed', [$this, 'onTestFailed']);
     $emitter->on('test.pending', [$this, 'onTestPending']);
     $emitter->on('suite.halt', [$this, 'onSuiteHalt']);
 }
 /**
  * Emits the given state machine event,
  * passing the given subject, affected state and the state machine itself as arguments to anyone listening.
  *
  * @param string $event Must be one of state machine's $supported_events, hence one of the ON_* constants.
  * @param StatefulSubjectInterface $subject
  * @param StateInterface $current_state
  *
  * @throws Error If the given event is not supported.
  */
 protected function fireEvent($event, StatefulSubjectInterface $subject, StateInterface $affected_state)
 {
     $this->guardSupportedEvents($event);
     $this->event_emitter->emit($event, [$this, $subject, $affected_state]);
 }
Exemple #18
0
 /**
  * Commit the database to the file system
  *
  * @param DatabaseInterface $database
  */
 public function commitDatabase($database)
 {
     $this->dataWriter->writeDatabase($database);
     $this->eventEmitter->emit(Event::DATABASE_COMMITTED, array($database));
 }
 /**
  * @param EventEmitterInterface $emitter
  */
 public function __construct(EventEmitterInterface $emitter)
 {
     $this->emitter = $emitter;
     $this->emitter->on('peridot.reporters', [$this, 'onPeridotReporters']);
 }
/**
 * Creates a `Promise` which resolves with an array of all the event data
 *
 * @param ReadableStreamInterface|WritableStreamInterface $stream
 * @param string                                          $event
 * @return CancellablePromiseInterface Promise<string, Exception>
 */
function all(EventEmitterInterface $stream, $event = 'data')
{
    // stream already ended => resolve with empty buffer
    if ($stream instanceof ReadableStreamInterface) {
        // readable or duplex stream not readable => already closed
        // a half-open duplex stream is considered closed if its readable side is closed
        if (!$stream->isReadable()) {
            return Promise\resolve(array());
        }
    } elseif ($stream instanceof WritableStreamInterface) {
        // writable-only stream (not duplex) not writable => already closed
        if (!$stream->isWritable()) {
            return Promise\resolve(array());
        }
    }
    $buffer = array();
    $bufferer = function ($data) use(&$buffer) {
        $buffer[] = $data;
    };
    $stream->on($event, $bufferer);
    $promise = new Promise\Promise(function ($resolve, $reject) use($stream, &$buffer) {
        $stream->on('error', function ($error) use($reject) {
            $reject(new \RuntimeException('An error occured on the underlying stream while buffering', 0, $error));
        });
        $stream->on('close', function () use($resolve, &$buffer) {
            $resolve($buffer);
        });
    }, function ($_, $reject) {
        $reject(new \RuntimeException('Cancelled buffering'));
    });
    return $promise->then(null, function ($error) use(&$buffer, $bufferer, $stream, $event) {
        // promise rejected => clear buffer and buffering
        $buffer = array();
        $stream->removeListener($event, $bufferer);
        throw $error;
    });
}
Exemple #21
0
 public function __construct(LoopInterface $loop, EventEmitterInterface $emitter, $token)
 {
     $self = $this;
     $this->emitter = $emitter;
     $connector = new ClientFactory($loop);
     $endpoint = $this->getEndpoint($token);
     $consumer = new Consumer($emitter);
     $connector($endpoint)->then(function (WebSocket $conn) use($self, $emitter) {
         $emitter->emit('log', ['Connected!']);
         $conn->on('message', function ($msg) use($self, $emitter) {
             $emitter->emit('log', ['Received a message: ' . $msg, OutputInterface::VERBOSITY_DEBUG]);
             $msgData = json_decode($msg);
             if (property_exists($msgData, 'user') && $msgData->user === $self->selfId) {
                 return;
             }
             if (property_exists($msgData, 'channel') && substr($msgData->channel, 0, 1) === 'D' && property_exists($msgData, 'text')) {
                 if (strpos($msgData->text, 'start') !== false) {
                     $self->log('Received a start request: ' . json_encode($msg));
                     $emitter->emit('session.start', [$msgData]);
                 } elseif (strpos($msgData->text, 'stop') !== false) {
                     $self->log('Received a stop request: ' . json_encode($msg));
                     $emitter->emit('session.stop', [$msgData]);
                 } elseif (strpos($msgData->text, 'est') !== false) {
                     $self->log('Received an estimate request: ' . json_encode($msg));
                     $emitter->emit('session.estimate', [$msgData]);
                 } elseif (strpos($msgData->text, 'rate') !== false) {
                     $emitter->emit('session.rate', [$msgData]);
                 } elseif (strpos($msgData->text, 'status') !== false) {
                     $self->log('Received an estimate request: ' . json_encode($msg));
                     $emitter->emit('session.status', [$msgData]);
                 } elseif (strpos($msgData->text, 'hello') !== false) {
                     $emitter->emit('hello', [$msgData]);
                 } else {
                     $emitter->emit('unknown', [$msgData]);
                 }
             }
         });
         // $emitter->on('send', function($msg) use ($conn, $self) {
         //     $self->increase();
         //     $msg['id'] = $self->msgCounter;
         //     $self->log('Sending message: '.json_encode($msg));
         //     $conn->send(json_encode($msg));
         //     $self->increase();
         // });
     }, function ($e) use($loop, $emitter) {
         $emitter->emit('error.fatal', "Could not connect: {$e->getMessage()}\n");
         $loop->stop();
     });
 }
 /**
  * Detach the plugin.
  */
 public function detach(EventEmitterInterface $emitter)
 {
     $emitter->removeListener('suite.define', [$this, 'onSuiteDefine']);
     $emitter->removeListener('suite.start', [$this, 'onSuiteStart']);
 }
 /**
  * @param EventEmitterInterface $emitter
  * @param HttpKernelInterface|callable  $factory
  */
 public static function register(EventEmitterInterface $emitter, $factory, $property = "client")
 {
     $plugin = new static($emitter, $factory, $property);
     $emitter->on('runner.start', [$plugin, 'onRunnerStart']);
     return $plugin;
 }
 /**
  * Listen for Peridot events
  */
 private function listen()
 {
     $this->emitter->on('peridot.configure', [$this, 'onPeridotConfigure']);
     $this->emitter->on('peridot.start', [$this, 'onPeridotStart']);
     $this->emitter->on('peridot.end', [$this, 'onPeridotEnd']);
 }
 /**
  * Listen for Peridot events.
  */
 private function listen()
 {
     $this->eventEmitter->on('suite.start', [$this, 'onSuiteStart']);
 }