/** * @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; }
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(); }); }
/** * @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); } } }
/** * 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)); }
/** * 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)); }
/** * 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]); }