Skip to content

Commit a93cdc8

Browse files
committed
Code chapter 2
Signed-off-by: Howriq <[email protected]>
1 parent d1c5d96 commit a93cdc8

File tree

8 files changed

+27
-59
lines changed

8 files changed

+27
-59
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# tutorial-101
2+
Book tutorial starting from Dotkernel Light: Level 101 beginner

phpcs.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@
1919
<file>test</file>
2020

2121
<!-- Include all rules from the Laminas Coding Standard -->
22-
<rule ref="LaminasCodingStandard" >
23-
<exclude-pattern>src/Migrations/*</exclude-pattern>
24-
</rule>
22+
<rule ref="LaminasCodingStandard" />
2523
</ruleset>

src/App/src/ConfigProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
1111
use Dot\Cache\Adapter\ArrayAdapter;
1212
use Dot\Cache\Adapter\FilesystemAdapter;
13+
use Light\App\DBAL\Types\UuidType;
1314
use Light\App\Factory\GetIndexViewHandlerFactory;
1415
use Light\App\Handler\GetIndexViewHandler;
15-
use Light\App\Types\UuidType;
1616
use Mezzio\Application;
1717
use Roave\PsrContainerDoctrine\EntityManagerFactory;
1818
use Symfony\Component\Cache\Adapter\AdapterInterface;
@@ -175,7 +175,7 @@ private function getDoctrineConfig(): array
175175
],
176176
// Modify this line based on where you would like to have you migrations
177177
'migrations_paths' => [
178-
'Migrations' => 'src/Migrations',
178+
'Migrations' => 'src/App/src/Migration',
179179
],
180180
'all_or_nothing' => true,
181181
'check_database_platform' => true,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Light\App\Types;
5+
namespace Light\App\DBAL\Types;
66

77
use Doctrine\DBAL\Platforms\AbstractPlatform;
88

src/App/src/Entity/AbstractEntity.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,29 @@
1717
#[ORM\MappedSuperclass]
1818
abstract class AbstractEntity implements ArraySerializableInterface
1919
{
20+
#[ORM\Id]
21+
#[ORM\Column(name: 'id', type: 'uuid', unique: true, nullable: false)]
22+
protected UuidInterface $id;
23+
2024
#[ORM\Column(name: 'created', type: 'datetime_immutable', nullable: false)]
2125
protected DateTimeImmutable $created;
2226

2327
#[ORM\Column(name: 'updated', type: 'datetime_immutable', nullable: true)]
2428
protected ?DateTimeImmutable $updated = null;
2529

26-
#[ORM\Id]
27-
#[ORM\Column(name: 'id', type: 'uuid', unique: true, nullable: false)]
28-
protected UuidInterface $uuid;
29-
30-
#[ORM\PrePersist]
31-
public function created(): void
32-
{
33-
$this->created = new DateTimeImmutable();
34-
}
35-
36-
#[ORM\PreUpdate]
37-
public function touch(): void
38-
{
39-
$this->updated = new DateTimeImmutable();
40-
}
41-
4230
public function __construct()
4331
{
44-
$this->uuid = Uuid::uuid7();
32+
$this->id = Uuid::uuid7();
4533
}
4634

4735
public function getId(): UuidInterface
4836
{
49-
return $this->uuid;
37+
return $this->id;
5038
}
5139

5240
public function setId(UuidInterface $id): static
5341
{
54-
$this->uuid = $id;
42+
$this->id = $id;
5543

5644
return $this;
5745
}
@@ -80,6 +68,18 @@ public function getUpdatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): ?string
8068
return null;
8169
}
8270

71+
#[ORM\PrePersist]
72+
public function created(): void
73+
{
74+
$this->created = new DateTimeImmutable();
75+
}
76+
77+
#[ORM\PreUpdate]
78+
public function touch(): void
79+
{
80+
$this->updated = new DateTimeImmutable();
81+
}
82+
8383
/**
8484
* @param array<non-empty-string, mixed> $array
8585
*/

src/App/src/Resolver/EntityListenerResolver.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Book/src/Entity/Book.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class Book extends AbstractEntity
1919
#[ORM\Column(name: 'author', type: 'string', length: 500, nullable: true)]
2020
private ?string $author = null;
2121

22-
public function __construct()
23-
{
24-
parent::__construct();
25-
}
26-
2722
public function getTitle(): ?string
2823
{
2924
return $this->title;
@@ -46,8 +41,8 @@ public function setAuthor(string $author): void
4641

4742
/**
4843
* @return array{
49-
* title:string|null,
50-
* author:string|null
44+
* title: string|null,
45+
* author: string|null
5146
* }
5247
*/
5348
public function getArrayCopy(): array

0 commit comments

Comments
 (0)