コード例 #1
0
 /**
  * AbstractManagerTest constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->eventDispatcher = new EventDispatcher();
     // Configure a null logger to suppress unwanted output
     $this->logger = new Logger('TestLogger');
     $this->logger->setHandlers([new NullHandler()]);
     // Configure a single test instance
     $this->configuration = ConfigurationParser::parseConfiguration(new ArrayReader($this->getBaseConfiguration()));
 }
コード例 #2
0
 public function testParser()
 {
     $rawConfiguration = $this->getBaseConfiguration();
     // Configure two instances
     $rawConfiguration['instances'] = ['example.com' => ['address' => 'example.com', 'port' => 9981], 'foo.example.com' => ['address' => 'foo.example.com', 'port' => 9981]];
     $configuration = Parser::parseConfiguration(new ArrayReader($rawConfiguration));
     $this->assertEquals($rawConfiguration['database_path'], $configuration->getDatabasePath());
     $this->assertEquals($rawConfiguration['log_path'], $configuration->getLogPath());
     $this->assertEquals($rawConfiguration['access_token'], $configuration->getAccessToken());
     $this->assertCount(2, $configuration->getInstances());
     $this->assertEquals('example.com', $configuration->getInstanceByName('example.com')->getName());
     $this->assertEquals('foo.example.com', $configuration->getInstanceByName('foo.example.com')->getName());
     $this->assertEquals($rawConfiguration['update_interval'], $configuration->getUpdateInterval());
     $this->assertEquals($rawConfiguration['listen_address'], $configuration->getListenAddress());
     $this->assertEquals($rawConfiguration['listen_port'], $configuration->getListenPort());
     $this->assertEquals($rawConfiguration['http_listen_port'], $configuration->getHttpListenPort());
     $this->assertEquals($rawConfiguration['http_username'], $configuration->getHttpUsername());
     $this->assertEquals($rawConfiguration['http_password'], $configuration->getHttpPassword());
     $this->assertEquals([], $configuration->getInstanceByName('example.com')->getIgnoredUsers());
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Parse the configuration
     $configFile = $input->getArgument('configFile');
     $configuration = ConfigurationParser::parseConfiguration(new YamlReader($configFile));
     // Configure Propel and the logger
     $logger = $this->configureLogger($output, $configuration);
     $this->configurePropel($configuration, $logger);
     $injector = new Injector();
     // Configure shared instances
     $eventLoop = EventLoopFactory::create();
     $eventDispatcher = new EventDispatcher();
     $aliases = [':logger' => $logger, ':loop' => $eventLoop];
     $injector->share($configuration)->share($logger)->share($eventDispatcher)->share($eventLoop);
     // Create managers
     $statusManager = $injector->make('Jalle19\\StatusManager\\Manager\\StatusManager', $aliases);
     $instanceStateManager = $injector->make('Jalle19\\StatusManager\\Manager\\InstanceStateManager', $aliases);
     $webSocketManager = $injector->make('Jalle19\\StatusManager\\Manager\\WebSocketManager', $aliases);
     $persistenceManager = $injector->make('Jalle19\\StatusManager\\Manager\\PersistenceManager', $aliases);
     $statisticsManager = $injector->make('Jalle19\\StatusManager\\Manager\\StatisticsManager', $aliases);
     $inputErrorManager = $injector->make('Jalle19\\StatusManager\\Manager\\InputErrorManager', $aliases);
     $httpRequestManager = $injector->make('Jalle19\\StatusManager\\Manager\\HttpRequestManager', $aliases);
     // Wire the event dispatcher
     $webSocketManager->registerMessageHandler($statisticsManager);
     $webSocketManager->registerMessageHandler($webSocketManager);
     $eventDispatcher->addSubscriber($statusManager);
     $eventDispatcher->addSubscriber($instanceStateManager);
     $eventDispatcher->addSubscriber($webSocketManager);
     $eventDispatcher->addSubscriber($persistenceManager);
     $eventDispatcher->addSubscriber($inputErrorManager);
     $eventDispatcher->addSubscriber($httpRequestManager);
     // Configure the event loop and start the application
     $eventLoop->addPeriodicTimer($configuration->getUpdateInterval(), function () use($eventDispatcher) {
         // Emit an event on each tick
         $eventDispatcher->dispatch(Events::MAIN_LOOP_TICK);
     });
     $eventDispatcher->dispatch(Events::MAIN_LOOP_STARTING);
     $eventLoop->run();
 }