protected function initializeProperty(ClassFileDefinition $file, PropertyDefinition $property)
 {
     $fqcn = new FullyQualifiedClassName('SplObjectStorage');
     $arrayCollection = new ObjectValue($fqcn);
     $property->setDefaultValue($arrayCollection);
     $construct = $this->getConstructor($file);
     $construct->addLine(sprintf('$this->%s = %s;', $property->getName()->toLowerCamelCase(), $arrayCollection->getPhpFormatedValue()));
 }
コード例 #2
0
 private function resolveElementType(PropertyDefinition $property)
 {
     $type = $property->getType();
     if ($type instanceof ArrayType && null !== $type->getTypeOf()) {
         return $type->getTypeOf();
     }
     return null;
 }
コード例 #3
0
    private function createRemoveMethod(PropertyDefinition $property)
    {
        $template = '
$key = array_search($%1$s, $this->%2$s, true);
if(false !== $key){
    unset($this->%2$s[ $key ]);
}';
        $name = $property->getName()->singularize();
        $method = $this->createPrototypeRemoveMethod($property);
        $method->addLine(sprintf($template, $name->toLowerCamelCase(), $property->getName()->toLowerCamelCase()));
        return $method;
    }
コード例 #4
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;
 }
コード例 #5
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);
 }
 /**
  * @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;
 }
コード例 #7
0
 /**
  * @param array $configuration
  * @param PropertyDefinition $property
  * @return Cardinality
  */
 protected function getCardinality(array $configuration, PropertyDefinition $property)
 {
     $definition = $property->getSourceConfiguration();
     if (true === array_key_exists('inverse', $definition)) {
         //Get from inversed side
         $inversedConfiguration = $configuration['entities'][$definition['entity']];
         $inversedProperty = $inversedConfiguration['properties'][$definition['inverse']];
         //reverse Cardinality
         $cardinalityString = $inversedProperty['cardinality'];
         $source = substr($cardinalityString, 0, 1);
         $target = substr($cardinalityString, 2, 1);
         return new Cardinality($target . '.' . $source);
     } else {
         return new Cardinality($definition['cardinality']);
     }
 }
コード例 #8
0
 /**
  * @param $entity
  * @param PropertyDefinition $property
  * @param Cardinality $cardinality
  * @return array
  */
 private function generateJoinColumn($entity, PropertyDefinition $property, Cardinality $cardinality)
 {
     $joinColumns = [];
     $definition = $property->getSourceConfiguration();
     $nullable = 0 === substr($cardinality, 2, 1) || true === $definition['nullable'];
     foreach ($this->getPrimaryProperties($this->configuration, $entity) as $primary) {
         $joinColumn = ['name' => '"' . $property->getName()->toLowerSnakeCase() . '_' . $primary->toLowerSnakeCase() . '"'];
         if ('id' !== $primary->toLowerCamelCase()) {
             $joinColumn['referencedColumnName'] = '"' . $primary->toLowerSnakeCase() . '"';
         }
         if (true === $nullable) {
             $joinColumn['nullable'] = 'true';
         }
         if (true === $definition['unique']) {
             $joinColumn['unique'] = 'true';
         }
         $formattedConf = [];
         foreach ($joinColumn as $key => $value) {
             $formattedConf[] = sprintf('%s=%s', $key, $value);
         }
         $joinColumns[] = sprintf('@ORM\\JoinColumn(%s)', implode(', ', $formattedConf));
     }
     return $joinColumns;
 }