/**
  * Convert array to collection reference
  *
  * @param array $array
  * @return CollectionReference
  * @throws ReferenceNotImplementsException
  * @throws \InvalidArgumentException
  */
 public static function convertArrayToCollection(array $array)
 {
     $collection = new CollectionReference();
     foreach ($array as $key => $value) {
         if ($value instanceof CollectionItem) {
             $collection->addItem($value);
         } else {
             // Add item to collection
             $collection->addItem(new CollectionItem(self::convertValueToReference($key), self::convertValueToReference($value)));
         }
     }
     return $collection;
 }
 public function testConstructor()
 {
     $collection1 = new CollectionReference([CollectionItem::create('key1', 'value')]);
     static::assertCount(1, $collection1->getCollection());
     static::assertInstanceOf(StringReference::class, $collection1->getCollection()[0]->getKey());
 }
 /**
  * Resolve collection type
  *
  * @param array $data
  * @return CollectionReference
  * @throws \samsonframework\container\definition\builder\exception\ReferenceNotImplementsException
  * @throws ReferenceNotImplementsException
  * @throws \InvalidArgumentException
  */
 protected function resolveCollection(array $data) : CollectionReference
 {
     $collection = new CollectionReference();
     if (array_key_exists('item', $data)) {
         /** @var array $itemCollection */
         $itemCollection = array_key_exists('key', $data['item']) && array_key_exists('value', $data['item']) ? [$data['item']] : $data['item'];
         /** @var array $item */
         foreach ($itemCollection as $item) {
             $collection->addItem(new CollectionItem($this->resolveDependency($item['key']), $this->resolveDependency($item['value'])));
         }
     }
     return $collection;
 }
 /**
  * Set dependency value by reflection
  *
  * @param ParameterDefinition $parameterDefinition
  * @param \ReflectionParameter $reflectionParameter
  * @throws \InvalidArgumentException
  * @throws ReferenceNotImplementsException
  */
 public function setDependencyByReflection(ParameterDefinition $parameterDefinition, \ReflectionParameter $reflectionParameter)
 {
     // If default value available
     if ($reflectionParameter->isDefaultValueAvailable()) {
         // There is a constant
         if ($reflectionParameter->isDefaultValueConstant()) {
             $parameterDefinition->setDependency(new ConstantReference($reflectionParameter->getDefaultValueConstantName()));
         } else {
             // There is some php types
             $parameterDefinition->setDependency(CollectionReference::convertValueToReference($reflectionParameter->getDefaultValue()));
         }
         // There is class dependency
     } elseif ($this->checkIfTypeHingIsClass($parameterDefinition)) {
         $class = (string) $parameterDefinition->getTypeHint();
         $parameterDefinition->setDependency(new ClassReference($class));
     }
 }
 /**
  * Create collection item from php type
  *
  * @param $key
  * @param $value
  * @return CollectionItem
  * @throws ReferenceNotImplementsException
  * @throws \InvalidArgumentException
  */
 public static function create($key, $value)
 {
     return new CollectionItem(CollectionReference::convertValueToReference($key), CollectionReference::convertValueToReference($value));
 }