Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified bin/clear-config-cache.php
100644 → 100755
Empty file.
Empty file modified bin/composer-post-install-script.php
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions bin/doctrine
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;

require_once 'vendor/autoload.php';

$container = require 'config/container.php';

$entityManager = $container->get(EntityManager::class);
$entityManager->getEventManager();

ConsoleRunner::run(new SingleManagerProvider($entityManager));
8 changes: 8 additions & 0 deletions bin/doctrine-migrations
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';
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@
"laminas/laminas-config-aggregator": "^1.17.0",
"mezzio/mezzio": "^3.24.0",
"mezzio/mezzio-fastroute": "^3.13.0",
"mezzio/mezzio-twigrenderer": "^2.17.0"
},
"mezzio/mezzio-twigrenderer": "^2.17.0",
"ramsey/uuid": "^4.5.0",
"ramsey/uuid-doctrine": "^2.1.0",
"roave/psr-container-doctrine": "^5.2.2"
} ,
"require-dev": {
"filp/whoops": "^2.17.0",
"laminas/laminas-coding-standard": "^3.0.1",
"laminas/laminas-development-mode": "^3.13.0",
"phpstan/phpstan": "^2.1.2",
"phpstan/phpstan-phpunit": "^2.0.4",
"phpstan/phpstan-doctrine": "^2.0.3",
"phpunit/phpunit": "^10.5.45",
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^7.2.3",
Expand All @@ -48,7 +52,8 @@
"autoload": {
"psr-4": {
"Light\\App\\": "src/App/src/",
"Light\\Page\\": "src/Page/src/"
"Light\\Page\\": "src/Page/src/",
"Light\\Book\\": "src/Book/src/"
}
},
"autoload-dev": {
Expand Down
18 changes: 18 additions & 0 deletions config/cli-config.php
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)
);
1 change: 1 addition & 0 deletions config/config.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

// Default App module config
\Light\App\ConfigProvider::class,
\Light\Book\ConfigProvider::class,
\Light\Page\ConfigProvider::class,

// Load application config in a pre-defined order in such a way that local settings
Expand Down
2 changes: 0 additions & 2 deletions data/cache/.gitignore

This file was deleted.

78 changes: 77 additions & 1 deletion src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

namespace Light\App;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Dot\Cache\Adapter\ArrayAdapter;
use Dot\Cache\Adapter\FilesystemAdapter;
use Light\App\Factory\GetIndexViewHandlerFactory;
use Light\App\Handler\GetIndexViewHandler;
use Mezzio\Application;
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType;
use Ramsey\Uuid\Doctrine\UuidBinaryType;
use Ramsey\Uuid\Doctrine\UuidType;
use Roave\PsrContainerDoctrine\EntityManagerFactory;

use function getcwd;

class ConfigProvider
{
Expand All @@ -20,6 +31,7 @@
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
'templates' => $this->getTemplates(),
];
}
Expand All @@ -32,14 +44,19 @@
*/
public function getDependencies(): array
{
return [

Check failure on line 47 in src/App/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Method Light\App\ConfigProvider::getDependencies() should return array{delegators: array<class-string, array<class-string>>, factories: array<class-string, class-string>} but returns array{delegators: array{Mezzio\Application: array{'Light\\App\\RoutesDelegator'}}, factories: array{'doctrine.entity_manager.orm_default': 'Roave\\PsrContainerDoctrine\\EntityManagerFactory', Light\App\Handler\GetIndexViewHandler: 'Light\\App\\Factory\\GetIndexViewHandlerFactory'}, aliases: array{Doctrine\ORM\EntityManager: 'doctrine.entity…', Doctrine\ORM\EntityManagerInterface: 'doctrine.entity…'}}.
'delegators' => [
Application::class => [
RoutesDelegator::class,
],
],
'factories' => [
GetIndexViewHandler::class => GetIndexViewHandlerFactory::class,
'doctrine.entity_manager.orm_default' => EntityManagerFactory::class,
GetIndexViewHandler::class => GetIndexViewHandlerFactory::class,
],
'aliases' => [
EntityManager::class => 'doctrine.entity_manager.orm_default',
EntityManagerInterface::class => 'doctrine.entity_manager.orm_default',
],
];
}
Expand All @@ -65,4 +82,63 @@
],
];
}

private function getDoctrineConfig(): array

