-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CU-8695wmnkj Add more generic entity traits & interfaces
- Loading branch information
1 parent
46c79bb
commit 56698f1
Showing
15 changed files
with
375 additions
and
3 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
/** | ||
* The archive entity must have the __toString method because his string representation is shown on flash message | ||
* | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
interface ArchivableInterface extends \Stringable | ||
{ | ||
public function getArchivedAt(): ?\DateTimeInterface; | ||
|
||
public function setArchivedAt(?\DateTimeInterface $archivedAt): self; | ||
|
||
public function isArchived(): bool; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait ArchivableTrait | ||
{ | ||
/** | ||
* @ORM\Column(name="archived_at", type="datetime", nullable=true) | ||
*/ | ||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] | ||
protected \DateTime|\DateTimeInterface|null $archivedAt = null; | ||
|
||
public function getArchivedAt(): ?\DateTimeInterface | ||
{ | ||
return $this->archivedAt; | ||
} | ||
|
||
public function setArchivedAt(?\DateTimeInterface $archivedAt): self | ||
{ | ||
$this->archivedAt = $archivedAt; | ||
|
||
return $this; | ||
} | ||
|
||
public function isArchived(): bool | ||
{ | ||
return $this->getArchivedAt() != null; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
/** | ||
* Interface to facilitate the unique representation of an entity via its canonical. | ||
* | ||
* Technical documentation: | ||
* - Once implemented on the entity, use its trait together. | ||
* - Add the UniqueEntity attribute to display the error in the form: | ||
* #[UniqueEntity( | ||
* fields: 'canonical', | ||
* errorPath: '%name of the target field where the error will be displayed%', | ||
* message: '%Explicit message that explains on which field the canonical detection applies.%' | ||
* )] | ||
* or if you use annotation | ||
* @UniqueEntity(fields={"canonical"}, errorPath="targetField", message="...") | ||
* - Define the generateCanonical method. Recommendation: use an AsciiSlugger if it must deal with cases and without accents. | ||
* | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
interface CanonicalInterface | ||
{ | ||
public function getCanonical(): ?string; | ||
|
||
public function setCanonical(?string $canonical): static; | ||
|
||
/** | ||
* Generates the canonical from the entity, the content must be defined by the developer integrating the interface. | ||
* Can also be used in fixtures to simplify value init | ||
*/ | ||
public function generateCanonical(): string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
trait CanonicalTrait | ||
{ | ||
/** | ||
* @ORM\Column(type="string", length=500, unique=true, nullable=true) | ||
* @Assert\Length(max=500) | ||
*/ | ||
#[ORM\Column(length: 500, unique: true, nullable: true)] | ||
#[Assert\Length(max: 500)] | ||
protected ?string $canonical = null; | ||
|
||
public function getCanonical(): ?string | ||
{ | ||
return $this->canonical; | ||
} | ||
|
||
public function setCanonical(?string $canonical): static | ||
{ | ||
$this->canonical = $canonical; | ||
|
||
return $this; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
interface CodableInterface | ||
{ | ||
public function getCode(): ?string; | ||
|
||
public function setCode(?string $code): self; | ||
|
||
public function hasCode(): bool; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait CodableTrait | ||
{ | ||
/** | ||
* If the code needs to be mandatory then specify it via an #[Assert\Callback] in the entity | ||
* @ORM\Column(type="string", unique=true, nullable=true) | ||
*/ | ||
#[ORM\Column(unique: true, nullable: true)] | ||
protected ?string $code = null; | ||
|
||
public function getCode(): ?string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(?string $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function hasCode(): bool | ||
{ | ||
return $this->getCode() != null; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
interface EnableInterface | ||
{ | ||
public function isEnabled(): ?bool; | ||
|
||
public function setEnabled(bool $enabled): self; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait EnableTrait | ||
{ | ||
/** | ||
* @ORM\Column(type="boolean", options={"default"=1}) | ||
*/ | ||
#[ORM\Column(options: ["default" => 1])] | ||
protected ?bool $enabled = true; | ||
|
||
public function isEnabled(): ?bool | ||
{ | ||
return $this->enabled; | ||
} | ||
|
||
public function setEnabled(bool $enabled): self | ||
{ | ||
$this->enabled = $enabled; | ||
|
||
return $this; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
interface PositionableInterface | ||
{ | ||
public function getPosition(): ?int; | ||
|
||
public function setPosition(?int $position): self; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
trait PositionableTrait | ||
{ | ||
/** | ||
* @ORM\Column(type="integer", nullable=true) | ||
*/ | ||
#[ORM\Column(nullable: true)] | ||
protected ?int $position = null; | ||
|
||
public function getPosition(): ?int | ||
{ | ||
return $this->position; | ||
} | ||
|
||
public function setPosition(?int $position): self | ||
{ | ||
$this->position = $position; | ||
|
||
return $this; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
/** | ||
* Allows to automatically add search update treatments in managers | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
interface SearchableInterface | ||
{ | ||
public function getSearch(): ?string; | ||
|
||
public function setSearch(?string $search): self; | ||
|
||
/** | ||
* returns the calculated value of the search | ||
* method not provided by the SearchableTrait to be defined | ||
* also used in fixtures to simplify the init of the search value | ||
*/ | ||
public function getComputedSearch(): string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait SearchableTrait | ||
{ | ||
/** | ||
* @ORM\Column(type="string", length=500, nullable=true) | ||
*/ | ||
#[ORM\Column(length: 500, nullable: true)] | ||
protected ?string $search = null; | ||
|
||
public function getSearch(): ?string | ||
{ | ||
return $this->search; | ||
} | ||
|
||
public function setSearch(?string $search): self | ||
{ | ||
$this->search = substr(strtolower($search), 0, 500); | ||
|
||
return $this; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
interface UpdatableInterface | ||
{ | ||
public function getUpdatedAt(): \DateTimeInterface; | ||
|
||
public function setUpdatedAt(\DateTimeInterface $updatedAt, bool $initIntegerFields = true): void; | ||
|
||
public function getUpdatedAtMonth(): ?int; | ||
|
||
public function setUpdatedAtMonth(?int $updatedAtMonth): void; | ||
|
||
public function getUpdatedAtYear(): ?int; | ||
|
||
public function setUpdatedAtYear(?int $updatedAtYear): void; | ||
} |
Oops, something went wrong.