From 90d5f3cbbb8c328f83ff276e5e591a59249d5220 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sat, 9 Dec 2023 11:32:46 -0600 Subject: [PATCH] Renaming from Rest Template to Rest Reference Architecture --- README.md | 40 ++++++++++++++----- builder/BaseScripts.php | 2 +- builder/PostCreateScript.php | 10 ++--- builder/Scripts.php | 4 +- composer.json | 6 +-- config/config-dev.php | 10 ++--- docs/functional_test.md | 2 +- docs/getting_started.md | 4 +- docs/login.md | 2 +- docs/psr11.md | 4 +- docs/rest.md | 8 ++-- public/app.php | 2 +- public/docs/openapi.json | 32 +++++++-------- src/Model/Dummy.php | 4 +- src/Model/DummyHex.php | 4 +- src/Model/User.php | 4 +- src/OpenApiSpec.php | 2 +- src/Psr11.php | 2 +- src/Repository/BaseRepository.php | 6 +-- src/Repository/DummyHexRepository.php | 4 +- src/Repository/DummyRepository.php | 4 +- src/Repository/UserDefinition.php | 6 +-- src/Rest/DummyHexRest.php | 10 ++--- src/Rest/DummyRest.php | 10 ++--- src/Rest/Login.php | 12 +++--- src/Rest/Sample.php | 2 +- src/Rest/SampleProtected.php | 2 +- src/Rest/ServiceAbstractBase.php | 8 ++-- src/Util/FakeApiRequester.php | 4 +- src/Util/HexUuidLiteral.php | 2 +- src/Util/HexUuidMysqlLiteral.php | 2 +- tests/Functional/Rest/BaseApiTestCase.php | 2 +- tests/Functional/Rest/Credentials.php | 4 +- tests/Functional/Rest/DummyHexTest.php | 6 +-- tests/Functional/Rest/DummyTest.php | 4 +- tests/Functional/Rest/LoginTest.php | 6 +-- tests/Functional/Rest/SampleProtectedTest.php | 2 +- tests/Functional/Rest/SampleTest.php | 2 +- 38 files changed, 130 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index afd3a5d..6db4b13 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Boilerplate Project Template for RESTFul API +# Reference Architecture project for RESTFul services in PHP [![Build Status](https://github.com/byjg/php-rest-template/actions/workflows/build-app-image.yml/badge.svg?branch=master)](https://github.com/byjg/php-rest-template/actions/workflows/build-app-image.yml) [![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com) @@ -11,14 +11,34 @@ This project is a boilerplate for create Rest Applications API Ready to Use with ## What is a PHP Rest Template? +```mermaid +mindmap + root((Reference Architecture)) + PSR Standards + PSR-7 (WebRequests) + PSR-11 (Container & Dependency Injection) + PSR-16 & PSR-6 (Cache) + Authentication & Authorization + Decoupled Code + Database + (ORM Integration) + (Migration) + (Routing) + OpenAPI + (Rest Methods) + (Contract Testing) + (Documentation) + Error Handling +``` + It is a PHP-based RESTful API template or boilerplate that aims to simplify the development process of RESTful web services in PHP. It provides a foundation or starting point for building APIs following REST architectural principles. -Using PHP Rest Template you can focus on the business logic of your application and not in the infrastructure as for example: +Using this PHP Rest Reference Architecture you can focus on the business logic of your application and not in the infrastructure as for example: - Rapid Development: By offering a pre-defined structure and essential components, the template can expedite the process of building RESTful APIs in PHP. - Standardization: The template promotes consistency and adherence to RESTful design principles, making it easier for developers to understand and collaborate on the codebase. -- Customizability: Developers can modify and extend the template to fit their specific requirements, allowing for flexibility in implementing additional features or business logic. +- Customizable: Developers can modify and extend the template to fit their specific requirements, allowing for flexibility in implementing additional features or business logic. Key features and components: @@ -26,12 +46,12 @@ Key features and components: - Routing: Includes a routing system that helps map incoming HTTP requests to specific API endpoints or resources. - Middleware: It allows developers to add custom logic or perform operations before and after the request is processed. - Handling: The project offer utilities to handle and parse incoming requests, extract parameters, and handle request methods (GET, POST, PUT, DELETE, etc.). -- Response Formatting: It provide mechanisms to format and structure API responses, including JSON serialization, error handling, and status codes. +- Response Formatting: It provides mechanisms to format and structure API responses, including JSON serialization, error handling, and status codes. - Authentication and Authorization: The template include support for implementing authentication and authorization mechanisms to secure API endpoints using JWT. -- Database Integration: It offer integration for connecting to databases, executing queries, and managing data persistence. +- Database Integration: It offers integration for connecting to databases, executing queries, and managing data persistence. - Error Handling: The project include error handling mechanisms to properly handle and format error responses. -- Dependency Injection: It include support for dependency injection and inversion of control (IoC) containers. -- Testing: It include support for testing the API endpoints and resources, including unit testing and functional testing. +- Dependency Injection: It includes support for dependency injection and inversion of control (IoC) containers. +- Testing: It includes support for testing the API endpoints and resources, including unit testing and functional testing. - PHP Standards: PSR-7 (Http Message Interface), PSR-11 (Container), PSR-16 and PSR-6 (Cache Interface) and others. This project is not a framework. It is a template that you can use to create your own project. You can use the template as a starting point for your own project and customize it to fit your specific requirements. @@ -41,7 +61,7 @@ This project is not a framework. It is a template that you can use to create you This project install the follow components (click on the link for more details): - [Rest Methods API integrated with OpenAPI](docs/rest.md) -- [Functional Unit Tests of your Rest Method API](docs/functional_tests.md) +- [Functional Unit Tests of your Rest Method API](docs/functional_test.md) - [PSR-11 Container and different environments](docs/psr11.md) - [Dependency Injection](docs/psr11_di.md) - [Login Integration with JWT](docs/login.md) @@ -54,8 +74,8 @@ Here some examples of how to use the template: - [Getting Started, Installing and create a new project](docs/getting_started.md) - [Add a new Table](docs/getting_started_01_create_table.md) -- [Add a new Field](docs/getting_started_02_add_field.md) -- [Add a new Rest Method](docs/getting_started_03_add_rest_method.md) +- [Add a new Field](docs/getting_started_02_add_new_field.md) +- [Add a new Rest Method](docs/getting_started_03_create_rest_method.md) ---- [Open source ByJG](http://opensource.byjg.com) diff --git a/builder/BaseScripts.php b/builder/BaseScripts.php index 9429581..b8dee10 100644 --- a/builder/BaseScripts.php +++ b/builder/BaseScripts.php @@ -10,7 +10,7 @@ use Closure; use Psr\SimpleCache\InvalidArgumentException; use ReflectionException; -use RestTemplate\Psr11; +use RestReferenceArchitecture\Psr11; class BaseScripts { diff --git a/builder/PostCreateScript.php b/builder/PostCreateScript.php index 1e08225..727ec6e 100755 --- a/builder/PostCreateScript.php +++ b/builder/PostCreateScript.php @@ -41,7 +41,7 @@ public function execute($workdir, $namespace, $composerName, $phpVersion, $mysql $contents = file_get_contents($workdir . '/composer.json'); file_put_contents( $workdir . '/composer.json', - str_replace('byjg/resttemplate', $composerName, $contents) + str_replace('byjg/rest-reference-architecture', $composerName, $contents) ); // ------------------------------------------------ @@ -87,22 +87,22 @@ public function execute($workdir, $namespace, $composerName, $phpVersion, $mysql $objects = new RecursiveIteratorIterator($filter); foreach ($objects as $name => $object) { $contents = file_get_contents($name); - if (strpos($contents, 'RestTemplate') !== false) { + if (strpos($contents, 'RestReferenceArchitecture') !== false) { echo "$name\n"; // Replace inside Quotes $contents = preg_replace( - "/([\'\"])RestTemplate(.*?[\'\"])/", + "/([\'\"])RestReferenceArchitecture(.*?[\'\"])/", '$1' . str_replace('\\', '\\\\\\\\', $namespace) . '$2', $contents ); // Replace reserved name - $contents = str_replace('RestTemplate', $namespace, $contents); + $contents = str_replace('RestReferenceArchitecture', $namespace, $contents); // Replace reserved name $contents = str_replace( - 'resttemplate', + 'rest-reference-architecture', str_replace('/', '', $composerName), $contents ); diff --git a/builder/Scripts.php b/builder/Scripts.php index fdcb031..3f6b500 100755 --- a/builder/Scripts.php +++ b/builder/Scripts.php @@ -18,7 +18,7 @@ use OpenApi\Generator; use Psr\SimpleCache\InvalidArgumentException; use ReflectionException; -use RestTemplate\Psr11; +use RestReferenceArchitecture\Psr11; class Scripts extends BaseScripts { @@ -308,7 +308,7 @@ public function runCodeGenerator(array $arguments) } $data = [ - 'namespace' => 'RestTemplate', + 'namespace' => 'RestReferenceArchitecture', 'restTag' => ucwords(explode('_', strtolower($table))[0]), 'restPath' => str_replace('_', '/', strtolower($table)), 'className' => preg_replace_callback('/(?:^|_)(.?)/', function($match) { diff --git a/composer.json b/composer.json index a047447..8d5bff1 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "byjg/resttemplate", - "description": "Boilerplate project template for create RESTFul services with docker and database integrated", + "name": "byjg/rest-reference-architecture", + "description": "ByJG's Reference Architecture project for RESTFul services in PHP{ with docker and database integrated", "minimum-stability": "dev", "prefer-stable": true, "license": "MIT", @@ -27,7 +27,7 @@ }, "autoload": { "psr-4": { - "RestTemplate\\": "src/", + "RestReferenceArchitecture\\": "src/", "Builder\\": "builder/" } }, diff --git a/config/config-dev.php b/config/config-dev.php index cb8fb48..1c5f176 100644 --- a/config/config-dev.php +++ b/config/config-dev.php @@ -23,11 +23,11 @@ use ByJG\RestServer\Route\OpenApiRouteList; use ByJG\Util\JwtKeySecret; use ByJG\Util\JwtWrapper; -use RestTemplate\Model\User; -use RestTemplate\Psr11; -use RestTemplate\Repository\DummyHexRepository; -use RestTemplate\Repository\DummyRepository; -use RestTemplate\Repository\UserDefinition as UserDefinitionAlias; +use RestReferenceArchitecture\Model\User; +use RestReferenceArchitecture\Psr11; +use RestReferenceArchitecture\Repository\DummyHexRepository; +use RestReferenceArchitecture\Repository\DummyRepository; +use RestReferenceArchitecture\Repository\UserDefinition as UserDefinitionAlias; return [ diff --git a/docs/functional_test.md b/docs/functional_test.md index b317635..4d2cdd5 100644 --- a/docs/functional_test.md +++ b/docs/functional_test.md @@ -27,7 +27,7 @@ namespace Test\Functional\Rest; use ByJG\ApiTools\Base\Schema; -use RestTemplate\Util\FakeApiRequester; +use RestReferenceArchitecture\Util\FakeApiRequester; /** * Create a TestCase inherited from SwaggerTestCase diff --git a/docs/getting_started.md b/docs/getting_started.md index 37117da..6992862 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -29,14 +29,14 @@ Required PHP extensions: ```bash mkdir ~/tutorial -composer create-project byjg/resttemplate ~/tutorial 4.9.* +composer create-project byjg/rest-reference-architecture ~/tutorial 4.9.* ``` or the latest development version: ```bash mkdir ~/tutorial -composer -sdev create-project byjg/resttemplate ~/tutorial master +composer -sdev create-project byjg/rest-reference-architecture ~/tutorial master ``` This process will ask some questions to setup your project. You can use the following below as a guide: diff --git a/docs/login.md b/docs/login.md index 1648ddd..3b4c5db 100644 --- a/docs/login.md +++ b/docs/login.md @@ -24,7 +24,7 @@ CREATE TABLE `users` ( ); ``` -and the RestTemplate/Model/User.php has the mapping for this table. +and the RestReferenceArchitecture/Model/User.php has the mapping for this table. If you have the same fields but named differently, you can change the mapping in the `config/config_dev.php` file: diff --git a/docs/psr11.md b/docs/psr11.md index c158aa9..6bc0628 100644 --- a/docs/psr11.md +++ b/docs/psr11.md @@ -45,7 +45,7 @@ Psr11::container()->get('WEB_SERVER'); ## Defining the available environments -The available environments are defined in the class `RestTemplate\Psr11` in the method `environment()`. +The available environments are defined in the class `RestReferenceArchitecture\Psr11` in the method `environment()`. The project has 4 environments: @@ -58,7 +58,7 @@ The project has 4 environments: It means that the environment `dev` is the parent of `test` and `staging` and `staging` is the parent of `prod`. A configuration of the bottom environment will override the configuration of the parent environment. -You can change the environments in the `RestTemplate\Psr11` class as your needs. +You can change the environments in the `RestReferenceArchitecture\Psr11` class as your needs. ```php public static function environment() diff --git a/docs/rest.md b/docs/rest.md index dfdce36..50e1480 100644 --- a/docs/rest.md +++ b/docs/rest.md @@ -16,7 +16,7 @@ There are one requirement in your specification. You need for each method to def "paths": { "/login": { "post": { - "operationId": "POST::/login::RestTemplate\\Rest\\Login::mymethod", + "operationId": "POST::/login::RestReferenceArchitecture\\Rest\\Login::mymethod", } } ``` @@ -28,12 +28,12 @@ The `operationId` is composed by the following parts: - Namespace of the class (required) - Method of the class (required) -With definition above every request to `POST /login` will be handled by the method `mymethod` of the class `RestTemplate\Rest\Login`. +With definition above every request to `POST /login` will be handled by the method `mymethod` of the class `RestReferenceArchitecture\Rest\Login`. The only requirement is that the method must receive two parameters: ```php -namespace RestTemplate\Rest; +namespace RestReferenceArchitecture\Rest; use ByJG\RestServer\HttpRequest; use ByJG\RestServer\HttpResponse; @@ -53,7 +53,7 @@ We use the package byjg/restserver to handle the requests. Please refer to the d If you don't have an OpenAPI specification, you can document your application with PHPDOC and generate the OpenAPI specification from your code. ```php -namespace RestTemplate\Rest; +namespace RestReferenceArchitecture\Rest; use ByJG\RestServer\HttpRequest; use ByJG\RestServer\HttpResponse; diff --git a/public/app.php b/public/app.php index 6764398..21d057f 100644 --- a/public/app.php +++ b/public/app.php @@ -4,7 +4,7 @@ use ByJG\RestServer\HttpRequestHandler; use ByJG\RestServer\Route\OpenApiRouteList; -use RestTemplate\Psr11; +use RestReferenceArchitecture\Psr11; class App { diff --git a/public/docs/openapi.json b/public/docs/openapi.json index a825c77..5e9f425 100644 --- a/public/docs/openapi.json +++ b/public/docs/openapi.json @@ -25,7 +25,7 @@ "Dummyhex" ], "summary": "Get the DummyHex by id", - "operationId": "GET::/dummyhex/{id}::RestTemplate\\Rest\\DummyHexRest::getDummyHex", + "operationId": "GET::/dummyhex/{id}::RestReferenceArchitecture\\Rest\\DummyHexRest::getDummyHex", "parameters": [ { "name": "id", @@ -62,7 +62,7 @@ "Dummyhex" ], "summary": "List DummyHex", - "operationId": "GET::/dummyhex::RestTemplate\\Rest\\DummyHexRest::listDummyHex", + "operationId": "GET::/dummyhex::RestReferenceArchitecture\\Rest\\DummyHexRest::listDummyHex", "parameters": [ { "name": "page", @@ -137,7 +137,7 @@ "Dummyhex" ], "summary": "Update an existing DummyHex", - "operationId": "PUT::/dummyhex::RestTemplate\\Rest\\DummyHexRest::putDummyHex", + "operationId": "PUT::/dummyhex::RestReferenceArchitecture\\Rest\\DummyHexRest::putDummyHex", "requestBody": { "description": "The object DummyHex to be updated", "required": true, @@ -175,7 +175,7 @@ "Dummyhex" ], "summary": "Create a new DummyHex", - "operationId": "POST::/dummyhex::RestTemplate\\Rest\\DummyHexRest::postDummyHex", + "operationId": "POST::/dummyhex::RestReferenceArchitecture\\Rest\\DummyHexRest::postDummyHex", "requestBody": { "description": "The object DummyHex to be created", "required": true, @@ -240,7 +240,7 @@ "Dummy" ], "summary": "Get the Dummy by id", - "operationId": "GET::/dummy/{id}::RestTemplate\\Rest\\DummyRest::getDummy", + "operationId": "GET::/dummy/{id}::RestReferenceArchitecture\\Rest\\DummyRest::getDummy", "parameters": [ { "name": "id", @@ -277,7 +277,7 @@ "Dummy" ], "summary": "List Dummy", - "operationId": "GET::/dummy::RestTemplate\\Rest\\DummyRest::listDummy", + "operationId": "GET::/dummy::RestReferenceArchitecture\\Rest\\DummyRest::listDummy", "parameters": [ { "name": "page", @@ -352,7 +352,7 @@ "Dummy" ], "summary": "Update an existing Dummy", - "operationId": "PUT::/dummy::RestTemplate\\Rest\\DummyRest::putDummy", + "operationId": "PUT::/dummy::RestReferenceArchitecture\\Rest\\DummyRest::putDummy", "requestBody": { "description": "The object Dummy to be updated", "required": true, @@ -390,7 +390,7 @@ "Dummy" ], "summary": "Create a new Dummy", - "operationId": "POST::/dummy::RestTemplate\\Rest\\DummyRest::postDummy", + "operationId": "POST::/dummy::RestReferenceArchitecture\\Rest\\DummyRest::postDummy", "requestBody": { "description": "The object Dummy to be created", "required": true, @@ -455,7 +455,7 @@ "Login" ], "summary": "Do login", - "operationId": "POST::/login::RestTemplate\\Rest\\Login::post", + "operationId": "POST::/login::RestReferenceArchitecture\\Rest\\Login::post", "requestBody": { "description": "The Login Data", "required": true, @@ -525,7 +525,7 @@ "Login" ], "summary": "Refresh Token", - "operationId": "POST::/refreshtoken::RestTemplate\\Rest\\Login::refreshToken", + "operationId": "POST::/refreshtoken::RestReferenceArchitecture\\Rest\\Login::refreshToken", "responses": { "200": { "description": "The object rto be created", @@ -583,7 +583,7 @@ "Login" ], "summary": "Initialize the Password Request", - "operationId": "POST::/login/resetrequest::RestTemplate\\Rest\\Login::postResetRequest", + "operationId": "POST::/login/resetrequest::RestReferenceArchitecture\\Rest\\Login::postResetRequest", "requestBody": { "description": "The email to have the password reset", "content": { @@ -630,7 +630,7 @@ "Login" ], "summary": "Initialize the Password Request", - "operationId": "POST::/login/confirmcode::RestTemplate\\Rest\\Login::postConfirmCode", + "operationId": "POST::/login/confirmcode::RestReferenceArchitecture\\Rest\\Login::postConfirmCode", "requestBody": { "description": "The email and code to confirm the password reset", "content": { @@ -695,7 +695,7 @@ "Login" ], "summary": "Initialize the Password Request", - "operationId": "POST::/login/resetpassword::RestTemplate\\Rest\\Login::postResetPassword", + "operationId": "POST::/login/resetpassword::RestReferenceArchitecture\\Rest\\Login::postResetPassword", "requestBody": { "description": "The email and the new password", "content": { @@ -760,7 +760,7 @@ "zz_sample" ], "summary": "Simple ping", - "operationId": "GET::/sample/ping::RestTemplate\\Rest\\Sample::getPing", + "operationId": "GET::/sample/ping::RestReferenceArchitecture\\Rest\\Sample::getPing", "responses": { "200": { "description": "The object", @@ -790,7 +790,7 @@ "zz_sampleprotected" ], "summary": "Sample Ping Only Authenticated", - "operationId": "GET::/sampleprotected/ping::RestTemplate\\Rest\\SampleProtected::getPing", + "operationId": "GET::/sampleprotected/ping::RestReferenceArchitecture\\Rest\\SampleProtected::getPing", "responses": { "200": { "description": "The object", @@ -835,7 +835,7 @@ "zz_sampleprotected" ], "summary": "Sample Ping Only Admin", - "operationId": "GET::/sampleprotected/pingadm::RestTemplate\\Rest\\SampleProtected::getPingAdm", + "operationId": "GET::/sampleprotected/pingadm::RestReferenceArchitecture\\Rest\\SampleProtected::getPingAdm", "responses": { "200": { "description": "The object", diff --git a/src/Model/Dummy.php b/src/Model/Dummy.php index 2026580..16a6c8f 100644 --- a/src/Model/Dummy.php +++ b/src/Model/Dummy.php @@ -1,11 +1,11 @@ get(MailWrapperInterface::class); - $envelope = Psr11::container()->get('MAIL_ENVELOPE', [$json->email, "RestTemplate - Password Reset", "email_code.html", [ + $envelope = Psr11::container()->get('MAIL_ENVELOPE', [$json->email, "RestReferenceArchitecture - Password Reset", "email_code.html", [ "code" => trim(chunk_split($code, 1, ' ')), "expire" => 10 ]]); diff --git a/src/Rest/Sample.php b/src/Rest/Sample.php index 5fd4bf1..c085beb 100644 --- a/src/Rest/Sample.php +++ b/src/Rest/Sample.php @@ -1,6 +1,6 @@