Example #1
0
 /**
  * @param \ZF\Console\Route $route
  * @param ConsoleWriter $consoleWriter
  * @return Environment
  */
 protected function loadEnvironment(Route $route, ConsoleWriter $consoleWriter)
 {
     $configPath = $route->getMatchedParam('config-file', getcwd() . DIRECTORY_SEPARATOR . 'processing.config.php');
     $additionalConfig = $route->getMatchedParam('config', json_encode([]));
     $additionalConfig = json_decode($additionalConfig, true);
     if (is_null($additionalConfig)) {
         $consoleWriter->writeError("Provided config is not a valid json string");
         $consoleWriter->writeError(json_last_error_msg());
         return self::MESSAGE_PROCESSING_FAILED;
     }
     if (file_exists($configPath)) {
         $config = (include $configPath);
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } elseif (file_exists($configPath . '.dist')) {
         $config = (include $configPath . '.dist');
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } else {
         $consoleWriter->writeInfo('No config file specified.');
         if (empty($additionalConfig)) {
             $consoleWriter->writeInfo('Falling back to default config');
         } else {
             $consoleWriter->writeInfo('Using config from argument');
         }
         return $additionalConfig;
     }
     $config = ArrayUtils::merge($config, $additionalConfig);
     $env = Environment::setUp($config);
     $env->getEventStore()->getActionEventDispatcher()->attachListenerAggregate(new PersistedEventsConsoleWriter($consoleWriter));
     return $env;
 }
 /**
  * @test
  */
 public function it_lazy_attaches_plugin_to_configured_channel_of_each_target()
 {
     $env = Environment::setUp(["processing" => ["channels" => ["multi_target_channel" => ["targets" => ["target1", "target2"], "message_dispatcher" => "mocked_message_handler"]]]]);
     $plugin = new SimpleBusPlugin();
     //Preload channels to check if plugin is added to them
     $env->getWorkflowEngine()->getCommandChannelFor("target1");
     $env->getWorkflowEngine()->getEventChannelFor("target1");
     $env->getWorkflowEngine()->attachPluginToAllChannels($plugin);
     $this->assertEquals(2, $plugin->getAttachCount());
     //Request channels again to check that plugin is not attached twice
     $env->getWorkflowEngine()->getCommandChannelFor("target1");
     $env->getWorkflowEngine()->getEventChannelFor("target1");
     $this->assertEquals(2, $plugin->getAttachCount());
     //Load next channels to check if plugin is attached to them, too
     $env->getWorkflowEngine()->getCommandChannelFor("target2");
     $env->getWorkflowEngine()->getEventChannelFor("target2");
     $this->assertEquals(4, $plugin->getAttachCount());
 }
Example #3
0
 /**
  * @test
  */
 public function it_returns_a_ready_to_use_workflow_processor()
 {
     $env = Environment::setUp();
     $this->assertInstanceOf('Prooph\\Processing\\Processor\\WorkflowProcessor', $env->getWorkflowProcessor());
 }
 /**
  * @param ConfigLocation $configLocation
  * @return \Prooph\Link\Application\Projection\ProcessingConfig
  */
 public static function asProjectionFrom(ConfigLocation $configLocation)
 {
     if (file_exists($configLocation->toString() . DIRECTORY_SEPARATOR . self::$configFileName)) {
         $instance = self::initializeFromConfigLocation($configLocation);
         return new \Prooph\Link\Application\Projection\ProcessingConfig($instance->toArray(), $configLocation, true);
     } else {
         $env = Environment::setUp();
         return new \Prooph\Link\Application\Projection\ProcessingConfig(['processing' => $env->getConfig()->toArray()], $configLocation);
     }
 }
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     return Environment::setUp($serviceLocator);
 }
 /**
  * @test
  */
 public function it_selects_the_target_and_sender_channel_because_target_list_contains_wildcard()
 {
     $targetChannelPlugin = new TargetChannelPlugin();
     $targetAndOriginPlugin = new TargetAndOriginChannelPlugin();
     $targetAndSenderPlugin = new TargetAndSenderChannelPlugin();
     $targetOriginAndSenderPlugin = new TargetOriginAndSenderChannelPlugin();
     $serviceLocator = new ServiceManager();
     $serviceLocator->setService('target_channel_plugin', $targetChannelPlugin);
     $serviceLocator->setService('target_and_origin_channel_plugin', $targetAndOriginPlugin);
     $serviceLocator->setService('target_and_sender_channel_plugin', $targetAndSenderPlugin);
     $serviceLocator->setService('target_origin_and_sender_channel_plugin', $targetOriginAndSenderPlugin);
     $serviceLocator->setService('configuration', ['processing' => ['channels' => ['target_channel' => ['targets' => ['another_target'], 'utils' => ['target_channel_plugin']], 'target_and_origin_channel' => ['targets' => ['another_target'], 'origin' => 'my_origin', 'utils' => ['target_and_origin_channel_plugin']], 'target_and_sender_channel' => ['targets' => ['*'], 'sender' => 'my_sender', 'utils' => ['target_and_sender_channel_plugin']], 'target_origin_and_sender_channel' => ['targets' => ['another_target'], 'origin' => 'my_origin', 'sender' => 'my_sender', 'utils' => ['target_origin_and_sender_channel_plugin']]]]]);
     $env = Environment::setUp($serviceLocator);
     $channel = $env->services()->get('processing.command_bus.my_target___my_origin___my_sender');
     $this->assertInstanceOf(\Prooph\ServiceBus\CommandBus::class, $channel);
     $this->assertFalse($targetAndOriginPlugin->isRegistered());
     $this->assertTrue($targetAndSenderPlugin->isRegistered());
     $this->assertFalse($targetChannelPlugin->isRegistered());
     $this->assertFalse($targetOriginAndSenderPlugin->isRegistered());
 }