Skip to content

Commit c734b8c

Browse files
committed
rollback improvements
2 parents 35ecc61 + 590fb49 commit c734b8c

31 files changed

+544
-233
lines changed

.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# NOTIFICATION
2+
SLACK_API_WEBHOOK=Your_webhook_here
3+
4+
# DATE
5+
DEFAULT_DATE_TIMEZONE=America/Sao_Paulo
6+
7+
# DATABASE
8+
DATABASE_USER=xpto
9+
DATABASE_PASSWORD=xpto_password
10+
DATABASE_NAME=xpto_database_name
11+
DATABASE_DRIVER=xpto_driver
12+
DATABASE_HOST=xpto_host
13+
DATABASE_SCHEMA=xpto_schema

.github/workflows/build.yml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
name: CI
2-
3-
on:
4-
push:
5-
branches:
6-
- master
7-
8-
jobs:
9-
build:
10-
runs-on: [ ubuntu-latest ]
11-
steps:
12-
- uses: actions/checkout@v1
13-
14-
- name: Cache PHP dependencies
15-
uses: actions/cache@v1
16-
with:
17-
path: vendor
18-
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
19-
20-
- uses: php-actions/composer@master
21-
22-
- name: Run Tests
23-
run: composer tests-exclude-notification
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
runs-on: [ ubuntu-latest ]
11+
steps:
12+
- uses: actions/checkout@v1
13+
14+
- name: Cache PHP dependencies
15+
uses: actions/cache@v1
16+
with:
17+
path: vendor
18+
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
19+
20+
- uses: php-actions/composer@master
21+
22+
- name: Run Tests
23+
run: composer test

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
.idea
2-
vendor
1+
# FOLDERS
2+
.idea
3+
vendor
4+
5+
# FILES
6+
.phpunit.result.cache

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8-fpm-buster
2-
3-
RUN apt-get update && apt-get install -y curl git
4-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
1+
FROM php:8-fpm-buster
2+
3+
RUN apt-get update && apt-get install -y curl git
4+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

README.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<h1 align="center">Simple PHP Router</h1>
2-
3-
<p align="center">
4-
<a href="https://github.com/mathleite/simple-php-router">
5-
<img src="https://github.com/mathleite/simple-php-router/workflows/CI/badge.svg" alt="Workflow badge">
6-
</a>
7-
</p>
8-
9-
| SETUP |
10-
|:------:|
11-
| Nginx |
12-
| PHP8 |
13-
| Docker |
14-
15-
16-
#### Start app
17-
- Build Docker containers
18-
```docker
19-
docker-compose up --build -d
20-
```
21-
22-
- Install Composer dependencies
23-
```docker
24-
docker exec -it php composer install
25-
```
26-
27-
### Create your own routes
28-
29-
`app/Route/index.php`
30-
31-
```php
32-
$route->registry('/greet', \App\Greet\GreetController::class, 'index');
33-
```
34-
35-
Where:
36-
- `/user` is the **route** that you want to *register*;
37-
- `\App\Greet\GreetController::class` is the *Controller* **namespace**;
38-
- `index` is a controller *function*
1+
<h1 align="center">Simple PHP Router</h1>
2+
3+
<p align="center">
4+
<a href="https://github.com/mathleite/simple-php-router">
5+
<img src="https://github.com/mathleite/simple-php-router/workflows/CI/badge.svg" alt="Workflow badge">
6+
</a>
7+
</p>
8+
9+
| SETUP |
10+
|:------:|
11+
| Nginx |
12+
| PHP8 |
13+
| Docker |
14+
15+
16+
#### Start app
17+
- Build Docker containers
18+
```docker
19+
docker-compose up --build -d
20+
```
21+
22+
- Install Composer dependencies
23+
```docker
24+
docker exec -it php composer install
25+
```
26+
27+
### Create your own routes
28+
29+
`app/Route/index.php`
30+
31+
```php
32+
$route->registry('/greet', \App\Greet\GreetController::class, 'index');
33+
```
34+
35+
Where:
36+
- `/user` is the **route** that you want to *register*;
37+
- `\App\Greet\GreetController::class` is the *Controller* **namespace**;
38+
- `index` is a controller *function*

app/Base/ControllerInterface.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<?php
2-
3-
4-
namespace App\Base;
5-
6-
7-
interface ControllerInterface
8-
{
9-
public static function index(): void;
10-
}
1+
<?php
2+
3+
4+
namespace App\Base;
5+
6+
7+
interface ControllerInterface
8+
{
9+
public static function index(): void;
10+
}

