Skip to content

Commit ef9c7b2

Browse files
committed
updated intro, how to
Signed-off-by: bidi <bidi@apidemia.com>
1 parent 9ca2b48 commit ef9c7b2

8 files changed

Lines changed: 230 additions & 3 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Authorization Guards
2+
3+
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).
4+
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.
5+
6+
The `authorization.global.php` file provides multiple configurations specifying multiple roles as well as the types of permissions to which these roles have access.
7+
8+
```php
9+
//example of a flat RBAC model that specifies two types of roles as well as their permission
10+
'roles' => [
11+
'admin' => [
12+
'permissions' => [
13+
'authenticated',
14+
'edit',
15+
'delete',
16+
//etc..
17+
]
18+
],
19+
'user' => [
20+
'permissions' => [
21+
'authenticated',
22+
//etc..
23+
]
24+
]
25+
]
26+
```
27+
28+
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.
29+
30+
```php
31+
// configuration example to restrict certain actions of some routes based on the permissions specified in the dot-rbac configuration file
32+
'rules' => [
33+
[
34+
'route' => 'account',
35+
'actions' => [//list of actions to apply , or empty array for all actions
36+
'unregister',
37+
'avatar',
38+
'details',
39+
'changePassword'
40+
],
41+
'permissions' => ['authenticated']
42+
],
43+
[
44+
'route' => 'admin',
45+
'actions' => [
46+
'deleteAccount'
47+
],
48+
'permissions' => [
49+
'delete'
50+
//list of roles to allow
51+
]
52+
]
53+
]
54+
```
File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Dependency Injection
2+
3+
Dependency injection is a design pattern used in software development to implement inversion of control.
4+
In simpler terms, it's the act of providing dependencies for an object during instantiation.
5+
6+
In PHP, dependency injection can be implemented in various ways, including through constructor injection, setter injection and property injection.
7+
8+
Dotkernel Admin, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package focuses only on constructor injection.
9+
10+
## Usage
11+
12+
**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.
13+
14+
`dot-dependency-injection` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor of a class.
15+
Each dependency is specified as a separate parameter of the `#[Inject]` attribute.
16+
17+
For our example we will inject `AdminService` and `config` dependencies into a `AdminController`.
18+
19+
```php
20+
use Dot\DependencyInjection\Attribute\Inject;
21+
22+
class AdminController implements RequestHandlerInterface
23+
{
24+
#[Inject(
25+
AdminService::class,
26+
"config",
27+
)]
28+
public function __construct(
29+
protected AdminServiceInterface $adminService,
30+
protected array $config,
31+
) {
32+
}
33+
}
34+
```
35+
36+
> If your class needs the value of a specific configuration key, you can specify the path using dot notation: `config.example`
37+
38+
The next step is to register the class in the `ConfigProvider` under `factories` using
39+
`Dot\DependencyInjection\Factory\AttributedServiceFactory::class`.
40+
41+
```php
42+
public function getDependencies(): array
43+
{
44+
return [
45+
'factories' => [
46+
AdminController::class => AttributedServiceFactory::class
47+
]
48+
];
49+
}
50+
```
51+
52+
That's it.
53+
When your object is instantiated from the container, it will automatically have its dependencies resolved.
54+
55+
> Dependencies injection is available to any object within Dotkernel Admin.
56+
> For example, you can inject dependencies in a service, a controller and so on, simply by registering them in the `ConfigProvider`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# NPM Commands
2+
3+
To install dependencies into the `node_modules` directory run this command.
4+
5+
```shell
6+
npm install
7+
```
8+
9+
> If `npm install` fails, this could be caused by user permissions of npm.
10+
> The recommended way to install npm is through `Node Version Manager`.
11+
12+
The watch command compiles the components then monitors the files for changes and recompiles them.
13+
14+
```shell
15+
npm run watch
16+
```
17+
18+
After all updates are done, this command compiles the assets locally, minifies them and makes them ready for production.
19+
20+
```shell
21+
npm run prod
22+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# File structure
2+
3+
Dotkernel Admin follows the [PSR-4](https://www.php-fig.org/psr/psr-4/) standards.
4+
5+
It is considered good practice to standardize the file structure of projects.
6+
7+
When using Dotkernel Admin the following structure is installed by default:
8+
9+
![Dotkernel Admin File Structure!](https://docs.dotkernel.org/img/Admin/file-structure-dk-Admin.png)
10+
11+
## Main directories
12+
13+
* `bin` - Executable files from CLI
14+
* `config` - Various configuration files
15+
* `data` - Should contain project-related data (AVOID storing sensitive data on VCS)
16+
* `log` - Storage of log files generated by dot-error-log library
17+
* `public` - Publicly visible files. The webserver need to have this folder as www-document root folder.
18+
* `src` - Should contain the source code files
19+
* `test` - Should contain the test files
20+
21+
## Special purpose folders
22+
23+
* `.github` - Contains workflow files
24+
* `.laminas-ci` - Contains laminas-ci workflow files
25+
26+
## `src` directory
27+
28+
This directory contains all source code related to the Module.
29+
It should contain the following directories, if they are not empty:
30+
31+
* Handler - Action classes (similar to Controllers but can only perform one action)
32+
* Entity - Database entities
33+
* Service - Service classes
34+
* Collection - Database entities collections
35+
* Repository - Entity repository folder
36+
37+
> The above example lists just a part of the directories in a project, but it should give you an idea of what the structure should look like.
38+
39+
Other classes in the `src` directory may include `InputFilter`, `EventListener`, `Helper`, `Command`, `Factory` etc.
40+
41+
The `src` directory should also contain 2 files:
42+
43+
* `ConfigProvider.php` - Provides configuration data
44+
* `RoutesDelegator.php` - Module main routes entry file
45+
46+
## `templates` directory for modules
47+
48+
This directory contains the template files, used for example to help render e-mail templates.
49+
50+
> Dotkernel Admin uses `twig` as Templating Engine.
51+
> All template files have the extension `.html.twig`.
52+
53+
## `data` directory
54+
55+
This directory contains project-related data, like cache and file uploads.
56+
57+
We recommend using the following directory structure:
58+
59+
* `data/cache` - Location where caches are stored
60+
* `data/doctrine` - Fixtures and migrations
61+
* `data/lock` - Lock files generated by [dotkernel/dot-cli](https://docs.dotkernel.org/dot-cli/v3/lock-files/)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Introduction
22

3-
Dotkernel web starter package suitable for admin applications.
3+
Dotkernel Admin is an application (skeleton) intended for quickly setting up an administration site for your platform.
4+
It's a fast and reliable way to manage records in your database with a simple table-based approach, and also to build reports and graphs to monitor your platform.
5+
The many graphical components at your disposal ensure an intuitive user experience.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Packages
2+
3+
* `dotkernel/dot-cache` - Provides caching based on symfony/cache
4+
* `dotkernel/dot-cli` - Build console applications based on laminas-cli
5+
* `dotkernel/dot-controller` - Provides base classes for action based controllers similar to Laminas controller component
6+
* `dotkernel/dot-data-fixtures` - Provides a CLI interface for listing & executing doctrine data fixtures
7+
* `dotkernel/dot-dependency-injection` - Dependency injection component using class attributes
8+
* `dotkernel/dot-errorhandler` - Logging Error Handler for Middleware Applications
9+
* `dotkernel/dot-flashmessenger` - Provides session messages between redirects
10+
* `dotkernel/dot-geoip` - Retrieve information about an IP address based on maxmind/GeoIP2-php
11+
* `dotkernel/dot-helpers` - Helper/Utility classes based on mezzio/mezzio-helpers
12+
* `dotkernel/dot-mail` - Mail component based on laminas-mail
13+
* `dotkernel/dot-navigation` - Allows you to easily define and parse menus inside templates, configuration based approach
14+
* `dotkernel/dot-rbac-guard` - Defines authorization guards that authorize users for accessing certain parts of an application based on various criteria
15+
* `dotkernel/dot-session` - Dotkernel session component extending and customizing laminas-session
16+
* `dotkernel/dot-twigrenderer` - Dotkernel component providing twig extensions and customizations
17+
* `friendsofphp/proxy-manager-lts` - Fork of ocramius/proxy-manager
18+
* `laminas/laminas-component-installer` - Composer plugin for injecting modules and configuration providers into application configuration
19+
* `laminas/laminas-config-aggregator` - Lightweight library for collecting and merging configuration from different sources
20+
* `laminas/laminas-i18n` - Complete translation suite
21+
* `laminas/laminas-math` - Create cryptographically secure pseudo-random numbers and manage big integers
22+
* `mezzio/mezzio` - PSR-15 Middleware Microframework
23+
* `mezzio/mezzio-authorization-rbac` - mezzio authorization rbac adapter for laminas/laminas-permissions-rbac
24+
* `mezzio/mezzio-cors` - CORS component for Mezzio and other PSR-15 middleware runners
25+
* `mezzio/mezzio-fastroute` - FastRoute integration for Mezzio
26+
* `ramsey/uuid-doctrine` - Use ramsey/uuid as a Doctrine field type
27+
* `roave/psr-container-doctrine` - Doctrine Factories for PSR-11 Containers

mkdocs.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ nav:
1111
- Introduction: v5/introduction/introduction.md
1212
- Overview:
1313
- "Server Requirements": v5/introduction/server-requirements.md
14+
- "File Structure": v5/introduction/file-structure.md
15+
- "Packages": v5/introduction/packages.md
1416
- Installation:
1517
- "Getting Started": v5/installation/getting-started.md
1618
- "Composer": v5/installation/composer.md
1719
- "Configuration Files": v5/installation/configuration-files.md
1820
- "Doctrine ORM": v5/installation/doctrine-orm.md
1921
- "Manage Geolite2": v5/installation/manage-geolite2.md
2022
- "Test the Installation": v5/installation/test-the-installation.md
21-
- Core Features:
22-
- "CSRF": v5/core-features/csrf.md
23+
- Hot to:
24+
- "Configure Authorizations": v5/how-to/authorization.md
25+
- "Use NPM Commands": v5/how-to/npm_commands.md
26+
- "Inject Dependencies": v5/how-to/dependency-injection.md
27+
- "Set Up CSRF": v5/how-to/csrf.md
2328
site_name: admin
2429
site_description: "DotKernel Admin"
2530
repo_url: "https://github.com/dotkernel/admin"

0 commit comments

Comments
 (0)