Skip to content

Commit b5772dc

Browse files
authored
Merge pull request #385 from dotkernel/issue-384
Issue #384: Refactored handlers
2 parents 217831d + 4a106d2 commit b5772dc

File tree

87 files changed

+2420
-1817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2420
-1817
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 DotKernel (https://www.dotkernel.com)
3+
Copyright (c) 2024 Dotkernel (https://www.dotkernel.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
66
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# DotKernel API
1+
# Dotkernel API
22

3-
DotKernel API is a PHP skeleton app for building REST APIs using [Laminas](https://github.com/laminas) and [Mezzio](https://github.com/mezzio) components and implements standards like PSR-3, PSR-4, PSR-7, PSR-11 and PSR-15.
3+
Dotkernel API is a PHP skeleton app for building REST APIs using [Laminas](https://github.com/laminas) and [Mezzio](https://github.com/mezzio) components and implements standards like PSR-3, PSR-4, PSR-7, PSR-11 and PSR-15.
44

55
Dotkernel API is an alternative for legacy Laminas API Tools (formerly Apigility) applications, and is based on Enrico Zimuel's [Zend Expressive API - Skeleton example](https://github.com/ezimuel/zend-expressive-api).
66

@@ -122,13 +122,13 @@ Sending a GET request to the [home page](http://0.0.0.0:8080/) should output the
122122

123123
```text
124124
{
125-
"message": "DotKernel API version 5"
125+
"message": "Dotkernel API version 5"
126126
}
127127
```
128128

129129
## Documentation
130130

131-
In order to access DotKernel API documentation, check the provided [readme file](documentation/README.md).
131+
In order to access Dotkernel API documentation, check the provided [readme file](documentation/README.md).
132132

133133
Additionally, each CLI command available has it's own documentation:
134134

composer.json

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dotkernel/api",
33
"type": "project",
4-
"description": "DotKernel API",
4+
"description": "Dotkernel API",
55
"license": "MIT",
66
"homepage": "https://www.dotkernel.org",
77
"support": {
@@ -19,7 +19,7 @@
1919
],
2020
"authors": [
2121
{
22-
"name": "DotKernel Team",
22+
"name": "Dotkernel Team",
2323
"email": "[email protected]"
2424
}
2525
],
@@ -51,47 +51,48 @@
5151
"php": "~8.2.0 || ~8.3.0",
5252
"ext-gd": "*",
5353
"ext-json": "*",
54-
"dotkernel/dot-cache": "^4.0",
55-
"dotkernel/dot-cli": "^3.5.0",
56-
"dotkernel/dot-data-fixtures": "^1.2.2",
57-
"dotkernel/dot-dependency-injection": "^1.0",
54+
"dotkernel/dot-cache": "^4.3",
55+
"dotkernel/dot-cli": "^3.9.0",
56+
"dotkernel/dot-data-fixtures": "^1.4.0",
57+
"dotkernel/dot-dependency-injection": "^1.2",
5858
"dotkernel/dot-errorhandler": "^4.0.0",
59-
"dotkernel/dot-mail": "^5.1.0",
60-
"dotkernel/dot-response-header": "^3.2.3",
61-
"laminas/laminas-component-installer": "^3.4.0",
62-
"laminas/laminas-config-aggregator": "^1.14.0",
63-
"laminas/laminas-hydrator": "^4.15.0",
64-
"laminas/laminas-inputfilter": "^2.29.0",
65-
"laminas/laminas-stdlib": "^3.19.0",
66-
"mezzio/mezzio": "^3.19.0",
67-
"mezzio/mezzio-authentication-oauth2": "^2.8.0",
68-
"mezzio/mezzio-authorization-acl": "^1.10.0",
69-
"mezzio/mezzio-authorization-rbac": "^1.7.0",
70-
"mezzio/mezzio-cors": "^1.11.1",
71-
"mezzio/mezzio-fastroute": "^3.11.0",
72-
"mezzio/mezzio-hal": "^2.9",
73-
"mezzio/mezzio-problem-details": "^1.13.1",
74-
"mezzio/mezzio-twigrenderer": "^2.15.0",
59+
"dotkernel/dot-mail": "^5.3.0",
60+
"dotkernel/dot-response-header": "^3.4.1",
61+
"laminas/laminas-component-installer": "^3.5.0",
62+
"laminas/laminas-config-aggregator": "^1.18.0",
63+
"laminas/laminas-hydrator": "^4.16.0",
64+
"laminas/laminas-inputfilter": "^2.31.0",
65+
"laminas/laminas-stdlib": "^3.20.0",
66+
"mezzio/mezzio": "^3.20.1",
67+
"mezzio/mezzio-authentication-oauth2": "^2.11.0",
68+
"mezzio/mezzio-authorization-acl": "^1.11.0",
69+
"mezzio/mezzio-authorization-rbac": "^1.8.0",
70+
"mezzio/mezzio-cors": "^1.13.0",
71+
"mezzio/mezzio-fastroute": "^3.12.0",
72+
"mezzio/mezzio-hal": "^2.10",
73+
"mezzio/mezzio-problem-details": "^1.15.0",
74+
"mezzio/mezzio-twigrenderer": "^2.17.0",
7575
"ramsey/uuid-doctrine": "^2.1.0",
76-
"roave/psr-container-doctrine": "^5.2.1",
77-
"symfony/filesystem": "^7.0.3",
78-
"zircote/swagger-php": "^4.10"
76+
"roave/psr-container-doctrine": "^5.2.2",
77+
"symfony/filesystem": "^7.2.0",
78+
"zircote/swagger-php": "^5.0.6"
7979
},
8080
"require-dev": {
81-
"laminas/laminas-coding-standard": "^3.0",
82-
"laminas/laminas-development-mode": "^3.12.0",
83-
"mezzio/mezzio-tooling": "^2.9.0",
84-
"phpstan/phpstan": "^2.0",
85-
"phpstan/phpstan-doctrine": "^2.0",
86-
"phpstan/phpstan-phpunit": "^2.0",
87-
"phpunit/phpunit": "^10.5.10",
81+
"laminas/laminas-coding-standard": "^3.0.1",
82+
"laminas/laminas-development-mode": "^3.13.0",
83+
"mezzio/mezzio-tooling": "^2.10.1",
84+
"phpstan/phpstan": "^2.1.7",
85+
"phpstan/phpstan-doctrine": "^2.0.2",
86+
"phpstan/phpstan-phpunit": "^2.0.4",
87+
"phpunit/phpunit": "^10.5.45",
8888
"roave/security-advisories": "dev-latest",
89-
"symfony/var-dumper": "^7.1"
89+
"symfony/var-dumper": "^7.2.3"
9090
},
9191
"autoload": {
9292
"psr-4": {
9393
"Api\\Admin\\": "src/Admin/src/",
9494
"Api\\App\\": "src/App/src/",
95+
"Api\\Security\\": "src/Security/src/",
9596
"Api\\User\\": "src/User/src/",
9697
"Core\\Admin\\": "src/Core/src/Admin/src/",
9798
"Core\\App\\": "src/Core/src/App/src/",
@@ -105,12 +106,6 @@
105106
}
106107
},
107108
"scripts": {
108-
"post-update-cmd": [
109-
"php bin/composer-post-install-script.php"
110-
],
111-
"development-disable": "laminas-development-mode disable",
112-
"development-enable": "laminas-development-mode enable",
113-
"development-status": "laminas-development-mode status",
114109
"check": [
115110
"@cs-check",
116111
"@test",
@@ -119,6 +114,12 @@
119114
"clear-config-cache": "php bin/clear-config-cache.php",
120115
"cs-check": "phpcs",
121116
"cs-fix": "phpcbf",
117+
"development-disable": "laminas-development-mode disable",
118+
"development-enable": "laminas-development-mode enable",
119+
"development-status": "laminas-development-mode status",
120+
"post-update-cmd": [
121+
"php bin/composer-post-install-script.php"
122+
],
122123
"serve": "php -S 0.0.0.0:8080 -t public/",
123124
"static-analysis": "phpstan analyse --memory-limit 1G",
124125
"test": "phpunit --colors=always"

config/autoload/authorization.global.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,50 @@
3030
'permissions' => [
3131
AdminRole::ROLE_SUPERUSER => [],
3232
AdminRole::ROLE_ADMIN => [
33-
'admin.my-account.update',
34-
'admin.my-account.view',
35-
'admin.create',
36-
'admin.delete',
37-
'admin.list',
38-
'admin.update',
39-
'admin.view',
40-
'admin.role.list',
41-
'admin.role.view',
42-
'user.activate',
43-
'user.create',
44-
'user.list',
45-
'user.delete',
46-
'user.view',
47-
'user.update',
48-
'user.avatar.create',
49-
'user.avatar.delete',
50-
'user.avatar.view',
51-
'user.role.list',
52-
'user.role.view',
53-
'error.report',
54-
'home',
33+
'admin::list-admin',
34+
'admin::create-admin',
35+
'admin::delete-admin',
36+
'admin::view-admin',
37+
'admin::update-admin',
38+
'admin::list-role',
39+
'admin::view-role',
40+
'admin::view-account',
41+
'admin::update-account',
42+
'user::list-user',
43+
'user::create-user',
44+
'user::delete-user',
45+
'user::view-user',
46+
'user::update-user',
47+
'user::delete-user-avatar',
48+
'user::view-user-avatar',
49+
'user::create-user-avatar',
50+
'user::list-role',
51+
'user::view-role',
52+
'user::activate-user',
53+
'user::deactivate-user',
54+
'app::create-error-report',
55+
'app::view-index',
5556
],
5657
UserRole::ROLE_USER => [
57-
'user.my-account.delete',
58-
'user.my-account.update',
59-
'user.my-account.view',
60-
'user.my-avatar.create',
61-
'user.my-avatar.delete',
62-
'user.my-avatar.view',
58+
'user::delete-account',
59+
'user::view-account',
60+
'user::update-account',
61+
'user::delete-account-avatar',
62+
'user::view-account-avatar',
63+
'user::create-account-avatar',
6364
],
6465
UserRole::ROLE_GUEST => [
65-
'account.activate.request',
66-
'account.activate',
67-
'account.register',
68-
'account.modify-password',
69-
'account.recover-identity',
70-
'account.reset-password.validate',
71-
'account.reset-password.request',
72-
'security.generate-token',
73-
'security.refresh-token',
74-
'error.report',
75-
'home',
76-
'user.create',
66+
'app::create-error-report',
67+
'app::view-index',
68+
'user::activate-account',
69+
'user::request-activate-account',
70+
'user::recover-account',
71+
'user::check-account-reset-password',
72+
'user::update-account-reset-password',
73+
'user::create-account-reset-password',
74+
'user::create-account',
75+
'security::token',
76+
'security::token',
7777
],
7878
],
7979
],

config/autoload/cli.global.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return [
1212
'dot_cli' => [
1313
'version' => '1.0.0',
14-
'name' => 'DotKernel CLI',
14+
'name' => 'Dotkernel CLI',
1515
'commands' => [
1616
DemoCommand::getDefaultName() => DemoCommand::class,
1717
RouteListCommand::getDefaultName() => RouteListCommand::class,

config/autoload/local.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $databases = [
2020

2121
return [
2222
'application' => [
23-
'name' => 'DotKernel API',
23+
'name' => 'Dotkernel API',
2424
'url' => $baseUrl,
2525
'versioning' => [
2626
'documentation_url' => 'https://docs.dotkernel.org/api-documentation/v5/core-features/versioning',

config/autoload/mail.global.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
/**
7+
* Dotkernel mail module configuration
8+
* Note that many of these options can be set programmatically too, when sending mail messages actually that is
9+
* what you'll usually do, these configs provide just defaults and options that remain the same for all mails
10+
*/
11+
'dot_mail' => [
12+
//the key is the mail service name, this is the default one, which does not extend any configuration
13+
'default' => [
14+
//message configuration
15+
'message_options' => [
16+
//from email address of the email
17+
'from' => '',
18+
//from name to be displayed instead of from address
19+
'from_name' => '',
20+
//reply-to email address of the email
21+
'reply_to' => '',
22+
//replyTo name to be displayed instead of the address
23+
'reply_to_name' => '',
24+
//destination email address as string or a list of email addresses
25+
'to' => [],
26+
//copy destination addresses
27+
'cc' => [],
28+
//hidden copy destination addresses
29+
'bcc' => [],
30+
//email subject
31+
'subject' => '',
32+
//body options - content can be plain text, HTML
33+
'body' => [
34+
'content' => '',
35+
'charset' => 'utf-8',
36+
],
37+
//attachments config
38+
'attachments' => [
39+
'files' => [],
40+
'dir' => [
41+
'iterate' => false,
42+
'path' => 'data/mail/attachments',
43+
'recursive' => false,
44+
],
45+
],
46+
],
47+
/**
48+
* the mail transport to use can be any class implementing
49+
* Symfony\Component\Mailer\Transport\TransportInterface
50+
*
51+
* for standard mail transports, you can use these aliases:
52+
* - sendmail => Symfony\Component\Mailer\Transport\SendmailTransport
53+
* - esmtp => Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport
54+
*
55+
* defaults to sendmail
56+
**/
57+
'transport' => 'sendmail',
58+
//options that will be used only if esmtp adapter is used
59+
'smtp_options' => [
60+
//hostname or IP address of the mail server
61+
'host' => '',
62+
//port of the mail server - 587 or 465 for secure connections
63+
'port' => 587,
64+
'connection_config' => [
65+
//the smtp authentication identity
66+
'username' => '',
67+
//the smtp authentication credential
68+
'password' => '',
69+
//to disable auto_tls set tls key to false
70+
//it's not recommended to disable TLS while connecting to an SMTP server
71+
'tls' => null,
72+
],
73+
],
74+
],
75+
// option to log the SENT emails
76+
'log' => [
77+
'sent' => getcwd() . '/log/mail/sent.log',
78+
],
79+
],
80+
];

config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class_exists(Mezzio\Tooling\ConfigProvider::class)
5353
Core\User\ConfigProvider::class,
5454
Api\Admin\ConfigProvider::class,
5555
Api\App\ConfigProvider::class,
56+
Api\Security\ConfigProvider::class,
5657
Api\User\ConfigProvider::class,
5758

5859
// Load application config in a pre-defined order in such a way that local settings

config/pipeline.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
declare(strict_types=1);
44

5-
use Api\App\Handler\NotFoundHandler;
5+
use Api\App\Handler\GetNotFoundViewHandler;
66
use Api\App\Middleware\AuthenticationMiddleware;
77
use Api\App\Middleware\AuthorizationMiddleware;
88
use Api\App\Middleware\ContentNegotiationMiddleware;
99
use Api\App\Middleware\DeprecationMiddleware;
10+
use Api\App\Middleware\ResponseMiddleware;
1011
use Dot\ErrorHandler\ErrorHandlerInterface;
1112
use Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware;
1213
use Mezzio\Application;
@@ -79,10 +80,12 @@
7980
// - route-based validation
8081
// - etc.
8182

83+
$app->pipe(ResponseMiddleware::class);
84+
8285
// Register the dispatch middleware in the middleware pipeline
8386
$app->pipe(DispatchMiddleware::class);
8487
// At this point, if no Response is returned by any middleware, the
8588
// NotFoundHandler kicks in; alternately, you can provide other fallback
8689
// middleware to execute.
87-
$app->pipe(NotFoundHandler::class);
90+
$app->pipe(GetNotFoundViewHandler::class);
8891
};

0 commit comments

Comments
 (0)