Skip to content

Commit e6df85f

Browse files
committed
New documentation files.
Signed-off-by: alexmerlin <[email protected]>
1 parent df102e9 commit e6df85f

38 files changed

+1061
-0
lines changed

.github/workflows/docs-build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: docs-build
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Build Docs
13+
uses: dotkernel/documentation-theme/github-actions/docs@main
14+
env:
15+
DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

api-doc/customize.md

Whitespace-only changes.

api-doc/intro.md

Whitespace-only changes.

api-doc/swagger.md

Whitespace-only changes.

api-primer/content-negotiation.md

Whitespace-only changes.

api-primer/content-validation.md

Whitespace-only changes.

api-primer/error-reporting.md

Whitespace-only changes.

api-primer/halprimer.md

Whitespace-only changes.

api-primer/http-negotiation.md

Whitespace-only changes.

api-primer/representation-formats.md

Whitespace-only changes.

api-primer/versioning.md

Whitespace-only changes.

api-primer/what-is-an-api.md

Whitespace-only changes.

auth/authentication-about.md

Whitespace-only changes.

auth/authentication-http-basic.md

Whitespace-only changes.

auth/authentication-oauth2.md

Whitespace-only changes.

auth/authorization.md

Whitespace-only changes.

auth/intro.md

Whitespace-only changes.

auth/user-differentiation.md

Whitespace-only changes.

content-negotiation/index.md

Whitespace-only changes.

content-validation/advanced.md

Whitespace-only changes.

content-validation/basic-usage.md

Whitespace-only changes.

content-validation/filtering.md

Whitespace-only changes.

content-validation/intro.md

Whitespace-only changes.

content-validation/validating.md

Whitespace-only changes.

deployment/intro.md

Whitespace-only changes.

