-
Notifications
You must be signed in to change notification settings - Fork 1
Chapter 2 code #12
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
Draft
Howriq
wants to merge
14
commits into
chapter-1
Choose a base branch
from
chapter-2
base: chapter-1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Chapter 2 code #12
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c198d8a
Changes for chapter 1
Howriq 6a8465e
Merge remote-tracking branch 'origin/chapter-1' into chapter-1
Howriq 715eef1
Code chapter 2
Howriq fe04d0f
Code chapter 2
Howriq b887f5f
Code chapter 2
Howriq 776f323
Code chapter 2
Howriq b5a00a7
Code chapter 2
Howriq d1c5d96
Code chapter 2
Howriq a93cdc8
Code chapter 2
Howriq 8ff4031
Code chapter 2
Howriq 7a22f63
Code chapter 2
Howriq 8761a5f
Code chapter 2
Howriq cd1e8d9
remove local.php
Howriq 4a20431
Merge pull request #20 from Howriq/chapter-2
alexmerlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,8 @@ | ||
| #!/usr/bin/env php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Doctrine\Migrations; | ||
|
|
||
| require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php'; |
This file contains hidden or 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 hidden or 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 | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager; | ||
| use Doctrine\Migrations\Configuration\Migration\ConfigurationArray; | ||
| use Doctrine\Migrations\DependencyFactory; | ||
| use Doctrine\ORM\EntityManager; | ||
|
|
||
| $container = require 'config/container.php'; | ||
|
|
||
| $entityManager = $container->get(EntityManager::class); | ||
| $entityManager->getEventManager(); | ||
|
|
||
| return DependencyFactory::fromEntityManager( | ||
| new ConfigurationArray($container->get('config')['doctrine']['migrations']), | ||
| new ExistingEntityManager($entityManager) | ||
| ); |
This file contains hidden or 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
alexmerlin marked this conversation as resolved.
Show resolved
Hide resolved
|
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
alexmerlin marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,106 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Entity; | ||
|
|
||
| use DateTimeImmutable; | ||
| use Doctrine\ORM\Mapping as ORM; | ||
| use Laminas\Stdlib\ArraySerializableInterface; | ||
| use Ramsey\Uuid\Uuid; | ||
| use Ramsey\Uuid\UuidInterface; | ||
|
|
||
| use function is_array; | ||
| use function method_exists; | ||
| use function ucfirst; | ||
|
|
||
| #[ORM\MappedSuperclass] | ||
| abstract class AbstractEntity implements ArraySerializableInterface | ||
| { | ||
| #[ORM\Column(name: 'created', type: 'datetime_immutable', nullable: false)] | ||
| protected DateTimeImmutable $created; | ||
|
|
||
| #[ORM\Column(name: 'updated', type: 'datetime_immutable', nullable: true)] | ||
| protected ?DateTimeImmutable $updated = null; | ||
|
|
||
| #[ORM\Id] | ||
| #[ORM\Column(name: 'id', type: 'uuid', unique: true, nullable: false)] | ||
| protected UuidInterface $uuid; | ||
|
|
||
| #[ORM\PrePersist] | ||
| public function created(): void | ||
| { | ||
| $this->created = new DateTimeImmutable(); | ||
| } | ||
|
|
||
| #[ORM\PreUpdate] | ||
| public function touch(): void | ||
| { | ||
| $this->updated = new DateTimeImmutable(); | ||
| } | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->uuid = Uuid::uuid7(); | ||
| } | ||
|
|
||
| public function getId(): UuidInterface | ||
| { | ||
| return $this->uuid; | ||
| } | ||
|
|
||
| public function setId(UuidInterface $id): static | ||
| { | ||
| $this->uuid = $id; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<non-empty-string, mixed> $array | ||
| */ | ||
| public function exchangeArray(array $array): void | ||
| { | ||
| foreach ($array as $property => $values) { | ||
| if (is_array($values)) { | ||
| $method = 'add' . ucfirst($property); | ||
| if (! method_exists($this, $method)) { | ||
| continue; | ||
| } | ||
| foreach ($values as $value) { | ||
| $this->$method($value); | ||
| } | ||
| } else { | ||
| $method = 'set' . ucfirst($property); | ||
| if (! method_exists($this, $method)) { | ||
| continue; | ||
| } | ||
| $this->$method($values); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Entity; | ||
|
|
||
| use DateTimeImmutable; | ||
| use Ramsey\Uuid\UuidInterface; | ||
|
|
||
| interface EntityInterface | ||
| { | ||
| public function getId(): UuidInterface; | ||
|
|
||
| public function getCreated(): ?DateTimeImmutable; | ||
|
|
||
| public function getCreatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): string; | ||
|
|
||
| public function getUpdated(): ?DateTimeImmutable; | ||
|
|
||
| public function getUpdatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): ?string; | ||
| } |
This file contains hidden or 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 | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Repository; | ||
|
|
||
| use Doctrine\ORM\EntityRepository; | ||
| use Doctrine\ORM\QueryBuilder; | ||
| use Light\App\Entity\EntityInterface; | ||
|
|
||
| /** | ||
| * @extends EntityRepository<object> | ||
| */ | ||
| class AbstractRepository extends EntityRepository | ||
| { | ||
| public function deleteResource(EntityInterface $resource): void | ||
| { | ||
| $this->getEntityManager()->remove($resource); | ||
| $this->getEntityManager()->flush(); | ||
| } | ||
|
|
||
| public function getQueryBuilder(): QueryBuilder | ||
| { | ||
| return $this->getEntityManager()->createQueryBuilder(); | ||
| } | ||
|
|
||
| public function saveResource(EntityInterface $resource): void | ||
| { | ||
| $this->getEntityManager()->persist($resource); | ||
| $this->getEntityManager()->flush(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.