Beispiel #1
0
 /**
  * Asserts that item type is collection defined type
  *
  * @param string $instanceName
  * @param string|int|null $index
  * @return void
  * @throws \InvalidArgumentException
  */
 private function assertValidTypeLazy($instanceName, $index = null)
 {
     $realType = $this->configInterface->getInstanceType($this->configInterface->getPreference($instanceName));
     if (!in_array($this->type, $this->classReaderInterface->getParents($realType), true)) {
         $this->throwTypeException($realType, $index);
     }
 }
Beispiel #2
0
 /**
  * Asserts that item type is collection defined type
  *
  * @param string $instanceName
  * @param string|int|null $index
  * @return void
  * @throws \InvalidArgumentException
  */
 private function assertValidTypeLazy($instanceName, $index = null)
 {
     $realType = $this->configInterface->getInstanceType($this->configInterface->getPreference($instanceName));
     if (!in_array($this->type, array_unique(array_merge(class_parents($realType), class_implements($realType))), true)) {
         $this->throwTypeException($realType, $index);
     }
 }
Beispiel #3
0
 /**
  * Create instance with call time arguments
  *
  * @param string $requestedType
  * @param array $arguments
  * @return object
  * @throws \Exception
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function create($requestedType, array $arguments = [])
 {
     $args = $this->config->getArguments($requestedType);
     $type = $this->config->getInstanceType($requestedType);
     if (!$args) {
         return new $type();
     }
     foreach ($args as $key => &$argument) {
         if (isset($arguments[$key])) {
             $argument = $arguments[$key];
         } elseif (isset($argument['_i_'])) {
             $argument = $this->get($argument['_i_']);
         } elseif (isset($argument['_ins_'])) {
             $argument = $this->create($argument['_ins_']);
         } elseif (isset($argument['_v_'])) {
             $argument = $argument['_v_'];
         } elseif (isset($argument['_vac_'])) {
             $argument = $argument['_vac_'];
             $this->parseArray($argument);
         } elseif (isset($argument['_vn_'])) {
             $argument = null;
         } elseif (isset($argument['_a_'])) {
             if (isset($this->globalArguments[$argument['_a_']])) {
                 $argument = $this->globalArguments[$argument['_a_']];
             } else {
                 $argument = $argument['_d_'];
             }
         }
     }
     $args = array_values($args);
     return $this->createObject($type, $args);
 }