docs/book/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ../../README.md
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Comparison between api-tools and Dotkernel API
2+
3+
| | API-TOOLS(APIGILITY) | DOTKERNEL API |
4+
|--------------------|------------------------------------------------|--------------------------------------------------------------------------|
5+
| URL | [api-tools](https://api-tools.getlaminas.org/) | [Dotkernel API](https://www.dotkernel.org) |
6+
| YEAR | 2012 | 2018 |
7+
| PHP VERSION | <= 8.2 | >= 8.1 |
8+
| ARHITECTURE | MVC, Event Driven | Middleware |
9+
| OSS Lifecycle | Archived | ![](https://img.shields.io/osslifecycle/dotkernel/api?style=flat&label=) |
10+
| STYLE | REST, RPC | REST |
11+
| VERSIONING | Yes | No |
12+
| DOCUMENTATION | Swagger (Automated) | Postman (Manual) |
13+
| LICENSE | BSD-3 | MIT |
14+
| DEFAULT DB LAYER | laminas-db | doctrine-orm |
15+
| AUTHORIZATION | ACL | RBAC-guard |
16+
| AUTHENTICATION | HTTP Basic/Digest <br/> OAuth2.0 | OAuth2.0 |
17+
| CI/CD | Yes | Yes |
18+
| Unit Tests | Yes | Yes |
19+
| Endpoint Generator | Yes | No |
20+
| PSR | PSR-7 | PSR-7, PSR-15 |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# File structure
2+
3+
It is a good practice to standardize the file structure of projects. This way it’s easier to keep a clean overview of multiple projects, and less time is wasted trying to find the correct class.
4+
5+
When using DotKernel API the following structure is recommended:
6+
7+
## Main directories
8+
9+
* `src` - should contain the source code files
10+
* `templates` - should contain the page templates and layouts
11+
* `data` - should contain project-related data (AVOID storing sensitive data on VCS)
12+
* `docs` - should contain project-related documentation
13+
14+
These directories reside in one of the following directories:
15+
16+
* if the Module is a composer package where the directories above are stored in the package’s root path, eg.: `/vendor/my-name/my-project-name/`
17+
* if the Module is an extension/component for the project, eg.: `/src/MyProjectName`
18+
19+
## The `src` directory
20+
21+
This directory contains all source code related to the Module. It should contain following directories, if they’re not empty:
22+
23+
* Handler - Action classes (similar to Controllers but can only perform one action)
24+
* Entity - For database entities
25+
* Service - Service classes
26+
* Collection - Database entities collections
27+
* Repository - Entity repository folder
28+
29+
> 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.
30+
31+
Other classes in the `src` directory may include `InputFilter`, `EventListener`, `Helper`, `Command`, `Factory` etc.
32+
33+
The `src` directory should also contain 2 files:
34+
35+
* `ConfigProvider.php` - Provides configuration data
36+
* `RoutesDelegator.php` - Module main routes entry file
37+
38+
## The `templates` directory
39+
40+
This directory contains the template files, used for example to help render e-mail templates.
41+
42+
> DotKernel API uses twig as Templating Engine. All template files have the extension .html.twig
43+
44+
## The `data` directory
45+
46+
This directory contains project-related data (such as cache, file uploads)
47+
48+
We recommend using the following directory structure:
49+
50+
* `data/cache` - location where caches are stored
51+
* `data/oauth` - encryption, private and public keys needed for authentication.
52+
* `data/lock` - folder where lock files generated by commands are stored, if enabled
53+
* `data/doctrine/fixtures` - folder for doctrine data fixtures
54+
* `data/doctrine/migrations` - folder for doctrine migrations
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Clone the project
2+
3+
Using your terminal, navigate inside the directory you want to download the project files into. Make sure that the directory is empty before proceeding to the download process. Once there, run the following command:
4+
5+
```shell
6+
git clone https://github.com/dotkernel/api.git .
7+
```
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Installation
2+
3+
## Install dependencies
4+
5+
```shell
6+
composer install
7+
```
8+
9+
## Development mode
10+
11+
If you're installing the project for development, make sure you have development mode enabled, by running:
12+
13+
```shell
14+
composer development-enable
15+
```
16+
17+
You can disable development mode by running:
18+
19+
```shell
20+
composer development-disable
21+
```
22+
23+
You can check if you have development mode enabled by running:
24+
25+
```shell
26+
composer development-status
27+
```
28+
29+
## Prepare config files
30+
31+
* duplicate `config/autoload/cors.local.php.dist` as `config/autoload/cors.local.php` <- if your API will be consumed by another application, make sure configure the `allowed_origins`
32+
* duplicate `config/autoload/local.php.dist` as `config/autoload/local.php`
33+
* duplicate `config/autoload/mail.local.php.dist` as `config/autoload/mail.local.php` <- if your API will send emails, make sure you fill in SMTP connection params
34+
* **optional**: in order to run/create tests, duplicate `config/autoload/local.test.php.dist` as `config/autoload/local.test.php` <- this creates a new in-memory database that your tests will run on.
35+
36+
## Setup database
37+
38+
Make sure you fill out the database credentials in `config/autoload/local.php` under `$databases['default']`.
39+
40+
## Running migrations
41+
42+
* create a new MySQL database - set collation to `utf8mb4_general_ci`
43+
* run the database migrations by using the following command:
44+
45+
```shell
46+
php vendor/bin/doctrine-migrations migrate
47+
```
48+
49+
This command will prompt you to confirm that you want to run it.
50+
51+
> 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]:
52+
53+
Hit `Enter` to confirm the operation.
54+
55+
## Executing fixtures
56+
57+
**Fixtures are used to seed the database with initial values and should be executed after migrating the database.**
58+
59+
To list all the fixtures, run:
60+
61+
```shell
62+
php bin/doctrine fixtures:list
63+
```
64+
65+
This will output all the fixtures in the order of execution.
66+
67+
To execute all fixtures, run:
68+
69+
```shell
70+
php bin/doctrine fixtures:execute
71+
```
72+
73+
To execute a specific fixture, run:
74+
75+
```shell
76+
php bin/doctrine fixtures:execute --class=FixtureClassName
77+
```
78+
79+
More details on how fixtures work can be found here: https://github.com/dotkernel/dot-data-fixtures#creating-fixtures
80+
81+
## Test the installation
82+
83+
```shell
84+
php -S 0.0.0.0:8080 -t public
85+
```
86+
87+
Sending a GET request to the [home page](http://0.0.0.0:8080/) should output the following message:
88+
89+
> {"message": "Welcome to DotKernel API!"}
90+
91+
## Running tests
92+
93+
The project has 2 types of tests: functional and unit tests, you can run both types at the same type by executing this command:
94+
95+
```shell
96+
php vendor/bin/phpunit
97+
```
98+
99+
## Running unit tests
100+
101+
```shell
102+
vendor/bin/phpunit --testsuite=UnitTests --testdox --colors=always
103+
```
104+
105+
## Running functional tests
106+
107+
```shell
108+
vendor/bin/phpunit --testsuite=FunctionalTests --testdox --colors=always
109+
```
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Introduction
2+
3+
Based on Enrico Zimuel’s Zend Expressive API – Skeleton example, DotKernel API runs on Laminas and Mezzio components and implements standards like PSR-3, PSR-4, PSR-7, PSR-11 and PSR-15.
4+
5+
Here is a list of the core components:
6+
7+
* Middleware Microframework (mezzio/mezzio)
8+
* Error Handler (dotkernel/dot-errorhandler)
9+
* Problem Details (mezzio/mezzio-problem-details)
10+
* CORS (mezzio/mezzio-cors)
11+
* Routing (mezzio/mezzio-fastroute)
12+
* Authentication (mezzio/mezzio-authentication)
13+
* Authorization (mezzio/mezzio-authorization)
14+
* Config Aggregator (laminas/laminas-config-aggregator)
15+
* Container (roave/psr-container-doctrine)
16+
* Annotations (dotkernel/dot-annotated-services)
17+
* Input Filter (laminas/laminas-inputfilter)
18+
* Doctrine 2 ORM (doctrine/orm)
19+
* Serializer/Deserializer (laminas/laminas-hydrator)
20+
* Paginator (laminas/laminas-paginator)
21+
* HAL (mezzio/mezzio-hal)
22+
* CLI (dotkernel/dot-cli)
23+
* TwigRenderer (mezzio/mezzio-twigrenderer)
24+
* Fixtures (dotkernel/dot-data-fixtures)
25+
* UUID (ramsey/uuid-doctrine)
26+
27+
## Doctrine 2 ORM
28+
29+
For the persistence in a relational database management system we chose Doctrine ORM (object-relational mapper).
30+
31+
The benefit of Doctrine for the programmer is the ability to focus on the object-oriented business logic and worry about persistence only as a secondary priority.
32+
33+
## Documentation
34+
35+
Our documentation is Postman based. We use the following files in which we store information about every available endpoint ready to be tested:
36+
37+
* documentation/DotKernel_API.postman_collection.json
38+
* documentation/DotKernel_API.postman_environment.json
39+
40+
## Hypertext Application Language
41+
42+
For our API payloads (a value object for describing the API resource, its relational links and any embedded/child resources related to it) we chose mezzio-hal.
43+
44+
## CORS
45+
46+
By using `MezzioCorsMiddlewareCorsMiddleware`, the CORS preflight will be recognized and the middleware will start to detect the proper CORS configuration. The Router is used to detect every allowed request method by executing a route match with all possible request methods. Therefore, for every preflight request, there is at least one Router request.
47+
48+
## OAuth 2.0
49+
50+
OAuth 2.0 is an authorization framework that enables applications to obtain limited access to user accounts on your DotKernel API. We are using mezzio/mezzio-authentication-oauth2 which provides OAuth 2.0 authentication for Mezzio and PSR-7/PSR-15 applications by using league/oauth2-server package.
51+
52+
## Email
53+
54+
It is not unlikely for an API to send emails depending on the use case. Here is another area where DotKernel API shines. Using `DotMailServiceMailService` provided by dotkernel/dot-mail you can easily send custom email templates.
55+
56+
## Configuration
57+
58+
From authorization at request route level to API keys for your application, you can find every configuration variable in the config directory.
59+
60+
Registering a new module can be done by including its ConfigProvider.php in config.php.
61+
62+
Brand new middlewares should go into pipeline.php. Here you can edit the order in which they run and find more info about the currently included ones.
63+
64+
You can further customize your api within the autoload directory where each configuration category has its own file.
65+
66+
## Routing
67+
68+
Each module has a `RoutesDelegator.php` file for managing existing routes inside that specific module. It also allows a quick way of adding new routes by providing the route path, Middlewares that the route will use and the route name.
69+
70+
You can allocate permissions per route name in order to restrict access for a user role to a specific route in `config/autoload/authorization.global.php`.
71+
72+
## Commands
73+
74+
For registering new commands first make sure your command class extends `SymfonyComponentConsoleCommandCommand`. Then you can enable it by registering it in `config/autoload/cli.global.php`.
75+
76+
## File locker
77+
78+
Here you will also find our brand-new file locker configuration, so you can easily turn it on or off (by default: `'enabled' => true`).
79+
80+
Note: The File Locker System will create a `command-{command-default-name}.lock` file which will not let another instance of the same command to run until the previous one has finished.
81+
82+
## PSR Standards
83+
84+
* [PSR-3](https://www.php-fig.org/psr/psr-3/): Logger Interface – the application uses `LoggerInterface` for error logging
85+
* [PSR-4](https://www.php-fig.org/psr/psr-4): Autoloader – the application locates classes using an autoloader
86+
* [PSR-7](https://www.php-fig.org/psr/psr-7): HTTP message interfaces – the handlers return `ResponseInterface`
87+
* [PSR-11](https://www.php-fig.org/psr/psr-11): Container interface – the application is container-based
88+
* [PSR-15](https://www.php-fig.org/psr/psr-15): HTTP Server Request Handlers – the handlers implement `RequestHandlerInterface`
89+
90+
## Tests
91+
92+
One of the best ways to ensure the quality of your product is to create and run functional and unit tests. You can find factory-made tests in the tests/AppTest/ folder, and you can also register your own.
93+
94+
We have 2 types of tests: functional and unit tests, you can run both types at the same type by executing this command:
95+
96+
```shell
97+
php vendor/bin/phpunit
98+
```
99+
100+
## Running unit tests
101+
102+
```shell
103+
vendor/bin/phpunit --testsuite=UnitTests --testdox --colors=always
104+
```
105+
106+
## Running functional tests
107+
108+
```shell
109+
vendor/bin/phpunit --testsuite=FunctionalTests --testdox --colors=always
110+
```

docs/book/v4/introduction/packages.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Packages
2+
3+
* `dotkernel/dot-annotated-services` - Dependency injection component using class attributes.
4+
* `dotkernel/dot-cache` - Cache component extending symfony-cache
5+
* `dotkernel/dot-cli` - Component for creating console applications based on laminas-cli
6+
* `dotkernel/dot-data-fixtures` - Provides a CLI interface for listing & executing doctrine data fixtures
7+
* `dotkernel/dot-errorhandler` - Logging Error Handler for Middleware Applications
8+
* `dotkernel/dot-mail` - Mail component based on laminas-mail
9+
* `dotkernel/dot-response-header` - Middleware for setting custom response headers.
10+
* `laminas/laminas-component-installer` - Composer plugin for injecting modules and configuration providers into application configuration
11+
* `laminas/laminas-config` - Provides a nested object property based user interface for accessing this configuration data within application code
12+
* `laminas/laminas-config-aggregator` - Lightweight library for collecting and merging configuration from different sources
13+
* `laminas/laminas-http` - Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests
14+
* `laminas/laminas-hydrator` - Serialize objects to arrays, and vice versa
15+
* `laminas/laminas-inputfilter` - Normalize and validate input sets from the web, APIs, the CLI, and more, including files
16+
* `laminas/laminas-paginator` - Paginate collections of data from arbitrary sources
17+
* `laminas/laminas-stdlib` - SPL extensions, array utilities, error handlers, and more
18+
* `laminas/laminas-text` - Create FIGlets and text-based tables
19+
* `mezzio/mezzio` - PSR-15 Middleware Microframework
20+
* `mezzio/mezzio-authentication-oauth2` - OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications
21+
* `mezzio/mezzio-authorization-acl` - laminas-permissions-acl adapter for mezzio-authorization
22+
* `mezzio/mezzio-authorization-rbac` - mezzio authorization rbac adapter for laminas/laminas-permissions-rbac
23+
* `mezzio/mezzio-cors` - CORS component for Mezzio and other PSR-15 middleware runners
24+
* `mezzio/mezzio-fastroute` - FastRoute integration for Mezzio
25+
* `mezzio/mezzio-hal` - Hypertext Application Language implementation for PHP and PSR-7
26+
* `mezzio/mezzio-problem-details` - Problem Details for PSR-7 HTTP APIs addressing the RFC 7807 standard
27+
* `mezzio/mezzio-twigrenderer` - Twig integration for Mezzio
28+
* `ramsey/uuid-doctrine` - Use ramsey/uuid as a Doctrine field type
29+
* `roave/psr-container-doctrine` - Doctrine Factories for PSR-11 Containers
30+
* `symfony/filesystem` - Provides basic utilities for the filesystem
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Server Requirements
2+
3+
For production, we highly recommend a *nix based system.
4+
5+
## Webserver
6+
7+
* Apache >= 2.2 **or** Nginx
8+
* mod_rewrite
9+
* .htaccess support `(AllowOverride All)`
10+
11+
## PHP >= 8.2
12+
13+
Both mod_php and FCGI (FPM) are supported.
14+
15+
## Required Settings and Modules & Extensions
16+
17+
* memory_limit >= 128M
18+
* upload_max_filesize and post_max_size >= 100M (depending on your data)
19+
* mbstring
20+
* CLI SAPI (for Cron Jobs)
21+
* Composer (added to $PATH)
22+
23+
## RDBMS
24+
25+
* MySQL / MariaDB >= 5.5.3
26+
27+
## Recommended extensions
28+
29+
* opcache
30+
* pdo_mysql or mysqli (if using MySQL or MariaDB as RDBMS)
31+
* dom - if working with markup files structure (html, xml, etc)
32+
* simplexml - working with xml files
33+
* gd, exif - if working with images
34+
* zlib, zip, bz2 - if compessing files
35+
* curl (required if APIs are used)

0 commit comments

Comments
 (0)