protected function createSetMethod(PropertyDefinition $property) { $methodName = new PhpVariableName('set' . $property->getName()->toUpperCamelCase()); $parameter = new ParameterDefinition($property->getType(), $property->getName()); $method = new MethodDefinition($methodName, [$parameter]); $method->setVisibility(Visibility::PUBLIC_VISIBILITY())->addLine(sprintf('$this->%1$s = $%1$s;', $property->getName()->toLowerCamelCase())); return $method; }
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())); }
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; }
/** * @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 $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; }