public function distributeResources($resources, $componentPrefixedKey = 'LogicalResourceId')
 {
     Log::debug(__METHOD__ . ' start');
     $groupedResourceCollection = [];
     foreach ($this->items as $componentKey => $component) {
         foreach ($resources as $resourceKey => $resource) {
             if (Stringy::create($resource[$componentPrefixedKey])->startsWith(studly_case($componentKey), false)) {
                 $groupedResourceCollection[$componentKey][] = $resource;
                 unset($resources[$resourceKey]);
             }
             if ($resource[$componentPrefixedKey] == data_get($resource, 'StackName') or $resource[$componentPrefixedKey] == '') {
                 $groupedResourceCollection['_stack'][] = $resource;
                 unset($resources[$resourceKey]);
             }
         }
     }
     if (count($resources) > 0) {
         $groupedResourceCollection['_ungrouped'] = $resources;
     }
     $groupedResourceCollectionKeys = array_keys($groupedResourceCollection);
     $retval = Collection::make($groupedResourceCollection)->map(function ($resources) {
         return Collection::make($resources);
     })->replaceKeys(function ($k) use($groupedResourceCollectionKeys) {
         return $groupedResourceCollectionKeys[$k];
     });
     Log::debug(__METHOD__ . ' end');
     return $retval;
 }
Ejemplo n.º 2
0
 /**
  * @param string $class_slug Model class name
  * @param mixed|array $parameters Array of parameters to use in where clause
  * @param array $relations Array of relations with parameters as keys.
  *                         Each relation provides key and relation path for QueryBuilder
  * @param string $key Field to be used as a key
  * @return Collection
  */
 protected function getModels($class_slug, $parameters = [], $relations, $key)
 {
     if (!is_array($parameters)) {
         $parameters = ['key' => $parameters];
     }
     $relations_parameters = array_intersect_key($relations, $parameters);
     $model_parameters = array_except($parameters, array_keys($relations_parameters));
     $orm_class = self::getQueryClass($class_slug);
     /** @var Builder $query */
     $query = $orm_class::query();
     foreach ($model_parameters as $parameter => $value) {
         if ($parameter == 'key') {
             $parameter = $key;
         }
         self::where($query, $parameter, $value);
     }
     $query->with(array_map(function ($r) {
         return $r['relation'];
     }, array_values($relations)));
     foreach ($relations_parameters as $parameter => $relation_data) {
         $value = $parameters[$parameter];
         $query->with([$relation_data['relation'] => function ($query) use($key, $value) {
             self::where($query, $key, $value);
         }]);
         $query->whereHas($relation_data['relation'], function ($query) use($key, $value) {
             self::where($query, $key, $value);
         });
     }
     $orm_models = $query->get();
     $models = Collection::make();
     $class = Model::getModelClass($class_slug);
     foreach ($orm_models as $orm_model) {
         $models->push($class::make($orm_model));
     }
     return $models;
 }
 public function setUp()
 {
     parent::setUp();
     $this->cfn_params = ParametersCollection::make(['StackName' => 'test-stack', 'Capabilities' => ['CAPABILITY_IAM']]);
     $this->stack_params = Collection::make([Parameter::make(['id' => 'cloud_credentials', 'sensitive' => true, 'value' => ['access_key' => 'test-key', 'secret_key' => 'xWva3qmvoAgCK0rUcN3gb9FJdLFXhSln1lCbKBl9se8GK9RpbIIcuhM98NGzN18Cv6dvjhL7rwgxYHuj7GDLzOYKTLEjNzExfAJEnZRPKJ94Pk9pgGhs7D9KVLcMYCl4plHsUkckijaXUYLJj2EojVjajIwkjLVkChosefq5RjVkyO08NSIzmsohRKBBTg6tpJys42FVmTNiFJ1a8PMoOgbmmK3xj2J1eEAybWrgcpwuu87YXDaBwbnhLuVWqqUTGf9jHTaaIxzG590fBEwNxOV8']])], $class = null, $key_by = 'id');
 }
Ejemplo n.º 4
0
 /**
  * @param Stack $stack
  * @param Collection $remote_stacks
  * @return Collection
  */
 private function getOutputs(Stack $stack, Collection $remote_stacks = null)
 {
     $remote_stacks = $remote_stacks ? $remote_stacks : Collection::make([$stack]);
     $params = Collection::make();
     foreach ($remote_stacks as $remote_stack) {
         if (!$remote_stack->provisioned) {
             throw new CloudFormerException('Cannot use non-provisioned remote stack ' . $remote_stack->name);
         }
         $cfn_params = new ParametersCollection(['StackName' => $remote_stack->name]);
         $response = $this->cfn($stack)->describeStacks($cfn_params->all());
         foreach (array_get(head($response->get('Stacks')), 'Outputs', []) as $output) {
             $key = snake_case($output['OutputKey']);
             $value = $output['OutputValue'];
             if (starts_with($value, ['[']) && ends_with($value, [']'])) {
                 $value = explode(',', trim($value, '[]'));
             }
             $param = ['id' => $key, 'value' => $value];
             $params->put($key, Parameter::make($param));
         }
     }
     return $params;
 }