Skip to content
Draft
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
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# tutorial-101
Book tutorial starting from Dotkernel Light: Level 101 beginner

### BRANCH : - main unde e documentatia , se compileaza documentatia. aplicatie din light, deploy functional !!!! --> 101.dotkernel.net
1. instalezi light la tine pe WSL2
2. iei chapter 1, citesti documentation, implementezi una cite una
- CHAPTER-1-doctrine # protected - including Light, and add visible DIFF between branches
- CHAPTER-2- forms # protected
- CHAPTER-3- inputfilter # protected
- CHAPTER-4 -list books # protected

main: incepi de la light , clone
- adaigi folderul docs/book cu structura asta https://github.com/dotkernel/dot-session/tree/5.0/docs/book
- cu fisier symlink si etc.


Book tutorial starting from Dotkernel Light: Level 101 beginner
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';
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,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
46 changes: 0 additions & 46 deletions config/autoload/local.php

This file was deleted.

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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// Default App module config
\Light\App\ConfigProvider::class,
\Light\Page\ConfigProvider::class,
\Light\Book\ConfigProvider::class,

// Load application config in a pre-defined order in such a way that local settings
// overwrite global settings. (Loaded as first to last):
Expand Down
Empty file modified data/cache/.gitignore
100755 → 100644
Empty file.
16 changes: 0 additions & 16 deletions mkdocs.yml

This file was deleted.

81 changes: 72 additions & 9 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,72 @@

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Dot\Cache\Adapter\ArrayAdapter;
use Dot\Cache\Adapter\FilesystemAdapter;
use Light\App\DBAL\Types\UuidType;
use Light\App\Factory\GetIndexViewHandlerFactory;
use Light\App\Handler\GetIndexViewHandler;
use Mezzio\Application;
use Ramsey\Uuid\Doctrine\UuidType;
use Roave\PsrContainerDoctrine\EntityManagerFactory;
use Symfony\Component\Cache\Adapter\AdapterInterface;

use function getcwd;

/**
* @phpstan-type ConfigType array{
* dependencies: DependenciesType,
* doctrine: DoctrineConfigType,
* }
* @phpstan-type DoctrineConfigType array{
* cache: array{
* array: array{
* class: class-string<AdapterInterface>,
* },
* filesystem: array{
* class: class-string<AdapterInterface>,
* directory: non-empty-string,
* namespace: non-empty-string,
* },
* },
* configuration: array{
* orm_default: array{
* result_cache: non-empty-string,
* metadata_cache: non-empty-string,
* query_cache: non-empty-string,
* hydration_cache: non-empty-string,
* typed_field_mapper: non-empty-string|null,
* second_level_cache: array{
* enabled: bool,
* default_lifetime: int,
* default_lock_lifetime: int,
* file_lock_region_directory: string,
* regions: string[],
* },
* },
* },
* driver: array{
* orm_default: array{
* class: class-string<MappingDriver>,
* },
* },
* migrations: array{
* migrations_paths: array<non-empty-string, non-empty-string>,
* all_or_nothing: bool,
* check_database_platform: bool,
* },
* types: array<non-empty-string, class-string>,
* }
* @phpstan-type DependenciesType array{
* factories: array<class-string|non-empty-string, class-string|non-empty-string>,
* aliases: array<class-string|non-empty-string, class-string|non-empty-string>,
* }
**/
class ConfigProvider
{
/**
@return array{
* dependencies: array<mixed>,
* templates: array<mixed>,
* }
* @return ConfigType
*/
public function __invoke(): array
{
Expand All @@ -35,10 +83,7 @@ public function __invoke(): array
}

/**
* @return array{
* delegators: array<class-string, array<class-string>>,
* factories: array<class-string, class-string>,
* }
* @return DependenciesType
*/
public function getDependencies(): array
{
Expand Down Expand Up @@ -81,6 +126,9 @@ public function getTemplates(): array
];
}

/**
* @return DoctrineConfigType
*/
private function getDoctrineConfig(): array
{
return [
Expand Down Expand Up @@ -117,6 +165,21 @@ private function getDoctrineConfig(): array
'class' => MappingDriverChain::class,
],
],
'migrations' => [
'table_storage' => [
'table_name' => 'doctrine_migration_versions',
'version_column_name' => 'version',
'version_column_length' => 191,
'executed_at_column_name' => 'executed_at',
'execution_time_column_name' => 'execution_time',
],
// Modify this line based on where you would like to have your migrations
'migrations_paths' => [
'Migrations' => 'src/App/src/Migration',
],
'all_or_nothing' => true,
'check_database_platform' => true,
],
'types' => [
UuidType::NAME => UuidType::class,
],
Expand Down
17 changes: 17 additions & 0 deletions src/App/src/DBAL/Types/UuidType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Light\App\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;

class UuidType extends \Ramsey\Uuid\Doctrine\UuidType
{
public const NAME = 'uuid';

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'UUID';
}
}
106 changes: 106 additions & 0 deletions src/App/src/Entity/AbstractEntity.php
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\Id]
#[ORM\Column(name: 'id', type: 'uuid', unique: true, nullable: false)]
protected UuidInterface $id;

#[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 __construct()
{
$this->id = Uuid::uuid7();
}

public function getId(): UuidInterface
{
return $this->id;
}

public function setId(UuidInterface $id): static
{
$this->id = $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;
}

#[ORM\PrePersist]
public function created(): void
{
$this->created = new DateTimeImmutable();
}

#[ORM\PreUpdate]
public function touch(): void
{
$this->updated = new DateTimeImmutable();
}

/**
* @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);
}
}
}
}
21 changes: 21 additions & 0 deletions src/App/src/Entity/EntityInterface.php
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;
}
Empty file added src/App/src/Migration/.gitkeep
Empty file.
Loading