-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dotkernel/diataxis
Diataxis
- Loading branch information
Showing
19 changed files
with
330 additions
and
203 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
docs/book/v5/core-features/authorization.md → docs/book/v5/how-to/authorization.md
This file contains 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 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 @@ | ||
# Fixtures | ||
|
||
> Fixtures are used to seed the database with initial values and should only be executed ONCE each, after migrating the database. | ||
Seeding the database is done with the help of our custom package `dotkernel/dot-data-fixtures` built on top of `doctrine/data-fixtures`. | ||
See below on how to use our CLI command for listing and executing Doctrine data fixtures. | ||
|
||
## Working with fixtures | ||
|
||
You can find an example of a fixtures class in `data/doctrine/fixtures/RoleLoader.php`. | ||
|
||
To list all the available fixtures by order of execution run: | ||
|
||
```shell | ||
php bin/doctrine fixtures:list | ||
``` | ||
|
||
To execute all fixtures run: | ||
|
||
```shell | ||
php bin/doctrine fixtures:execute | ||
``` | ||
|
||
To execute a specific fixture, use its class name, like in this example: | ||
|
||
```shell | ||
php bin/doctrine fixtures:execute --class=RoleLoader | ||
``` | ||
|
||
Fixtures can and should be ordered to ensure database consistency. | ||
More on ordering fixtures can be found here : | ||
https://www.doctrine-project.org/projects/doctrine-data-fixtures/en/latest/how-to/fixture-ordering.html#fixture-ordering |
This file contains 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,29 @@ | ||
# Creating migrations | ||
|
||
Migrations are used to create and/or edit the database structure. | ||
To generate a new migration file, use this command: | ||
|
||
```shell | ||
php vendor/bin/doctrine-migrations migrations:generate | ||
``` | ||
|
||
It creates a PHP file like this one `/data/doctrine/migrations/Version20220606131835.php` that can then be edited in the IDE. | ||
You can add new queries in: | ||
|
||
- `public function up` - these are executed when the migration is run. | ||
- `public function down` - these are optional queries that undo the above changes. | ||
|
||
## Example | ||
|
||
This example creates a new column named `test`. | ||
Add this in `public function up`: | ||
|
||
```shell | ||
$this->addSql('ALTER TABLE users ADD test VARCHAR(255) NOT NULL'); | ||
``` | ||
|
||
And its opposite in `public function down`: | ||
|
||
```shell | ||
$this->addSql('ALTER TABLE users DROP test'); | ||
``` |
This file contains 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 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,56 @@ | ||
# Dependency Injection | ||
|
||
Dependency injection is a design pattern used in software development to implement inversion of control. | ||
In simpler terms, it's the act of providing dependencies for an object during instantiation. | ||
|
||
In PHP, dependency injection can be implemented in various ways, including through constructor injection, setter injection and property injection. | ||
|
||
DotKernel Frontend, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package focuses only on constructor injection. | ||
|
||
## Usage | ||
|
||
**DotKernel Frontend** comes out of the box with the [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package, which provides all the functionality injecting dependencies into any object you want. | ||
|
||
`dot-dependency-injection` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor of a class. | ||
Each dependency is specified as a separate parameter of the `#[Inject]` attribute. | ||
|
||
For our example we will inject `UserService` and `config` dependencies into a `UserHandler`. | ||
|
||
```php | ||
use Dot\DependencyInjection\Attribute\Inject; | ||
|
||
class UserHandler implements RequestHandlerInterface | ||
{ | ||
#[Inject( | ||
UserService::class, | ||
"config", | ||
)] | ||
public function __construct( | ||
protected UserServiceInterface $userService, | ||
protected array $config, | ||
) { | ||
} | ||
} | ||
``` | ||
|
||
> If your class needs the value of a specific configuration key, you can specify the path using dot notation: `config.example` | ||
The next step is to register the class in the `ConfigProvider` under `factories` using | ||
`Dot\DependencyInjection\Factory\AttributedServiceFactory::class`. | ||
|
||
```php | ||
public function getDependencies(): array | ||
{ | ||
return [ | ||
'factories' => [ | ||
UserHandler::class => AttributedServiceFactory::class | ||
] | ||
]; | ||
} | ||
``` | ||
|
||
That's it. | ||
When your object is instantiated from the container, it will automatically have its dependencies resolved. | ||
|
||
> Dependencies injection is available to any object within DotKernel Frontend. | ||
> For example, you can inject dependencies in a service, a handler and so on, simply by registering them in the `ConfigProvider`. |
This file contains 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 @@ | ||
# Languages | ||
|
||
The `local.php.dist` file provides an example for working with multiple languages. | ||
The `translator` variable can be expanded to other languages using [Poedit](https://poedit.net/) which can edit `.po` files like the example in `data/language/da_DK/LC_MESSAGES/messages.po`. | ||
The compiled file will have the extension `.mo`. | ||
|
||
To apply the translations | ||
|
||
- the twig templates need either `{% trans 'translateText' %}` or `{{ translateText|trans }}` | ||
- then the js file needs `translateText("translateText")` | ||
|
||
> In order to have a proper behaviour of language selector , you need the language pack installed at Operating System level. | ||
```shell | ||
dnf install glibc-all-langpacks | ||
``` | ||
|
||
Then restart PHP-FPM. |
This file contains 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 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
Oops, something went wrong.