-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to PHP 8.2, improve platform and schema interface
- Loading branch information
1 parent
06eb060
commit 4c28b42
Showing
5 changed files
with
223 additions
and
223 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,98 @@ | ||
<?php | ||
|
||
namespace AlphaSoft\AsLinkOrm\Mapping; | ||
|
||
use AlphaSoft\AsLinkOrm\Types\Type; | ||
use AlphaSoft\AsLinkOrm\Types\TypeFactory; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS|\Attribute::IS_REPEATABLE)] | ||
class Column | ||
{ | ||
|
||
public function __construct( | ||
private readonly string $property, | ||
private $defaultValue = null, | ||
private readonly ?string $name = null, | ||
private string $type = 'string', | ||
private readonly bool $unique = false, | ||
private readonly bool $nullable = false, | ||
) | ||
{ | ||
} | ||
|
||
final public function __toString(): string | ||
{ | ||
return $this->getProperty(); | ||
} | ||
|
||
public function getProperty(): string | ||
{ | ||
return $this->property; | ||
} | ||
|
||
final public function getName(): ?string | ||
{ | ||
return $this->name ?: $this->getProperty(); | ||
} | ||
|
||
/** | ||
* @return mixed|null | ||
*/ | ||
final public function getDefaultValue() | ||
{ | ||
return $this->defaultValue; | ||
} | ||
|
||
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; | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
} | ||
<?php | ||
|
||
namespace AlphaSoft\AsLinkOrm\Mapping; | ||
|
||
use AlphaSoft\AsLinkOrm\Types\Type; | ||
use AlphaSoft\AsLinkOrm\Types\TypeFactory; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS|\Attribute::IS_REPEATABLE)] | ||
class Column | ||
{ | ||
|
||
public function __construct( | ||
private readonly string $property, | ||
private $defaultValue = null, | ||
private readonly ?string $name = null, | ||
private string $type = 'string', | ||
private readonly bool $unique = false, | ||
private readonly bool $nullable = false, | ||
) | ||
{ | ||
} | ||
|
||
final public function __toString(): string | ||
{ | ||
return $this->getProperty(); | ||
} | ||
|
||
public function getProperty(): string | ||
{ | ||
return $this->property; | ||
} | ||
|
||
final public function getName(): ?string | ||
{ | ||
return $this->name ?: $this->getProperty(); | ||
} | ||
|
||
/** | ||
* @return mixed|null | ||
*/ | ||
final public function getDefaultValue() | ||
{ | ||
return $this->defaultValue; | ||
} | ||
|
||
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; | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<?php | ||
|
||
namespace AlphaSoft\AsLinkOrm\Mapping; | ||
|
||
use AlphaSoft\AsLinkOrm\Types\IntegerType; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class PrimaryKeyColumn extends Column | ||
{ | ||
public function __construct(string $property, $defaultValue = null, string $name = null, string $type = IntegerType::class) | ||
{ | ||
parent::__construct($property, $defaultValue, $name, $type); | ||
} | ||
} | ||
<?php | ||
|
||
namespace AlphaSoft\AsLinkOrm\Mapping; | ||
|
||
use AlphaSoft\AsLinkOrm\Types\IntegerType; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class PrimaryKeyColumn extends Column | ||
{ | ||
public function __construct(string $property, $defaultValue = null, string $name = null, string $type = IntegerType::class) | ||
{ | ||
parent::__construct($property, $defaultValue, $name, $type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
<?php | ||
|
||
namespace Test\AlphaSoft\AsLinkOrm\Model; | ||
|
||
use AlphaSoft\AsLinkOrm\Mapping\Column; | ||
use AlphaSoft\AsLinkOrm\Mapping\Entity; | ||
use AlphaSoft\AsLinkOrm\Mapping\JoinColumn; | ||
use AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn; | ||
use AlphaSoft\AsLinkOrm\Entity\AsEntity; | ||
use Test\AlphaSoft\AsLinkOrm\Repository\PostRepository; | ||
|
||
#[Entity(table: "post", repositoryClass: PostRepository::class)] | ||
#[PrimaryKeyColumn(property: 'id', type: 'int')] | ||
#[Column(property: 'title')] | ||
#[Column(property: 'content')] | ||
#[JoinColumn(property: 'user', name: 'user_id', referencedColumnName: 'id', targetEntity: User::class)] | ||
final class Post extends AsEntity | ||
{ | ||
public function getPrimaryKeyValue(): ?int | ||
{ | ||
return $this->get(self::getPrimaryKeyColumn()); | ||
} | ||
|
||
public function setUser(User $user): self | ||
{ | ||
$this->setRelatedOne('user', $user); | ||
return $this; | ||
} | ||
|
||
public function getUser(): ?User | ||
{ | ||
return $this->getRelatedOne('user'); | ||
} | ||
|
||
public function getUserHasOneMethod(): ?User | ||
{ | ||
return $this->hasOne(User::class, ['id' => $this->get('user_id')]); | ||
} | ||
|
||
// static public function getRepositoryName(): string | ||
// { | ||
// return PostRepository::class; | ||
// } | ||
|
||
// static public function columnsMapping(): array | ||
// { | ||
// return [ | ||
// new PrimaryKeyColumn('id'), | ||
// new Column('title'), | ||
// new Column('content'), | ||
// new JoinColumn('user', 'user_id', 'id',User::class), | ||
// ]; | ||
// } | ||
} | ||
<?php | ||
|
||
namespace Test\AlphaSoft\AsLinkOrm\Model; | ||
|
||
use AlphaSoft\AsLinkOrm\Mapping\Column; | ||
use AlphaSoft\AsLinkOrm\Mapping\Entity; | ||
use AlphaSoft\AsLinkOrm\Mapping\JoinColumn; | ||
use AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn; | ||
use AlphaSoft\AsLinkOrm\Entity\AsEntity; | ||
use Test\AlphaSoft\AsLinkOrm\Repository\PostRepository; | ||
|
||
#[Entity(table: "post", repositoryClass: PostRepository::class)] | ||
#[PrimaryKeyColumn(property: 'id', type: 'int')] | ||
#[Column(property: 'title')] | ||
#[Column(property: 'content')] | ||
#[JoinColumn(property: 'user', name: 'user_id', referencedColumnName: 'id', targetEntity: User::class)] | ||
final class Post extends AsEntity | ||
{ | ||
public function getPrimaryKeyValue(): ?int | ||
{ | ||
return $this->get(self::getPrimaryKeyColumn()); | ||
} | ||
|
||
public function setUser(User $user): self | ||
{ | ||
$this->setRelatedOne('user', $user); | ||
return $this; | ||
} | ||
|
||
public function getUser(): ?User | ||
{ | ||
return $this->getRelatedOne('user'); | ||
} | ||
|
||
public function getUserHasOneMethod(): ?User | ||
{ | ||
return $this->hasOne(User::class, ['id' => $this->get('user_id')]); | ||
} | ||
|
||
// static public function getRepositoryName(): string | ||
// { | ||
// return PostRepository::class; | ||
// } | ||
|
||
// static public function columnsMapping(): array | ||
// { | ||
// return [ | ||
// new PrimaryKeyColumn('id'), | ||
// new Column('title'), | ||
// new Column('content'), | ||
// new JoinColumn('user', 'user_id', 'id',User::class), | ||
// ]; | ||
// } | ||
} |
Oops, something went wrong.