Check failure on line 86 in src/App/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Method Light\App\ConfigProvider::getDoctrineConfig() return type has no value type specified in iterable type array.
{
return [
'cache' => [
'array' => [
'class' => ArrayAdapter::class,

Check failure on line 91 in src/App/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Dot\Cache\Adapter\ArrayAdapter not found.
],
'filesystem' => [
'class' => FilesystemAdapter::class,

Check failure on line 94 in src/App/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Dot\Cache\Adapter\FilesystemAdapter not found.
'directory' => getcwd() . '/data/cache',
'namespace' => 'doctrine',
],
],
'configuration' => [
'orm_default' => [
'result_cache' => 'filesystem',
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
'hydration_cache' => 'array',
'typed_field_mapper' => null,
'second_level_cache' => [
'enabled' => true,
'default_lifetime' => 3600,
'default_lock_lifetime' => 60,
'file_lock_region_directory' => '',
'regions' => [],
],
],
],
'connection' => [
'orm_default' => [
'doctrine_mapping_types' => [
UuidBinaryType::NAME => 'binary',
UuidBinaryOrderedTimeType::NAME => 'binary',
],
],
],
'driver' => [
// The default metadata driver aggregates all other drivers into a single one.
// Override `orm_default` only if you know what you're doing.
'orm_default' => [
'class' => MappingDriverChain::class,
],
],
'migrations' => [
'migrations_paths' => [
'Migrations' => 'src/Migrations',
],
'all_or_nothing' => true,
'check_database_platform' => true,
],
'types' => [
UuidType::NAME => UuidType::class,
UuidBinaryType::NAME => UuidBinaryType::class,
UuidBinaryOrderedTimeType::NAME => UuidBinaryOrderedTimeType::class,
],
];
}
}
27 changes: 27 additions & 0 deletions src/App/src/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Light\App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\MappedSuperclass]
abstract class AbstractEntity
{
#[ORM\Id]
#[ORM\Column(name: 'uuid', type: 'uuid_binary', unique: true)]
protected UuidInterface $uuid;

public function __construct()
{
$this->uuid = Uuid::uuid7();
}

public function getUuid(): UuidInterface
{
return $this->uuid;
}
}
53 changes: 53 additions & 0 deletions src/App/src/Entity/TimestampsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Light\App\Entity;

use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;

trait TimestampsTrait
{
#[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;

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]
public function created(): void
{
$this->created = new DateTimeImmutable();
}

#[ORM\PreUpdate]
public function touch(): void
{
$this->updated = new DateTimeImmutable();
}
}
62 changes: 62 additions & 0 deletions src/Book/src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Light\Book;

use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Light\Book\Factory\CreateBookHandlerFactory;
use Light\Book\Factory\DeleteBookHandlerFactory;
use Light\Book\Factory\ListBookHandlerFactory;
use Light\Book\Factory\UpdateBookHandlerFactory;
use Light\Book\Handler\CreateBookHandler;
use Light\Book\Handler\DeleteBookHandler;
use Light\Book\Handler\ListBooksHandler;
use Light\Book\Handler\UpdateBookHandler;
use Mezzio\Application;

class ConfigProvider
{
public function __invoke(): array

Check failure on line 20 in src/Book/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Method Light\Book\ConfigProvider::__invoke() return type has no value type specified in iterable type array.
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
];
}

private function getDependencies(): array

Check failure on line 28 in src/Book/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Method Light\Book\ConfigProvider::getDependencies() return type has no value type specified in iterable type array.
{
return [
'delegators' => [
Application::class => [
RoutesDelegator::class,
],
],
'factories' => [
CreateBookHandler::class => CreateBookHandlerFactory::class,
ListBooksHandler::class => ListBookHandlerFactory::class,
UpdateBookHandler::class => UpdateBookHandlerFactory::class,
DeleteBookHandler::class => DeleteBookHandlerFactory::class,
],
];
}

private function getDoctrineConfig(): array

Check failure on line 45 in src/Book/src/ConfigProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Method Light\Book\ConfigProvider::getDoctrineConfig() return type has no value type specified in iterable type array.
{
return [
'driver' => [
'orm_default' => [
'drivers' => [
'Light\Book\Entity' => 'BookEntities',
],
],
'BookEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => [__DIR__ . '/Entity'],
],
],
];
}
}
50 changes: 50 additions & 0 deletions src/Book/src/Entity/Book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Light\Book\Entity;

use Doctrine\ORM\Mapping as ORM;
use Light\App\Entity\AbstractEntity;
use Light\App\Entity\TimestampsTrait;

#[ORM\Entity]
#[ORM\Table(name: 'books')]
#[ORM\HasLifecycleCallbacks]
class Book extends AbstractEntity
{
use TimestampsTrait;

#[ORM\Column(name: 'title', type: 'string', length: 500, nullable: true)]
private ?string $title = null;

#[ORM\Column(name: 'author', type: 'string', length: 500, nullable: true)]
private ?string $author = null;

public function __construct()
{
parent::__construct();

$this->created();
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): void
{
$this->title = $title;
}

public function getAuthor(): ?string
{
return $this->author;
}

public function setAuthor(string $author): void
{
$this->author = $author;
}
}
Loading
Loading