コード例 #1
0
 private function resolveElementType(PropertyDefinition $property)
 {
     $type = $property->getType();
     if ($type instanceof ArrayType && null !== $type->getTypeOf()) {
         return $type->getTypeOf();
     }
     return null;
 }
コード例 #2
0
 /**
  * @param PropertyDefinition $property
  * @return string[]
  */
 protected function resolvePropertyTypes(PropertyDefinition $property)
 {
     $types = [];
     $type = $property->getType();
     if ($type instanceof ArrayType) {
         $types[] = $this->getPhpDocArrayType($type);
         if ($property->hasDefaultValue() && $property->getDefaultValue() instanceof ArrayType) {
             return $types;
         }
     } else {
         $types[] = $property->getType()->getPhpTypeName();
     }
     if ($property->hasDefaultValue()) {
         $types[] = $property->getDefaultValue()->getPhpTypeName();
     } else {
         $types[] = 'null';
     }
     return array_unique($types);
 }
コード例 #3
0
 /**
  * @param PropertyDefinition $property
  * @return $this
  */
 public function addProperty(PropertyDefinition $property)
 {
     if (method_exists($this, 'addClassNameUse')) {
         foreach ([$property->getDefaultValue(), $property->getType()] as $type) {
             if (true === $type instanceof ObjectType) {
                 /** @var $type ObjectType */
                 $this->addClassNameUse($type->getClassName());
             }
         }
     }
     $key = $property->getName()->toLowerCamelCase();
     $this->properties[$key] = $property;
     return $this;
 }
 /**
  * @param PropertyDefinition $property
  * @return MethodDefinition
  */
 protected function createSetMethod(PropertyDefinition $property)
 {
     $methodName = new PhpVariableName('set' . $property->getName()->toUpperCamelCase());
     $parameter = new ParameterDefinition($property->getType(), $property->getName(), new NullValue());
     $method = new MethodDefinition($methodName, [$parameter]);
     $method->setVisibility(Visibility::PUBLIC_VISIBILITY())->addLine(sprintf('$this->%1$s = $%1$s;', $property->getName()->toLowerCamelCase()));
     return $method;
 }
コード例 #5
0
 private function resolveDoctrineTypeOfProperty(PropertyDefinition $property)
 {
     $map = [ObjectType::class => 'object', ArrayType::class => 'array', BooleanType::class => 'boolean', DateTimeType::class => 'datetime', DateType::class => 'date', FloatType::class => 'float', IntegerType::class => 'integer', JsonArrayType::class => 'json', StringType::class => 'text', TimeType::class => 'time'];
     $type = $property->getType();
     $resolvedType = $map[get_class($type)];
     if ($type instanceof StringType) {
         $definition = $property->getSourceConfiguration();
         if (true === array_key_exists('length', $definition)) {
             $resolvedType = 'string';
         }
     }
     return $resolvedType;
 }