Example #1
0
 public function testRegisterAndForwardThenUnregister()
 {
     $listener = new TestListener();
     $target = new EventEmitter();
     $n = 0;
     $target->on('received', function ($type, $data) use(&$n, &$capturedType, &$capturedData) {
         $n++;
         $capturedData = $data;
         $capturedType = $type;
     });
     $m = 0;
     $listener->on('received', function ($type, $data) use(&$m, &$capturedType2, &$capturedData2) {
         $m++;
         $capturedData2 = $data;
         $capturedType2 = $type;
     });
     $listeners = new Listeners();
     $listeners->register($listener, $target);
     $type = 'type';
     $data = 'data';
     $listener->handle($type, $data);
     $listener->handle($type, $data);
     $listeners->unregister($listener, $target);
     $listener->handle($type, $data);
     $this->assertEquals(2, $n);
     $this->assertEquals(3, $m);
     $this->assertEquals($type, $capturedType);
     $this->assertEquals($data, $capturedData);
     $this->assertEquals($type, $capturedType2);
     $this->assertEquals($data, $capturedData2);
 }
Example #2
0
 /**
  * @param CommandInterface $command
  * @return bool
  */
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof EditMemberCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->member_repo);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     //        $member = new Member();
     $member = $this->app->em->getRepository("Mabes\\Entity\\Member")->find($command->getAccountId());
     $member->setEmail($command->getEmail());
     $member->setAccountNumber($command->getAccountNumber());
     $member->setAccountHolder($command->getAccountHolder());
     $member->setBankName($command->getBankName());
     $member->setFullName($command->getFullname());
     $member->setAddress($command->getAddress());
     $member->setPhone($command->getPhone());
     $this->app->em->flush();
     //        $this->member_repo->save($member);
     $data = ["account_id" => $member->getAccountId(), "email" => $member->getEmail(), "phone" => $member->getPhone(), "fullname" => $member->getFullName(), "bank_name" => $member->getBankName(), "account_number" => $member->getAccountNumber(), "account_holder" => $member->getAccountHolder(), "address" => $member->getAddress(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("validation.created", [$data]);
     return true;
 }
 public function testWithOverrides()
 {
     $called = false;
     $callback = function ($case, $class, $method) use(&$called) {
         $called = true;
         $this->assertInstanceOf('Phantestic\\Test\\Test', $case);
         $this->assertSame(__NAMESPACE__ . '\\PassingTest', $class);
         $this->assertSame('testPassingTestMethod', $method);
     };
     $filter = function ($file, $class, $method) {
         return $file === __DIR__ . '/PassingTest.php' && $class === __NAMESPACE__ . '\\PassingTest' && $method === 'testPassingTestMethod';
     };
     $generator = function ($class, $method) {
         $this->assertSame(__NAMESPACE__ . '\\PassingTest', $class);
         $this->assertSame('testPassingTestMethod', $method);
         $callback = function () {
             // noop
         };
         return new \Phantestic\Test\Test($callback, 'foo');
     };
     $emitter = new EventEmitter();
     $emitter->on('phantestic.loader.loaded', $callback);
     $loader = new ClassmapObjectLoaderSubclass($emitter, $filter, $generator);
     $this->testLoader($loader);
     $this->assertTrue($called, 'Event callback was not called');
 }
 public function __construct(LoopInterface $loop, EventEmitter $emit, \SplObjectStorage $clients, RoundProcessor $roundProcessor, EngineHelper $helper, $time = 60, $debug = false)
 {
     $this->debug = $debug;
     $this->helper = $helper;
     $this->emit = $emit;
     $this->loop = $loop;
     $this->roundTimer = new RoundTimer($loop, $emit);
     $this->roundNumber = 0;
     $this->clients = $clients;
     $this->disconnected = new \SplObjectStorage();
     $this->time = $time;
     $that = $this;
     $this->say = new Say($this->clients);
     $this->roundProcessor = $roundProcessor;
     $players = new Say($this->clients);
     // Setup listeners on the roundTimer object.
     $emit->on('GAME.COUNTDOWN', function () use($that) {
         if ($this->playerCount !== $this->clients->count()) {
             $this->playerCount = $this->clients->count();
             $this->say->to($this->clients)->that(Say::TICK, ["players" => $this->playerCount]);
         }
     });
     // Setup listeners on the roundTimer object.
     $emit->on('GAME.COUNTDOWN_END', function () use($that, $loop, $emit) {
         $this->say->to($this->clients)->that(Say::GAME_STARTING, ["players" => $this->clients->count()]);
         $this->setGameStarted(true);
         $loop->addTimer(3, function () use($loop, $emit) {
             $this->startRound($loop, $emit);
         });
     });
     $this->roundTimer->startCountDown($this->time);
 }
 public function testPendingThenWaiting()
 {
     $stream = new EventEmitter();
     $buf = new BufferedReader($stream);
     $this->assertPromiseYields("line1\n", $buf->readline());
     $stream->emit('data', ["line1\nline2\n"]);
     $this->assertPromiseYields("line2\n", $buf->readline());
 }
 /**
  * This read sets the pending test count to 0
  * and immediately frees all workers.
  */
 public function read()
 {
     $this->pool->setPending([]);
     $workers = $this->pool->getWorkers();
     foreach ($workers as $worker) {
         $this->emitter->emit('peridot.concurrency.worker.completed', [$worker]);
     }
 }
Example #7
0
 /**
  * Output some contents.
  * @param  string $out The output.
  */
 public function output($out)
 {
     if (empty($this->emitter)) {
         $this->value .= $out;
     } else {
         $this->emitter->emit('output', array($out));
     }
 }
 public function testDoNoRemoveOtherListeners()
 {
     $emitter = new EventEmitter();
     $listener = function () {
     };
     $emitter->on('end', $listener);
     EventPromise::listen($emitter, ['end'])->done();
     $emitter->emit('end', ['payload']);
     $this->assertSame([$listener], $emitter->listeners('end'));
 }
 /**
  * Emit an event
  *
  * @param string $event
  * @param array  $arguments
  *
  * @return Void
  */
 public function emit($event, array $arguments = array())
 {
     foreach ($this->anyListeners as $listener) {
         call_user_func_array($listener, [$event, $arguments]);
     }
     parent::emit($event, $arguments);
 }
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof CreateIslamicAccountCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->member_repo);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     $member = $this->member_repo->findOneBy(["account_id" => $command->getAccountId()]);
     $data = ["account_id" => $command->getAccountId(), "mt4_account" => $command->getMt4Account(), "fullname" => $member->getFullname(), "phone" => $member->getPhone(), "email" => $member->getEmail(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("akun.islami.created", [$data]);
     return true;
 }
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof WithdrawalMarkAsDoneCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->withdrawal_repository);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     $withdrawal = $this->withdrawal_repository->findOneBy(["withdrawal_id" => $command->getWithdrawalId()]);
     $withdrawal->setStatus(Withdrawal::STATUS_PROCESSED);
     $this->withdrawal_repository->save($withdrawal);
     $data = ["email" => $withdrawal->getClient()->getEmail(), "account_id" => $withdrawal->getClient()->getAccountId(), "full_name" => $withdrawal->getClient()->getFullName(), "ticket" => $withdrawal->getWithdrawalId(), "amount" => $withdrawal->getAmount(), "bank_name" => $withdrawal->getClient()->getBankName(), "account_number" => $withdrawal->getClient()->getAccountNumber(), "account_holder" => $withdrawal->getClient()->getAccountHolder(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("admin.withdrawal.processed", [$data]);
     return true;
 }
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof DepositMarkAsFailedCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->deposit_repository);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     $deposit = $this->deposit_repository->findOneBy(["deposit_id" => $command->getDepositId()]);
     $deposit->setStatus(Deposit::STATUS_FAILED);
     $this->deposit_repository->save($deposit);
     $data = ["email" => $deposit->getClient()->getEmail(), "ticket" => $deposit->getDepositId(), "full_name" => $deposit->getClient()->getFullName(), "account_id" => $deposit->getClient()->getAccountId(), "amount_idr" => $deposit->getAmountIdr(), "amount_usd" => $deposit->getAmountUsd(), "bank_name" => $deposit->getToBank(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("admin.deposit.failed", [$data]);
     return true;
 }
Example #13
0
 /**
  * @param string|null $input
  * @throws Exception
  * @return Result
  */
 public function run($input = null)
 {
     $command = $this->_getCommand();
     $descriptorSpec = [0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => ["pipe", "w"]];
     $process = proc_open($command, $descriptorSpec, $pipes);
     if (!is_resource($process)) {
         throw new Exception('Cannot open command file pointer to `' . $command . '`');
     }
     $processStatus = proc_get_status($process);
     $this->_eventEmitter->emit('start', [$processStatus['pid']]);
     if (null !== $input) {
         fwrite($pipes[0], (string) $input);
     }
     fclose($pipes[0]);
     $stdout = null;
     $stderr = null;
     do {
         $readPipes = [$pipes[1], $pipes[2]];
         $writePipes = [];
         $exceptPipes = [];
         stream_select($readPipes, $writePipes, $exceptPipes, null);
         foreach ($readPipes as $readPipe) {
             $content = fread($readPipe, 4096);
             $streamType = array_search($readPipe, $pipes);
             switch ($streamType) {
                 case 1:
                     $stdout .= $content;
                     $this->_eventEmitter->emit('stdout', [$content]);
                     break;
                 case 2:
                     $stderr .= $content;
                     $this->_eventEmitter->emit('stderr', [$content]);
                     break;
             }
         }
         $processStatus = proc_get_status($process);
     } while ($processStatus['running']);
     fclose($pipes[1]);
     fclose($pipes[2]);
     $exitCode = $processStatus['exitcode'];
     $this->_eventEmitter->emit('stop', [$exitCode]);
     return new Result($this, $exitCode, $stdout, $stderr);
 }
Example #14
0
 /**
  * @param EventEmitter $server
  * @param LoggerInterface $logger
  */
 public function __construct(EventEmitter $server, LoggerInterface $logger)
 {
     $this->server = $server;
     $this->logger = $logger;
     $this->handlers = new \SplObjectStorage();
     $this->membership = new \SplObjectStorage();
     /**
      * @var $membership \SplObjectStorage|WebSocketUriHandlerInterface[]
      */
     $membership = $this->membership;
     $that = $this;
     $server->on("connect", function (WebSocketTransportInterface $client) use($that, $logger, $membership) {
         $handler = $that->matchConnection($client);
         if ($handler) {
             $logger->notice("Added client {$client->getId()} to " . get_class($handler));
             $membership->attach($client, $handler);
             $handler->emit("connect", ["client" => $client]);
             $handler->addConnection($client);
         } else {
             $logger->err(sprintf("Cannot route %s with request uri %s", $client->getId(), $client->getHandshakeRequest()->getUriString()));
         }
     });
     $server->on('disconnect', function (WebSocketTransportInterface $client) use($that, $logger, $membership) {
         if ($membership->contains($client)) {
             $handler = $membership[$client];
             $membership->detach($client);
             $logger->notice("Removed client {$client->getId()} from" . get_class($handler));
             $handler->removeConnection($client);
             $handler->emit("disconnect", ["client" => $client]);
         } else {
             $logger->warn("Client {$client->getId()} not attached to any handler, so cannot remove it!");
         }
     });
     $server->on("message", function (WebSocketTransportInterface $client, WebSocketMessageInterface $message) use($that, $logger, $membership) {
         if ($membership->contains($client)) {
             $handler = $membership[$client];
             $handler->emit("message", compact('client', 'message'));
         } else {
             $logger->warn(sprintf("Client %s not attached to any handler, so cannot forward the message!", $client->getId()));
         }
     });
 }
Example #15
0
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof ClaimRebateCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->member_repo);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     $member = $this->member_repo->findOneBy(["account_id" => $command->getAccountId()]);
     $claim_rebate = new ClaimRebate();
     $claim_rebate->setMember($member);
     $claim_rebate->setMt4Account($command->getMt4Account());
     $claim_rebate->setType($command->getType());
     $this->claim_rebate_repo->save($claim_rebate);
     $data = ["email" => $member->getEmail(), "account_id" => $member->getAccountId(), "fullname" => $member->getFullName(), "type" => $claim_rebate->getType(), "mt4_account" => $claim_rebate->getMt4Account(), "bank_name" => $member->getBankName(), "account_number" => $member->getAccountNumber(), "account_holder" => $member->getAccountHolder(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("claim.rebate.created", [$data]);
     return true;
 }
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof AddInvestorPasswordCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->member_repo);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     $member = $this->member_repo->findOneBy(["account_id" => $command->getAccountId()]);
     $investor_password = new InvestorPassword();
     $investor_password->setInvestorPassword($command->getInvestorPassword());
     $investor_password->setMtAccount($command->getMt4Account());
     $investor_password->setAccountId($member);
     $this->investor_password_repo->save($investor_password);
     $data = ["email" => $member->getEmail(), "account_id" => $member->getAccountId(), "fullname" => $member->getFullName(), "mt4_account" => $investor_password->getMtAccount(), "investor_password" => $investor_password->getInvestorPassword(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("investor.password.created", [$data]);
     return true;
 }
 public function testMuteListener()
 {
     $listenersCalled = 0;
     $listener = function () use(&$listenersCalled) {
         $listenersCalled++;
     };
     $this->emitter->on('foo', $listener);
     $this->emitter->on('foo', function () use(&$listenersCalled) {
         $listenersCalled++;
         return;
     });
     $this->emitter->mute('foo', $listener);
     $this->emitter->emit('foo');
     $this->assertEquals(1, $listenersCalled);
     $this->emitter->unMute('foo', $listener);
     $this->emitter->emit('foo');
     $this->assertEquals(3, $listenersCalled);
 }
 /**
  * @see AbstractDispatcherAdapter::get
  */
 public function get($name)
 {
     return $this->dispatcher->listeners($name);
 }
Example #19
0
 /**
  * Removes all signal handlers
  *
  * @param int|null $signo    The signal number
  */
 public function removeAllListeners($signo = null)
 {
     // prepare a list of signal numbers to deal with
     $signoList = [];
     if (!is_null($signo)) {
         $signoList = [$signo];
     } elseif (is_array($this->listeners)) {
         $signoList = array_keys($this->listeners);
     }
     // call the parent's code
     parent::removeAllListeners($signo);
     // uninstall PCNTL signal handlers
     foreach ($signoList as $realSigno) {
         pcntl_signal($realSigno, SIG_DFL);
     }
 }
 /**
  * Adds an event listener to log data emitted by a stream.
  *
  * @param \Evenement\EventEmitter $emitter
  * @param \Phergie\Irc\ConnectionInterface $connection Connection
  *        corresponding to the stream
  */
 protected function addLogging(EventEmitter $emitter, ConnectionInterface $connection)
 {
     $emitter->on('data', $this->getOutputLogCallback($connection, 'debug'));
     $emitter->on('error', $this->getOutputLogCallback($connection, 'notice'));
 }
 /**
  * Emit broadcasts an event from the message, and if the broker
  * is set on this message, the same event is broadcast on the broker.
  *
  * @param $event
  * @param array $arguments
  * @return void
  */
 public function emit($event, array $arguments = [])
 {
     parent::emit($event, $arguments);
     if ($this->broker) {
         $this->broker->emit($event, $arguments);
     }
 }
 /**
  * Adds an event listener to log data emitted by a stream.
  *
  * @param \Evenement\EventEmitter $emitter
  * @param \Phergie\Irc\ConnectionInterface $connection Connection
  *        corresponding to the stream
  */
 protected function addLogging(EventEmitter $emitter, ConnectionInterface $connection)
 {
     $logger = $this->getLogger();
     $callback = function ($msg) use($logger, $connection) {
         $mask = sprintf('%s!%s@%s', $connection->getNickname(), $connection->getUsername(), $connection->getServerHostname());
         $logger->debug($mask . ' ' . trim($msg));
     };
     $emitter->on('data', $callback);
     $emitter->on('error', $callback);
 }
Example #23
0
 /**
  * Registers a new signal handler
  *
  * @param int      $signo    The signal number
  * @param callable $listener The listener
  */
 public function on($signo, callable $listener)
 {
     pcntl_signal($signo, array($this, 'emit'));
     parent::on($signo, $listener);
 }
Example #24
0
             $test->addTearDownFunction(function () {
                 throw new Error();
             });
             $result = new TestResult(new EventEmitter());
             $test->run($result);
             $expected = "1 run, 1 failed";
             $actual = $result->getSummary();
             assert($expected == $actual, "expected {$expected}, got {$actual}");
         });
         it('should not result in a pass and fail if tear down fails', function () {
             $test = new Test("passing", function () {
             });
             $test->addTearDownFunction(function () {
                 throw new Exception("failure");
             });
             $emitter = new EventEmitter();
             $count = 0;
             $emitter->on('test.passed', function () use(&$count) {
                 $count++;
             });
             $emitter->on('test.failed', function () use(&$count) {
                 $count++;
             });
             $test->run(new TestResult($emitter));
             assert($count == 1, "should not have emitted a pass and fail event");
         });
     });
 });
 describe("->getTitle()", function () {
     it("should return the full text for a spec including parents", function () {
         $root = new Suite("parent", function () {
Example #25
0
 /**
  * @param EventEmitter $dispatcher
  */
 private function injectVisibilityFilter(EventEmitter $dispatcher)
 {
     $listener = function ($base, $challenger, &$skip) {
         $allowed = $this->input->getOption('visibility');
         $skip = $skip || (!$base || !in_array($base->getVisibility(), $allowed)) && (!$challenger || !in_array($challenger->getVisibility(), $allowed));
     };
     $dispatcher->on(MemberCollectionComparator::EVENT_PRE_COMPARE, $listener);
     $dispatcher->on(MethodCollectionComparator::EVENT_PRE_COMPARE, $listener);
     $dispatcher->on(ConstantCollectionComparator::EVENT_PRE_COMPARE, function ($base, $challenger, &$skip) {
         $allowed = $this->input->getOption('visibility');
         $skip = $skip || !in_array('public', $allowed);
     });
 }