-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bump for doctrine orm 2 -> 3, dbal 3 -> 4 through roave psr container #283
Changes from all commits
5fb5047
db46147
8f7b2ab
227804b
d1ebb75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Api\App\Entity; | ||
|
||
use DateTimeImmutable; | ||
use Doctrine\ORM\Mapping as ORM; | ||
Check warning on line 8 in src/App/src/Entity/TimestampsTrait.php GitHub Actions / Qodana for PHPUndefined class
|
||
|
||
#[ORM\HasLifecycleCallbacks] | ||
Check warning on line 10 in src/App/src/Entity/TimestampsTrait.php GitHub Actions / Qodana for PHPUndefined class
|
||
trait TimestampsTrait | ||
{ | ||
#[ORM\Column(name: "created", type: "datetime_immutable")] | ||
Check warning on line 13 in src/App/src/Entity/TimestampsTrait.php GitHub Actions / Qodana for PHPUndefined class
|
||
protected DateTimeImmutable $created; | ||
|
||
#[ORM\Column(name: "updated", type: "datetime_immutable", nullable: true)] | ||
Check warning on line 16 in src/App/src/Entity/TimestampsTrait.php GitHub Actions / Qodana for PHPUndefined class
|
||
protected ?DateTimeImmutable $updated = null; | ||
|
||
public function getCreated(): ?DateTimeImmutable | ||
{ | ||
return $this->created; | ||
} | ||
|
||
public function getCreatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): string | ||
{ | ||
return $this->created->format($dateFormat); | ||
} | ||
|
||
public function getUpdated(): ?DateTimeImmutable | ||
{ | ||
return $this->updated; | ||
} | ||
|
||
public function getUpdatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): ?string | ||
{ | ||
if ($this->updated instanceof DateTimeImmutable) { | ||
return $this->updated->format($dateFormat); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
#[ORM\PrePersist] | ||
Check warning on line 43 in src/App/src/Entity/TimestampsTrait.php GitHub Actions / Qodana for PHPUndefined class
|
||
public function created(): void | ||
{ | ||
$this->created = new DateTimeImmutable(); | ||
} | ||
|
||
#[ORM\PreUpdate] | ||
Check warning on line 49 in src/App/src/Entity/TimestampsTrait.php GitHub Actions / Qodana for PHPUndefined class
|
||
public function touch(): void | ||
{ | ||
$this->updated = new DateTimeImmutable(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the good:
updated
should get updated when the entity gets updated.the bad:
updated
should staynull
at entity creation.@arhimede correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is not a tragedy if at the creation time, created and updated fields have the samr value
if this simplify the code, we should keep it that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second tought (or so)
We should not use ilogical stuff in database.
So at creation time, should be null the updated field