Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Utils/AbstractBeanPropertyDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ public function useAlternativeName()
*
* @return null|string
*/
abstract public function getClassName();
abstract public function getClassName(): ?string;

/**
* Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....)
*
* @return string
*/
abstract public function getPhpType(): string;

/**
* Returns the param annotation for this property (useful for constructor).
Expand Down
13 changes: 12 additions & 1 deletion src/Utils/ObjectBeanPropertyDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,22 @@ public function getForeignKey()
*
* @return null|string
*/
public function getClassName()
public function getClassName(): ?string
{
return $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName());
}

/**
* Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....)
*
* @return string
*/
public function getPhpType(): string
{
return $this->getClassName();
}


/**
* Returns the param annotation for this property (useful for constructor).
*
Expand Down
25 changes: 17 additions & 8 deletions src/Utils/ScalarBeanPropertyDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public function getForeignKey()
*/
public function getParamAnnotation()
{
$className = $this->getClassName();
$paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType());
$paramType = $this->getPhpType();

$str = ' * @param %s %s';

Expand All @@ -59,9 +58,20 @@ public function getParamAnnotation()
*
* @return null|string
*/
public function getClassName()
public function getClassName(): ?string
{
return;
return null;
}

/**
* Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....)
*
* @return string
*/
public function getPhpType(): string
{
$type = $this->column->getType();
return TDBMDaoGenerator::dbalTypeToPhpType($type);
}

/**
Expand Down Expand Up @@ -121,8 +131,7 @@ public function isPrimaryKey()
*/
public function getGetterSetterCode()
{
$type = $this->column->getType();
$normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type);
$normalizedType = $this->getPhpType();

$columnGetterName = $this->getGetterName();
$columnSetterName = $this->getSetterName();
Expand Down Expand Up @@ -183,8 +192,7 @@ public function %s(%s%s $%s) : void
*/
public function getJsonSerializeCode()
{
$type = $this->column->getType();
$normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type);
$normalizedType = $this->getPhpType();

if ($normalizedType == '\\DateTimeInterface') {
return ' $array['.var_export($this->namingStrategy->getJsonProperty($this), true).'] = ($this->'.$this->getGetterName().'() === null) ? null : $this->'.$this->getGetterName()."()->format('c');\n";
Expand All @@ -202,4 +210,5 @@ public function getColumnName()
{
return $this->column->getName();
}

}