Skip to content

Commit

Permalink
Renaming from Rest Template to Rest Reference Architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Dec 9, 2023
1 parent 3d3e39f commit 90d5f3c
Show file tree
Hide file tree
Showing 38 changed files with 130 additions and 110 deletions.
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -11,27 +11,47 @@ 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:

- Uses [OpenAPI](https://swagger.io/specification/) specification for API documentation and endpoint creation.
- 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.
Expand All @@ -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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion builder/BaseScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Closure;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use RestTemplate\Psr11;
use RestReferenceArchitecture\Psr11;

class BaseScripts
{
Expand Down
10 changes: 5 additions & 5 deletions builder/PostCreateScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

// ------------------------------------------------
Expand Down Expand Up @@ -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
);
Expand Down
4 changes: 2 additions & 2 deletions builder/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use OpenApi\Generator;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use RestTemplate\Psr11;
use RestReferenceArchitecture\Psr11;

class Scripts extends BaseScripts
{
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -27,7 +27,7 @@
},
"autoload": {
"psr-4": {
"RestTemplate\\": "src/",
"RestReferenceArchitecture\\": "src/",
"Builder\\": "builder/"
}
},
Expand Down
10 changes: 5 additions & 5 deletions config/config-dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
2 changes: 1 addition & 1 deletion docs/functional_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions docs/psr11.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions docs/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
```
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion public/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ByJG\RestServer\HttpRequestHandler;
use ByJG\RestServer\Route\OpenApiRouteList;
use RestTemplate\Psr11;
use RestReferenceArchitecture\Psr11;

class App
{
Expand Down
Loading

0 comments on commit 90d5f3c

Please sign in to comment.