Пример #1
0
 /**
  * @param string $propertyName
  * @param Collection $annotations
  */
 private function setPropertyService($propertyName, Collection $annotations)
 {
     if ($annotations->has(Service::PROPERTY_ANNOTATION)) {
         $annProperty = $annotations->get(Service::PROPERTY_ANNOTATION);
         if (!is_null($serviceName)) {
             $this->{$propertyName} = $this->getDI()->get($serviceName);
         } else {
             Logger::getInstance()->warning("Annotation Inject in Controller required attribute service");
         }
     }
 }
Пример #2
0
 /**
  * @param string $attribute
  * @param mixed $value
  * @param Annotations $annotations
  * @param Transform|null $transform
  * @return mixed
  * @throws MustBeSimpleException
  * @throws MustBeSequenceException
  * @throws MustBeObjectException
  */
 protected function buildValueToMap($attribute, $value, Annotations $annotations, Transform $transform = null)
 {
     $valueToMap = $value;
     if ($annotations->has('mapper')) {
         /** @var Annotation $annotation */
         $annotation = $annotations->get('mapper');
         $annotationClass = $annotation->getArgument('class');
         $annotationIsArray = $annotation->getArgument('isArray');
         $transforms = $transform ? $transform->getTransforms() : null;
         $skipAttributes = $this->getSkipAttributesByParent($attribute);
         if ($this->isObject($value)) {
             if ($annotationIsArray) {
                 if ($this->hasValidation()) {
                     throw new MustBeSequenceException($attribute, $this->getOutputClass());
                 } else {
                     $valueToMap = null;
                 }
             } else {
                 /** @var object|array $value */
                 /** @var Mapper $mapper */
                 $mapper = new static($value, $annotationClass);
                 $valueToMap = $mapper->setTransforms($transforms)->setValidation($this->hasValidation())->setSkipAttributes($skipAttributes)->map();
             }
         } else {
             if ($annotationIsArray) {
                 $validation = $this->hasValidation();
                 $valueToMap = array_map(function ($value) use($annotationClass, $transforms, $validation, $skipAttributes) {
                     /** @var object|array $value */
                     /** @var Mapper $mapper */
                     $mapper = new static($value, $annotationClass);
                     return $mapper->setTransforms($transforms)->setValidation($validation)->setSkipAttributes($skipAttributes)->map();
                 }, $value);
             } elseif ($this->hasValidation()) {
                 throw new MustBeObjectException($attribute, $this->getOutputClass());
             } else {
                 $valueToMap = null;
             }
         }
     } elseif ($this->isStructure($value)) {
         if ($this->hasValidation()) {
             throw new MustBeSimpleException($attribute, $this->getOutputClass());
         } else {
             $valueToMap = null;
         }
     }
     return $valueToMap;
 }