property = $property; $this->name = $name; $this->type = $type; $this->defaultValue = $defaultValue; $this->unique = $unique; $this->nullable = $nullable; $this->firstArgument = $firstArgument; $this->secondArgument = $secondArgument; } final public function __toString(): string { return $this->getProperty(); } public function bindProperty(string $propertyName): self { $this->property = $propertyName; return $this; } public function getProperty(): string { if (empty($this->property)) { throw new \LogicException('Property must be set, use bindProperty'); } return $this->property; } final public function getName(): ?string { $property = $this->getProperty(); return $this->name ?: NamingStrategy::toSnakeCase($property); } public function getType(): string { return $this->type; } final public function type(string $type): self { $this->type = $type; return $this; } public function isUnique(): bool { return $this->unique; } public function isNullable(): bool { return $this->nullable; } final public function getFirstArgument(): ?string { return $this->firstArgument; } final public function getSecondArgument(): ?string { return $this->secondArgument; } public function getDefaultValue() { return $this->defaultValue; } public function getDefaultValueToDatabase() { return $this->convertToDatabase($this->getDefaultValue()); } public function getIndex(): ?Index { if ($this->index === null && ($this instanceof JoinColumn || $this->isUnique())) { $this->index = new Index([$this->getName()], $this->isUnique()); } return $this->index; } /** * Converts a value to its corresponding database representation. * * @param mixed $value The value to be converted. * @return mixed The converted value. * @throws \ReflectionException */ final function convertToDatabase($value) { $type = $this->getType(); if (is_subclass_of($type, Type::class)) { $value = TypeFactory::create($type)->convertToDatabase($value); } return $value; } /** * Converts a value to its corresponding PHP representation. * * @param mixed $value The value to be converted. * @return mixed The converted PHP value. * @throws \ReflectionException */ final function convertToPHP($value) { $type = $this->getType(); if (is_subclass_of($type, Type::class)) { $value = TypeFactory::create($type)->convertToPHP($value); } return $value; } }