Skip to content

Commit 6e05cba

Browse files
authored
Merge pull request #75 from dotkernel/versions
feature versions, psr page
2 parents f02c59a + 0df6eab commit 6e05cba

File tree

9 files changed

+174
-95
lines changed

9 files changed

+174
-95
lines changed

docs/book/v5/core-features/content-validation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Content Negotiation
22

3+
> Introduced in Dotkernel API 5.0.0
4+
35
**Content Negotiation** is performed by an application in order :
46

57
- To match the requested representation as specified by the client via the Accept header with a representation the
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# Dependency Injection
22

3-
Dependency injection is a design pattern used in software development to implement inversion of control. In simpler
4-
terms, it's the act of providing dependencies for an object during instantiation.
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.
55

6-
In PHP, dependency injection can be implemented in various ways, including through constructor injection, setter
7-
injection and property injection.
6+
In PHP, dependency injection can be implemented in various ways, including through constructor injection, setter injection and property injection.
87

9-
Dotkernel API, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package
10-
focuses only on constructor injection.
8+
> Introduced in Dotkernel API 5.0.0
9+
10+
Dotkernel API, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package focuses only on constructor injection.
1111

1212
## Usage
1313

14-
**Dotkernel API** comes out of the box with the
15-
[dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package, which provides all we need for
16-
injecting dependencies into any object you want.
14+
**Dotkernel API** comes out of the box with the [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package, which provides all we need for injecting dependencies into any object you want.
1715

18-
`dot-dependency-injection` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor
19-
of a class. Dependencies are specified as separate parameters of the `#[Inject]` attribute.
16+
`dot-dependency-injection` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor of a class.
17+
Dependencies are specified as separate parameters of the `#[Inject]` attribute.
2018

2119
For our example we will inject `UserService` and `config` dependencies into a `UseHandler`.
2220

@@ -37,11 +35,9 @@ class UserHandler implements RequestHandlerInterface
3735
}
3836
```
3937

40-
> If your class needs the value of a specific configuration key, you can specify the path using dot notation:
41-
> `config.example`
38+
> If your class needs the value of a specific configuration key, you can specify the path using dot notation `config.example`.
4239
43-
The next step is to register the class in the `ConfigProvider` under `factories` using
44-
`Dot\DependencyInjection\Factory\AttributedServiceFactory::class`
40+
The next step is to register the class in the `ConfigProvider` under `factories` using `Dot\DependencyInjection\Factory\AttributedServiceFactory::class`
4541

4642
```php
4743
public function getDependencies(): array
@@ -54,8 +50,8 @@ public function getDependencies(): array
5450
}
5551
```
5652

57-
That's it. When your object is instantiated from the container, it will automatically have its
58-
dependencies resolved.
53+
That's it.
54+
When your object is instantiated from the container, it will automatically have its dependencies resolved.
5955

60-
> Dependencies injection is available to any object within Dotkernel API. For example, you can inject dependencies in a
61-
> service, a handler and so on, simply by registering it in the `ConfigProvider`.
56+
> Dependencies injection is available to any object within Dotkernel API.
57+
> For example, you can inject dependencies in a service, a handler and so on, simply by registering it in the `ConfigProvider`.

docs/book/v5/core-features/exceptions.md

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,50 @@
22

33
## What are exceptions?
44

5-
Exceptions are a powerful mechanism for handling errors and other exceptional conditions that may occur during the
6-
execution of a script.
7-
They provide a way to manage errors in a structured and controlled manner, separating error-handling code from regular
8-
code.
5+
Exceptions are a powerful mechanism for handling errors and other exceptional conditions that may occur during the execution of a script.
6+
They provide a way to manage errors in a structured and controlled manner, separating error-handling code from regular code.
97

10-
## How we use exceptions?
8+
## How we use exceptions
119

12-
When it comes to handling exceptions, **Dotkernel API** relies on the usage of easy-to-understand, problem-specific
13-
exceptions.
14-
15-
Out-of-the-box we provide the following custom exceptions:
10+
When it comes to handling exceptions, **Dotkernel API** relies on the usage of easy-to-understand, problem-specific exceptions.
11+
Below we will list the available custom exceptions.
1612

1713
### `BadRequestException` thrown when
1814

19-
* client tries to create/update resource, but the data from the request is invalid/incomplete (example: client tries to
20-
create an account, but does not send the required `identity` field)
15+
* The Client tries to **create/update resource**, but the **request data is invalid/incomplete** (example: client tries to create an account, but does not send the required `identity` field)
2116

2217
### `ConflictException` thrown when
2318

24-
* resource cannot be created because a different resource with the same identifier already exists (example: cannot
25-
change existing user's identity because another user with the same identity already exists)
26-
* resource cannot change its state because it is already in the specified state (example: user cannot be activated
27-
because it is already active)
19+
* The **resource cannot be created** because a different resource with the same identifier **already exists** (example: cannot change existing user's identity because another user with the same identity already exists)
20+
* The **resource cannot change its state** because it is **already in the specified state** (example: user cannot be activated because it is already active)
2821

2922
### `ExpiredException` thrown when
3023

31-
* resource cannot be accessed because it expired (example: account activation link)
32-
* resource cannot be accessed because it has been consumed (example: one-time password)
24+
* The **resource cannot be accessed**
25+
* because it has **expired** (example: account activation link)
26+
* because it has been **consumed** (example: one-time password)
3327

3428
### `ForbiddenException` thrown when
3529

36-
* resource cannot be accessed by the authenticated client (example: client authenticated as regular user sends
37-
a `GET /admin` request)
30+
* The **resource cannot be accessed** by the authenticated client's **role** (example: client authenticated as regular user sends a `GET /admin` request)
3831

3932
### `MethodNotAllowedException` thrown when
4033

41-
* client tries to interact with a resource via an invalid HTTP request method (example: client sends a `PATCH /avatar`
42-
request)
34+
* The client tries to interact with a resource via an **invalid HTTP request method** (example: client sends a `PATCH /avatar` request)
4335

4436
### `NotFoundException` thrown when
4537

46-
* client tries to interact with a resource that does not exist on the server (example: client sends
47-
a `GET /resource-does-not-exist` request)
38+
* The client tries to interact with a **resource that does not exist** on the server (example: client sends a `GET /resource-does-not-exist` request)
4839

4940
### `UnauthorizedException` thrown when
5041

51-
* resource cannot be accessed because the client is not authenticated (example: unauthenticated client sends
52-
a `GET /admin` request)
42+
* The **resource cannot be accessed** because the **client is not authenticated** (example: unauthenticated client sends a `GET /admin` request)
5343

54-
## How it works?
44+
## How it works
5545

56-
During a request, if there is no uncaught exception **Dotkernel API** will return a JSON response with the data provided
57-
by the handler that handled the request.
46+
During a request, if there is no uncaught exception, **Dotkernel API** will return a JSON response with the data provided by the handler that processed the request.
5847

59-
Else, it will build and send a response based on the exception thrown:
48+
Otherwise, it will build and send a response based on the exception thrown:
6049

6150
* `BadRequestException` will return a `400 Bad Request` response
6251
* `UnauthorizedException` will return a `401 Unauthorized` response
@@ -67,11 +56,13 @@ Else, it will build and send a response based on the exception thrown:
6756
* `ExpiredException` will return a `410 Gone` response
6857
* `MailException`, `RuntimeException` and the generic `Exception` will return a `500 Internal Server Error` response
6958

70-
## How to extend?
59+
## How to extend
60+
61+
In this example we will
7162

72-
In this example we will create a custom exception called `CustomException`, place it next to the already existing custom
73-
exceptions (you can use your preferred location) and finally return a custom HTTP status code when `CustomException` is
74-
encountered.
63+
* Create a custom exception called `CustomException`
64+
* Place it next to the already existing custom exceptions (you can use your preferred location)
65+
* Return a custom HTTP status code when `CustomException` is encountered.
7566

7667
### Step 1: Create exception file
7768

@@ -106,8 +97,7 @@ Save and close the file.
10697

10798
### Step 3: Test for failure
10899

109-
Access your API's home page URL and make sure it returns `500 Internal Server Error` HTTP status code and the following
110-
content:
100+
Access your API's home page URL and make sure it returns `500 Internal Server Error` HTTP status code and the following content:
111101

112102
```json
113103
{
@@ -133,5 +123,5 @@ Save and close the file.
133123

134124
### Step 5: Test for success
135125

136-
Again, access your API's home page URL, which should return the same content.
126+
Access your API's home page URL, which should return the same content.
137127
Notice that this time it returns `418 I'm a teapot` HTTP status code.

docs/book/v5/introduction/file-structure.md

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,95 @@ When using Dotkernel API the following structure is installed by default:
2424
* `.github` - containes workflow files
2525
* `.laminas-ci` - contains laminas-ci workflow files
2626

27+
### `bin` directory
28+
29+
This directory contents are
30+
31+
* `clear-config-cache.php` which removes the config cache file (`data/cache/config-cache.php` - available only when development mode is enabled).
32+
* `cli.php` used to build console applications based on [laminas-cli](https://github.com/laminas/laminas-cli)
33+
* `doctrine` used by the doctrine fixtures to populate the database tables
34+
35+
### `config` directory
36+
37+
This directory contains all application-related config files:
38+
39+
* `cli-config.php`: command line interface configuration used by migrations, fixtures, crons
40+
* `config.php`: registers ConfigProviders for installing packages
41+
* `container.php`: main service container that provides access to all registered services
42+
* `development.config.php.dist`: activates debug mode; gets symlinked as `development.config.php` when enabling development mode
43+
* `migrations.php`: configuration for database migration, like migration file location and table to save the migration log
44+
* `pipeline.php`: contains a list of middlewares, in the order of their execution
45+
* `twig-cs-fixer.php`: configuration file for Twig code style checker/fixer
46+
47+
#### `config/autoload` directory
48+
49+
This directory contains all service-related local and global config files:
50+
51+
* `authorization.global.php`: configures access per route for user roles
52+
* `cli.global.php`: configures cli
53+
* `content-negotiation.global.php`: configures request and response formats
54+
* `cors.local.php.dist`: configures Cross-Origin Resource Sharing, like call origin, headers, cookies
55+
* `dependencies.global.php`: config file to set global dependencies that should be accessible by all modules
56+
* `development.local.php.dist`: gets symlinked as `development.local.php` when enabling development mode - activates error handlers
57+
* `doctrine.global.php`: configuration used by Object–relational mapping
58+
* `error-handling.global.php`: configures and activates error logs
59+
* `local.php.dist`: local config file where you can overwrite application name and URL
60+
* `local.test.php.dist`: local configuration for functional tests
61+
* `mail.local.php.dist`: mail configuration; e.g. sendmail vs smtp, message configuration, mail logging
62+
* `mezzio.global.php`: Mezzio core config file
63+
* `mezzio-tooling-factories.global.php`: add or remove factory definitions
64+
* `response-header.global.php`: defines headers per route
65+
* `templates.global.php`: dotkernel/dot-twigrenderer config file
66+
67+
### `data` directory
68+
69+
This directory is a storage for project data files and service caches.
70+
It contains these folders:
71+
72+
* `cache`: cache for e.g. Twig files
73+
* `doctrine`: database migrations and fixtures
74+
* `oauth`: encryption, private and public keys needed for authentication
75+
* `data/lock` - lock files generated by [`dotkernel/dot-cli`](https://docs.dotkernel.org/dot-cli/v3/lock-files/)
76+
77+
> AVOID storing sensitive data on VCS.
78+
79+
### `log` directory
80+
81+
This directory stores daily log files.
82+
When you access the application from the browser, (if not already created) a new log file gets created in the format specified in the `config/autoload/error-handling.global.php` config file under the `stream` array key.
83+
84+
### `public` directory
85+
86+
This directory contains all publicly available assets and serves as the entry point of the application:
87+
88+
* `uploads`: a folder that normally contains files uploaded via the application
89+
* `.htaccess`: server configuration file used by Apache web server; it enables the URL rewrite functionality
90+
* `index.php`: the application's main entry point
91+
* `robots.txt.dist`: a sample robots.txt file that allows/denies bot access to certain areas of your application; activate it by duplicating the file as `robots.txt` and comment out the lines that don't match your environment
92+
2793
## `src` directory
2894

29-
This directory contains all source code related to the Module. It should contain following directories, if they’re not empty:
95+
This folder contains a separate folder for each Module.
96+
Each Module folder, in turn, should contain following directories, unless they are empty:
3097

3198
* Handler - Action classes (similar to Controllers but can only perform one action)
32-
* Entity - For database entities
99+
* Entity - Used by database entities
33100
* Service - Service classes
34101
* Collection - Database entities collections
35102
* Repository - Entity repository folder
36103

37-
> The above example is just some of the directories a project may include, but these should give you an idea of how the structure should look like.
104+
> The above example is just some of the directories a project may include, but they should give you an idea about the recommended structure.
38105
39106
Other classes in the `src` directory may include `InputFilter`, `EventListener`, `Helper`, `Command`, `Factory` etc.
40107

41-
The `src` directory should also contain 2 files:
108+
The `src` directory normally also contains these files:
42109

43-
* `ConfigProvider.php` - Provides configuration data
44-
* `RoutesDelegator.php` - Module main routes entry file
110+
* `ConfigProvider.php` - Configuration data for the module
111+
* `OpenAPI.php` - Detailed descriptions for each endpoint in the OpenAPI format
112+
* `RoutesDelegator.php` - Module specific route registrations Module main routes entry file
45113

46114
## `templates` directory
47115

48116
This directory contains the template files, used for example to help render e-mail templates.
49117

50118
> Dotkernel API uses twig as Templating Engine. All template files have the extension .html.twig
51-
52-
## `data` directory
53-
54-
This directory contains project-related data (such as cache, file uploads)
55-
56-
We recommend using the following directory structure:
57-
58-
* `data/cache` - location where caches are stored
59-
* `data/oauth` - encryption, private and public keys needed for authentication.
60-
* `data/doctrine` - fixtures and migrations
61-
* `data/lock` - lock files generated by `dotkernel/dot-cli` [See more](https://docs.dotkernel.org/dot-cli/v3/lock-files/)

docs/book/v5/introduction/psr.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# PSRs
2+
3+
Some of the PSRs on this list are at the core of Dotkernel API, but several others are installed with the 3rd party packages used in the application.
4+
Below is the full list of PSRs present in Dotkernel API and their purpose.
5+
6+
* PSR-3: [Logger Interface](https://www.php-fig.org/psr/psr-3/)
7+
* Interface for logging libraries
8+
* Interfaces implemented in [php-fig/log](https://github.com/php-fig/log)
9+
* PSR-4: [Autoloader](https://www.php-fig.org/psr/psr-4/)
10+
* Autoloading classes from file paths
11+
* Interfaces implemented in [laminas/laminas-loader](https://github.com/laminas/laminas-loader)
12+
* PSR-6: [Caching Interface](https://www.php-fig.org/psr/psr-6/)
13+
* Interface for caching systems to improve the performance of any project
14+
* Interfaces implemented in [php-fig/cache](https://github.com/php-fig/cache)
15+
* PSR-7: [HTTP message interfaces](https://www.php-fig.org/psr/psr-7/)
16+
* Interfaces for representing HTTP messages and URIs for use with HTTP messages
17+
* Interfaces implemented in [php-fig/http-message](https://github.com/php-fig/http-message)
18+
* PSR-11: [Container interface](https://www.php-fig.org/psr/psr-11/)
19+
* Interface for dependency injection containers
20+
* Interfaces implemented in [php-fig/container](https://github.com/php-fig/container)
21+
* PSR-13: [Link definition interfaces](https://www.php-fig.org/psr/psr-13/)
22+
* Way of representing a hypermedia link independently of the serialization format
23+
* Interfaces implemented in [php-fig/link](https://github.com/php-fig/link)
24+
* PSR-14: [Event Dispatcher](https://www.php-fig.org/psr/psr-14/)
25+
* Mechanism for event-based extension and collaboration
26+
* Interfaces implemented in [php-fig/event-dispatcher](https://github.com/php-fig/event-dispatcher)
27+
* PSR-15: [HTTP Server Request Handlers](https://www.php-fig.org/psr/psr-15/)
28+
* Interfaces for HTTP server request handlers and HTTP server middleware components that use HTTP messages
29+
* Interfaces implemented in [php-fig/http-server-handler](https://github.com/php-fig/http-server-handler) and [php-fig/http-server-middleware](https://github.com/php-fig/http-server-middleware)
30+
* PSR-17: [HTTP Factories](https://www.php-fig.org/psr/psr-17/)
31+
* Standard for factories that create PSR-7 compliant HTTP objects
32+
* Interfaces implemented in [php-fig/http-factory](https://github.com/php-fig/http-factory)
33+
* PSR-18: [HTTP Client](https://www.php-fig.org/psr/psr-18/)
34+
* Interface for sending HTTP requests and receiving HTTP responses
35+
* Interfaces implemented in [php-fig/http-client](https://github.com/php-fig/http-client)
36+
* PSR-20: [Clock](https://www.php-fig.org/psr/psr-20/)
37+
* Interface for reading the system clock
38+
* Interfaces implemented in [php-fig/clock](https://github.com/php-fig/clock)

0 commit comments

Comments
 (0)