-
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/composer
updated intro, how to
- Loading branch information
Showing
17 changed files
with
450 additions
and
72 deletions.
There are no files selected for viewing
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,54 @@ | ||
# Authorization Guards | ||
|
||
The packages responsible for restricting access to certain parts of the application are [dot-rbac-guard](https://github.com/dotkernel/dot-rbac-guard) and [dot-rbac](https://github.com/dotkernel/dot-rbac). | ||
These packages work together to create an infrastructure that is customizable and diversified to manage user access to the platform by specifying the type of role the user has. | ||
|
||
The `authorization.global.php` file provides multiple configurations specifying multiple roles as well as the types of permissions to which these roles have access. | ||
|
||
```php | ||
//example of a flat RBAC model that specifies two types of roles as well as their permission | ||
'roles' => [ | ||
'admin' => [ | ||
'permissions' => [ | ||
'authenticated', | ||
'edit', | ||
'delete', | ||
//etc.. | ||
] | ||
], | ||
'user' => [ | ||
'permissions' => [ | ||
'authenticated', | ||
//etc.. | ||
] | ||
] | ||
] | ||
``` | ||
|
||
The `authorization-guards.global.php` file provides configuration to restrict access to certain actions based on the permissions defined in `authorization.global.php` so basically we have to add the permissions in the dot-rbac configuration file first to specify the action restriction permissions. | ||
|
||
```php | ||
// configuration example to restrict certain actions of some routes based on the permissions specified in the dot-rbac configuration file | ||
'rules' => [ | ||
[ | ||
'route' => 'account', | ||
'actions' => [//list of actions to apply , or empty array for all actions | ||
'unregister', | ||
'avatar', | ||
'details', | ||
'changePassword' | ||
], | ||
'permissions' => ['authenticated'] | ||
], | ||
[ | ||
'route' => 'admin', | ||
'actions' => [ | ||
'deleteAccount' | ||
], | ||
'permissions' => [ | ||
'delete' | ||
//list of roles to allow | ||
] | ||
] | ||
] | ||
``` |
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/AdminLoader.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=AdminLoader | ||
``` | ||
|
||
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/Version20240627134952.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 admin ADD test VARCHAR(255) NOT NULL'); | ||
``` | ||
|
||
And its opposite in `public function down`: | ||
|
||
```shell | ||
$this->addSql('ALTER TABLE admin DROP test'); | ||
``` |
File renamed without changes.
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 Admin, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package focuses only on constructor injection. | ||
|
||
## Usage | ||
|
||
**Dotkernel Admin** 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 `AdminService` and `config` dependencies into a `AdminController`. | ||
|
||
```php | ||
use Dot\DependencyInjection\Attribute\Inject; | ||
|
||
class AdminController implements RequestHandlerInterface | ||
{ | ||
#[Inject( | ||
AdminService::class, | ||
"config", | ||
)] | ||
public function __construct( | ||
protected AdminServiceInterface $adminService, | ||
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' => [ | ||
AdminController::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 Admin. | ||
> For example, you can inject dependencies in a service, a controller 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,22 @@ | ||
# NPM Commands | ||
|
||
To install dependencies into the `node_modules` directory run this command. | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
> If `npm install` fails, this could be caused by user permissions of npm. | ||
> The recommended way to install npm is through `Node Version Manager`. | ||
The watch command compiles the components then monitors the files for changes and recompiles them. | ||
|
||
```shell | ||
npm run watch | ||
``` | ||
|
||
After all updates are done, this command compiles the assets locally, minifies them and makes them ready for production. | ||
|
||
```shell | ||
npm run prod | ||
``` |
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
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 |
---|---|---|
@@ -1,47 +1,85 @@ | ||
# Doctrine ORM | ||
|
||
This step saves the database connection credentials in an Admin configuration file. | ||
We do not cover the creation steps of the database itself. | ||
|
||
## Setup database | ||
|
||
Make sure you fill out the database credentials in `config/autoload/local.php` under `$databases['default']`. | ||
Create a new MySQL database and set its collation to `utf8mb4_general_ci`. | ||
|
||
Create a new MySQL database - set collation to `utf8mb4_general_ci` | ||
Make sure you fill out the database credentials in `config/autoload/local.php` under `$databases['default']`. | ||
Below is the item you need to focus on. | ||
|
||
> `my_database`, `my_user`, `my_password` are provided only as an example. | ||
```php | ||
$databases = [ | ||
'default' => [ | ||
'host' => 'localhost', | ||
'dbname' => 'my_database', | ||
'user' => 'my_user', | ||
'password' => 'my_password', | ||
'port' => 3306, | ||
'driver' => 'pdo_mysql', | ||
'charset' => 'utf8mb4', | ||
'collate' => 'utf8mb4_general_ci', | ||
], | ||
// you can add more database connections into this array | ||
]; | ||
``` | ||
|
||
## Running migrations | ||
|
||
Run the database migrations by using the following command: | ||
|
||
```shell | ||
php bin/doctrine-migrations migrate | ||
php vendor/bin/doctrine-migrations migrate | ||
``` | ||
|
||
This command will prompt you to confirm that you want to run it. | ||
Note: If you have already run the migrations, you may get this message. | ||
You should double-check to make sure the new migrations are ok to run. | ||
|
||
> WARNING! You are about to execute a migration in database "..." that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]: | ||
```shell | ||
WARNING! You have x previously executed migrations in the database that are not registered migrations. | ||
{migration list} | ||
Are you sure you wish to continue? (y/n) | ||
``` | ||
|
||
Hit `Enter` to confirm the operation. | ||
When using an empty database, you will get this confirmation message instead. | ||
|
||
## Executing fixtures | ||
```shell | ||
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n) | ||
``` | ||
|
||
**Fixtures are used to seed the database with initial values and should be executed after migrating the database.** | ||
Again, submit `y` to run all the migrations in chronological order. | ||
Each migration will be logged in the `migrations` table to prevent running the same migration more than once, which is often not desirable. | ||
|
||
To list all the fixtures, run: | ||
If everything ran correctly, you will get this confirmation. | ||
|
||
```shell | ||
php bin/doctrine fixtures:list | ||
[OK] Successfully migrated to version: Admin\Migrations\Version20240627134952 | ||
``` | ||
|
||
This will output all the fixtures in the order of execution. | ||
> The migration name `Version20240627134952` may differ in future Admin updates. | ||
To execute all fixtures, run: | ||
## Fixtures | ||
|
||
Run this command to populate the admin tables with the default values: | ||
|
||
```shell | ||
php bin/doctrine fixtures:execute | ||
``` | ||
|
||
To execute a specific fixture, run: | ||
You should see our galloping horse in the command line. | ||
|
||
```shell | ||
php bin/doctrine fixtures:execute --class=FixtureClassName | ||
Executing Admin\Fixtures\AdminRoleLoader | ||
Executing Admin\Fixtures\AdminLoader | ||
Fixtures have been loaded. | ||
.'' | ||
._.-.___.' (`\ | ||
//( ( `' | ||
'/ )\ ).__. ) | ||
' <' `\ ._/'\ | ||
` \ \ | ||
``` | ||
|
||
More details on how fixtures work can be found here: https://github.com/dotkernel/dot-data-fixtures#creating-fixtures |
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,11 @@ | ||
# Introduction | ||
|
||
In this tutorial, we will install Dotkernel Admin from scratch. | ||
We will focus on these tasks: | ||
|
||
- Highlight 3rd party tools required for the installation. | ||
- Provide all the relevant commands with expected responses. | ||
- Configure the development environment. | ||
- Run the project. | ||
|
||
By the end of this tutorial you will have a fully-functional Dotkernel Admin on your selected environment and can begin coding. |
Oops, something went wrong.