Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Continuous Integration"

on:
pull_request:
push:
branches:
tags:

jobs:
ci:
uses: laminas/workflow-continuous-integration/.github/workflows/[email protected]
50 changes: 50 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
- push

name: Run PHPStan checks

jobs:
mutation:
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
uses: actions/checkout@v4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: actions/checkout@v4
uses: actions/checkout@v5


- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis with PHPStan
run: vendor/bin/phpstan analyse
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 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
## 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
Expand All @@ -12,5 +14,3 @@ Book tutorial starting from Dotkernel Light: Level 101 beginner
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.


241 changes: 9 additions & 232 deletions docs/book/chapter-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@

The first step is to add alongside your current packages the required entries for our Doctrine installation. We would add the following to our `composer.json` file located in our root folder:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The first step is to add alongside your current packages the required entries for our Doctrine installation. We would add the following to our `composer.json` file located in our root folder:
The first step is to add alongside your current packages the required entries for our Doctrine installation.
We would add the following to our `composer.json` file located in our root folder:


```json
{
"require": {
"dotkernel/dot-cache": "^4.0",
"ramsey/uuid": "^4.5.0",
"ramsey/uuid-doctrine": "^2.1.0",
"roave/psr-container-doctrine": "^5.2.2"
},
"require-dev": {
"phpstan/phpstan-doctrine": "^2.0.3"
}
}
```
![composer](../images/composer.png)

`dotkernel/dot-cache`

Expand Down Expand Up @@ -49,28 +37,9 @@ After successfully installing our dependencies we now need to configure our Doct

### Declare your database

In the file `config/autoload/local.php`:

```php
$databases = [
'default' => [
'host' => 'localhost',
'dbname' => 'light',
'user' => 'root',
'password' => '123',
'port' => 3306,
'driver' => 'pdo_mysql',
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_general_ci',
],
// you can add more database connections into this array
];

return [
'databases' => $databases,
//the rest of your configuration variables
];
```
In the file `config/autoload/local.php` the structure would be updated like this:

![local.php](../images/local.png)

### Declare the Doctrine Drivers and Migrations Location

Expand All @@ -79,216 +48,24 @@ This package takes all the provided configs from the `config/config.php` file an

Our new `src/App/src/ConfigProvider.php` class would look like this now:

```php
<?php

declare(strict_types=1);

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
{
/**
@return array{
* dependencies: array<mixed>,
* templates: array<mixed>,
* }
*/
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
'templates' => $this->getTemplates(),
];
}

/**
* @return array{
* delegators: array<class-string, array<class-string>>,
* factories: array<class-string, class-string>,
* }
*/
public function getDependencies(): array
{
return [
'delegators' => [
Application::class => [
RoutesDelegator::class,
],
],
'factories' => [
'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',
],
];
}

/**
* @return array{
* paths: array{
* app: array{literal-string&non-falsy-string},
* error: array{literal-string&non-falsy-string},
* layout: array{literal-string&non-falsy-string},
* partial: array{literal-string&non-falsy-string},
* }
* }
*/
public function getTemplates(): array
{
return [
'paths' => [
'app' => [__DIR__ . '/../templates/app'],
'error' => [__DIR__ . '/../templates/error'],
'layout' => [__DIR__ . '/../templates/layout'],
'partial' => [__DIR__ . '/../templates/partial'],
],
];
}

private function getDoctrineConfig(): array
{
return [
'cache' => [
'array' => [
'class' => ArrayAdapter::class,
],
'filesystem' => [
'class' => FilesystemAdapter::class,
'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' => [
// Modify this line based on where you would like to have you 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,
],
];
}
}

```
![Config provider factories update](../images/config-provider-1.png)
![Doctrine config function](../images/config-provider-2.png)

We also require a new file `config/cli-config.php`.
It initializes and returns a `DependencyFactory` that Doctrine Migrations uses to run migrations.

```php
<?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)
);
```
![cli-config](../images/cli-config.png)

## Running doctrine

Now that everything has been configured we only need to do one last thing, to create an executable for the Doctrine CLI.
In our case we will create it as `/bin/doctrine`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In our case we will create it as `/bin/doctrine`
In our case we will create a `doctrine` file inside the application's `bin` directory:

Rephrased to avoid confusion with the OS's bin directory - especially since you started the path with a leading /.
If you have a better rephrasing, go with it - as long as it clearly states which bin directory you are referring to.


```php
#!/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));
```
![bin/doctrine](../images/doctrine.png)

(Optional) To keep things tidy we recommend to make an executable for the migrations of Doctrine as well for example `/bin/doctrine-migrations`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(Optional) To keep things tidy we recommend to make an executable for the migrations of Doctrine as well for example `/bin/doctrine-migrations`:
(Optional) To keep things tidy, we recommend making an executable for the migrations of Doctrine as well.
For this, we create `doctrine-migrations` file inside the application's `bin` directory:

Same reason as with the above rephrasing.


```php
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace Doctrine\Migrations;

require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php';
```
![bin/doctrine-migrations](../images/doctrine-migrations.png)

Now by running the command bellow we should see the Doctrine CLI version alongside its available commands:

Expand Down
1 change: 1 addition & 0 deletions docs/book/index.md
Binary file added docs/images/cli-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/composer.png
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add mezzio/mezzio-twigrenderer and vincentlanglet/twig-cs-fixer when they already are in Light?

Also, I would add phpstan/phpstan-doctrine later, in a different chapter.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/config-provider-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/config-provider-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/doctrine-migrations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/doctrine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/local.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/index.md

This file was deleted.

2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ site_name: 101.dotkernel
site_description: "Beginner tutorial for using Dotkernel"
repo_url: "https://github.com/dotkernel/tutorial-101#"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
repo_url: "https://github.com/dotkernel/tutorial-101#"
repo_url: "https://github.com/dotkernel/tutorial-101"

plugins:
- search
- search