/**
  * @test
  * @dataProvider provideForMixedTest
  */
 public function is_default_mixed_returned_when_path_not_exists($value)
 {
     $arrayReader = new ArrayReader(array('hash' => array('with' => array('nested' => $value))));
     $this->assertSame(null, $arrayReader->mixedValue('hash.with.unknown', null));
 }
 /**
  * @return array
  */
 public function getConnectors()
 {
     return $this->config->arrayValue('processing.connectors');
 }
 /**
  * If a limit is present in a task metadata and this limit is greater than zero then the client wants the system
  * to process a source collection in chunks.
  *
  * @return bool
  */
 public function shouldCollectionBeSplitIntoChunks()
 {
     return $this->metadata->integerValue(MessageMetadata::LIMIT) > 0;
 }
 /**
  * @param array $result
  */
 public function fillThroughElasticsearchResponse(array $result)
 {
     $arrayReader = new ArrayReader($result);
     $this->isNew = false;
     $this->id = $arrayReader->stringValue('_id');
     $this->version = $arrayReader->mixedValue('_version', null);
     $class = get_class($this);
     $reflection = new \ReflectionClass($class);
     $properties = $reflection->getProperties();
     foreach ($properties as $property) {
         if ($property->getName() !== 'id') {
             $reader = new Reader($class, $property->getName(), 'property');
             $isBodyParameter = $reader->getParameter('isBodyParameter');
             if ($isBodyParameter === true) {
                 $this->{$property->getName()} = $arrayReader->mixedValue('_source.' . $property->getName());
             }
         }
     }
 }
Example #5
0
 /**
  * @param null|array|ServiceManager $configurationOrServices
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return \Prooph\Processing\Environment\Environment
  */
 public static function setUp($configurationOrServices = null)
 {
     $env = null;
     //If neither a config array nor a ServiceManager is given, we initialize the variable with an empty array
     //Later in the set up the default config is merged with this empty array
     if (is_null($configurationOrServices)) {
         $configurationOrServices = [];
     }
     //Initialize the Environment
     if ($configurationOrServices instanceof ServiceManager) {
         //We assume that when the workflow processor service definition is missing
         //then the other services related to the workflow environment are also missing
         if (!$configurationOrServices->has(Definition::SERVICE_WORKFLOW_PROCESSOR)) {
             $servicesConfig = new Config(self::$defaultServicesConfig);
             $servicesConfig->configureServiceManager($configurationOrServices);
         }
         $env = new self(Zf2ServiceManagerProxy::proxy($configurationOrServices));
         //Check if the provided ServiceManager already has a configuration service available
         //so we make sure that we won't override it later but just merge it with the default environment config
         if ($env->services()->has('configuration')) {
             $configurationOrServices = $env->services()->get('configuration');
         } else {
             $configurationOrServices = [];
         }
     } elseif (is_array($configurationOrServices)) {
         //No external ServiceManager given, so we set up a new one
         $servicesConfig = [];
         if (isset($configurationOrServices['services'])) {
             $servicesConfig = $configurationOrServices['services'];
             unset($configurationOrServices['services']);
         }
         $servicesConfig = new Config(ArrayUtils::merge(self::$defaultServicesConfig, $servicesConfig));
         $env = new self(Zf2ServiceManagerProxy::proxy(new ServiceManager($servicesConfig)));
     }
     //This should never happen, but if for whatever reason a wrong $configurationOrServices was passed to the set up
     //we stop the process here
     if (is_null($env)) {
         throw new \InvalidArgumentException("Processing set up requires either a config array or a ready to use Zend\\ServiceManager");
     }
     //We proceed with merging and preparing the environment configuration
     $envConfig = ArrayUtils::merge(self::$defaultEnvConfig, $configurationOrServices);
     //The environment node name is used as target for the local channel, the config needs to be adapted accordingly.
     $envConfigReader = new ArrayReader($envConfig);
     $nodeName = $envConfigReader->stringValue('processing.node_name', Definition::DEFAULT_NODE_NAME);
     $localChannelTargets = $envConfigReader->arrayValue('processing.channels.local.targets');
     if (!in_array($nodeName, $localChannelTargets)) {
         $envConfig = ArrayUtils::merge($envConfig, ['processing' => ['channels' => ['local' => ['targets' => [$nodeName]]]]]);
     }
     $env->services()->set('configuration', $envConfig, true);
     if (!$env->services()->has('config')) {
         $env->services()->setAlias('config', 'configuration');
     }
     $env->services()->set(Definition::SERVICE_ENVIRONMENT, $env, true);
     //The node name is used as message bus target to address the workflow processor of the current environment
     //We alias the workflow processor service with the node name to ensure that the target can be resolved
     $env->services()->setAlias($nodeName, Definition::SERVICE_WORKFLOW_PROCESSOR);
     //The environment component ships with an own workflow engine implementation that uses the ServiceManager
     //to resolve the required message buses for the various targets
     $env->workflowEngine = new ServicesAwareWorkflowEngine($env->services());
     //Add an initializer which injects the local processor message buses whenever a workflow message handler
     //is requested from the ServiceManager
     $env->services()->addInitializer(new WorkflowProcessorBusesProvider());
     //After the set up routine is finished the plugin mechanism can be triggered
     foreach ($env->getConfig()->arrayValue('plugins') as $plugin) {
         if (!$plugin instanceof Plugin && !is_string($plugin)) {
             throw new \RuntimeException(sprintf("Invalid plugin detected: %s. Plugins should be instance of Prooph\\Processing\\Environment\\Plugin or a ServiceManager alias that resolves to a plugin", is_object($plugin) ? get_class($plugin) : gettype($plugin)));
         }
         if (is_string($plugin)) {
             $plugin = $env->services->get($plugin);
             if (!$plugin instanceof Plugin) {
                 throw new \RuntimeException(sprintf("Resolved plugin for alias %s does not implement Prooph\\Processing\\Environment\\Plugin"));
             }
         }
         $env->register($plugin);
     }
     return $env;
 }
Example #6
0
 /**
  * @test
  */
 public function is_escaped_dot_ignored_in_path_detection()
 {
     $arrayReader = new ArrayReader(array('hash' => array('with.dot.key' => array('nested' => 'value'))));
     $this->assertSame('value', $arrayReader->stringValue('hash.with\\.dot\\.key.nested', 'default'));
 }