app/Date/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
date_default_timezone_set(getenv('DEFAULT_DATE_TIMEZONE'));

app/DotEnvLoader/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__ . '/../../');
4+
$dotenv->load();

app/Greet/GreetController.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<?php
2-
3-
namespace App\Greet;
4-
5-
use App\Base\ControllerInterface;
6-
7-
class GreetController implements ControllerInterface
8-
{
9-
public static function index(): void
10-
{
11-
echo 'Hi! I am a index function :)';
12-
}
13-
14-
}
1+
<?php
2+
3+
namespace App\Greet;
4+
5+
use App\Base\ControllerInterface;
6+
7+
class GreetController implements ControllerInterface
8+
{
9+
public static function index(): void
10+
{
11+
echo 'Hi! I am a index function :)';
12+
}
13+
14+
}

app/Greet/UserModel.php

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
4+
namespace App\Notification;
5+
6+
7+
use App\Notification\Client\HTTPClientAdapterInterface;
8+
use App\Notification\Client\ResponseAdapterInterface;
9+
10+
interface AppNotificationInterface
11+
{
12+
public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType);
13+
14+
public function notify(): ResponseAdapterInterface;
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
4+
namespace App\Notification\Client\Guzzle;
5+
6+
7+
use App\Notification\Client\HTTPClientAdapterInterface;
8+
use App\Notification\Client\ResponseAdapterInterface;
9+
use GuzzleHttp\Client;
10+
use Psr\Http\Message\ResponseInterface;
11+
12+
class GuzzleHTTPClient implements HTTPClientAdapterInterface
13+
{
14+
private Client $client;
15+
16+
public function __construct()
17+
{
18+
$this->client = new Client();
19+
}
20+
21+
public function post(string $url, array $params): ResponseAdapterInterface
22+
{
23+
$clientResponse = $this->client->post(
24+
$url,
25+
[
26+
'json' => $params
27+
]
28+
);
29+
30+
return new GuzzleResponse($clientResponse);
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
4+
namespace App\Notification\Client\Guzzle;
5+
6+
7+
use App\Notification\Client\ResponseAdapterInterface;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
class GuzzleResponse implements ResponseAdapterInterface
11+
{
12+
private ResponseInterface $clientResponse;
13+
14+
public function __construct(ResponseInterface $clientResponse)
15+
{
16+
$this->clientResponse = $clientResponse;
17+
}
18+
19+
public function getResponse(): array
20+
{
21+
return self::sanitizeResponse($this->clientResponse);
22+
}
23+
24+
private static function sanitizeResponse(ResponseInterface $guzzleResponse): array
25+
{
26+
return [
27+
'status_code' => $guzzleResponse->getStatusCode(),
28+
'message' => $guzzleResponse->getReasonPhrase()
29+
];
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
4+
namespace App\Notification\Client;
5+
6+
7+
interface HTTPClientAdapterInterface
8+
{
9+
public function post(string $url, array $params): ResponseAdapterInterface;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
4+
namespace App\Notification\Client;
5+
6+
7+
interface ResponseAdapterInterface
8+
{
9+
public function getResponse(): array;
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
4+
namespace App\Notification;
5+
6+
/**
7+
* Class MessageTypeEnum
8+
*
9+
* @package App\Notification
10+
* @method static string ERROR()
11+
*/
12+
final class NotificationTypeEnum
13+
{
14+
private const ERROR = 'error';
15+
16+
public static function __callStatic($name, $arguments): string
17+
{
18+
return constant('self::' . strtoupper($name));
19+
}
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
4+
namespace App\Notification\Slack;
5+
6+
7+
use App\Notification\AppNotificationInterface;
8+
use App\Notification\Client\HTTPClientAdapterInterface;
9+
use App\Notification\Client\ResponseAdapterInterface;
10+
11+
final class SlackNotification implements AppNotificationInterface
12+
{
13+
private SlackStylizedMessageCreator $message;
14+
private HTTPClientAdapterInterface $client;
15+
16+
public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType)
17+
{
18+
$this->message = new SlackStylizedMessageCreator($message, $messageType);
19+
$this->client = $client;
20+
}
21+
22+
public function notify(): ResponseAdapterInterface
23+
{
24+
return $this->client->post(
25+
getenv('SLACK_API_WEBHOOK'),
26+
$this->message->getStructuredMessage()
27+
);
28+
}
29+
}

0 commit comments

Comments
 (0)