Skip to content

Commit 02e1ad6

Browse files
committed
More adjustents
1 parent 94e2886 commit 02e1ad6

File tree

14 files changed

+102
-50
lines changed

14 files changed

+102
-50
lines changed

.github/workflows/build-app-image.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ jobs:
5757

5858
steps:
5959
- name: Checkout repository
60-
uses: actions/checkout@v3
60+
uses: actions/checkout@v4
6161

6262
- name: Set up QEMU
63-
uses: docker/setup-qemu-action@v2
63+
uses: docker/setup-qemu-action@v3
6464

6565
- name: Set up Docker Buildx
66-
uses: docker/setup-buildx-action@v2
66+
uses: docker/setup-buildx-action@v3
6767

6868
# Login against a Docker registry to pull the GHCR image
6969
# https://github.com/docker/login-action
7070
- name: Log into registry
71-
uses: docker/login-action@v2
71+
uses: docker/login-action@v3
7272
with:
7373
registry: ${{ env.REGISTRY }}
7474
username: ${{ github.actor }}
@@ -85,7 +85,7 @@ jobs:
8585
# Build image locally to enable to run the test
8686
# https://github.com/docker/build-push-action
8787
- name: Build Docker image
88-
uses: docker/build-push-action@v4
88+
uses: docker/build-push-action@v5
8989
with:
9090
context: .
9191
file: docker/Dockerfile

builder/BaseScripts.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class BaseScripts
1616
{
17-
protected $workdir;
17+
protected string|false $workdir;
1818
protected string $systemOs;
1919

2020
public function __construct()
@@ -47,9 +47,9 @@ public function fixDir($command)
4747
/**
4848
* Execute the given command by displaying console output live to the user.
4949
*
50-
* @param string|array $cmd : command to be executed
51-
* @return array exit_status : exit status of the executed command
52-
* output : console output of the executed command
50+
* @param array|string $cmd : command to be executed
51+
* @return array|null exit_status : exit status of the executed command
52+
* output : console output of the executed command
5353
* @throws ConfigException
5454
* @throws ConfigNotFoundException
5555
* @throws DependencyInjectionException
@@ -58,7 +58,7 @@ public function fixDir($command)
5858
* @throws KeyNotFoundException
5959
* @throws ReflectionException
6060
*/
61-
protected function liveExecuteCommand($cmd): ?array
61+
protected function liveExecuteCommand(array|string $cmd): ?array
6262
{
6363
// while (@ ob_end_flush()); // end all output buffers if any
6464

builder/PostCreateScript.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
use ByJG\JwtWrapper\JwtWrapper;
77
use ByJG\Util\Uri;
88
use Composer\Script\Event;
9+
use Exception;
910
use RecursiveCallbackFilterIterator;
1011
use RecursiveDirectoryIterator;
1112
use RecursiveIteratorIterator;
1213

1314
class PostCreateScript
1415
{
15-
public function execute($workdir, $namespace, $composerName, $phpVersion, $mysqlConnection, $timezone)
16+
public function execute($workdir, $namespace, $composerName, $phpVersion, $mysqlConnection, $timezone): void
1617
{
1718
// ------------------------------------------------
18-
// Defining function to interatively walking through the directories
19+
// Defining function to interactively walking through the directories
1920
$directory = new RecursiveDirectoryIterator($workdir);
2021
$filter = new RecursiveCallbackFilterIterator($directory, function ($current/*, $key, $iterator*/) {
2122
// Skip hidden files and directories.
@@ -88,12 +89,12 @@ public function execute($workdir, $namespace, $composerName, $phpVersion, $mysql
8889
$objects = new RecursiveIteratorIterator($filter);
8990
foreach ($objects as $name => $object) {
9091
$contents = file_get_contents($name);
91-
if (strpos($contents, 'RestReferenceArchitecture') !== false) {
92+
if (str_contains($contents, 'RestReferenceArchitecture')) {
9293
echo "$name\n";
9394

9495
// Replace inside Quotes
9596
$contents = preg_replace(
96-
"/([\'\"])RestReferenceArchitecture(.*?[\'\"])/",
97+
"/(['\"])RestReferenceArchitecture(.*?['\"])/",
9798
'$1' . str_replace('\\', '\\\\\\\\', $namespace) . '$2',
9899
$contents
99100
);
@@ -117,6 +118,11 @@ public function execute($workdir, $namespace, $composerName, $phpVersion, $mysql
117118
}
118119
}
119120

121+
/**
122+
* @param Event $event
123+
* @return void
124+
* @throws Exception
125+
*/
120126
public static function run(Event $event)
121127
{
122128
$workdir = realpath(__DIR__ . '/..');
@@ -129,35 +135,35 @@ public static function run(Event $event)
129135
if (in_array($arg, $validPHPVersions)) {
130136
return $arg;
131137
}
132-
throw new \Exception('Only the PHP versions ' . implode(', ', $validPHPVersions) . ' are supported');
138+
throw new Exception('Only the PHP versions ' . implode(', ', $validPHPVersions) . ' are supported');
133139
};
134140

135141
$validateNamespace = function ($arg) {
136142
if (empty($arg) || !preg_match('/^[A-Z][a-zA-Z0-9]*$/', $arg)) {
137-
throw new \Exception('Namespace must be one word in CamelCase');
143+
throw new Exception('Namespace must be one word in CamelCase');
138144
}
139145
return $arg;
140146
};
141147

142148
$validateComposer = function ($arg) {
143149
if (empty($arg) || !preg_match('/^[a-z0-9-]+\/[a-z0-9-]+$/', $arg)) {
144-
throw new \Exception('Invalid Composer name');
150+
throw new Exception('Invalid Composer name');
145151
}
146152
return $arg;
147153
};
148154

149155
$validateURI = function ($arg) {
150156
$uri = new Uri($arg);
151157
if (empty($uri->getScheme())) {
152-
throw new \Exception('Invalid URI');
158+
throw new Exception('Invalid URI');
153159
}
154160
Factory::getRegisteredDrivers($uri->getScheme());
155161
return $arg;
156162
};
157163

158164
$validateTimeZone = function ($arg) {
159165
if (empty($arg) || !in_array($arg, timezone_identifiers_list())) {
160-
throw new \Exception('Invalid Timezone');
166+
throw new Exception('Invalid Timezone');
161167
}
162168
return $arg;
163169
};

builder/Scripts.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ByJG\DbMigration\Database\MySqlDatabase;
1212
use ByJG\DbMigration\Exception\InvalidMigrationFile;
1313
use ByJG\DbMigration\Migration;
14+
use ByJG\JinjaPhp\Exception\TemplateParseException;
1415
use ByJG\JinjaPhp\Loader\FileSystemLoader;
1516
use ByJG\Util\Uri;
1617
use Composer\Script\Event;
@@ -39,7 +40,7 @@ public function __construct()
3940
* @throws KeyNotFoundException
4041
* @throws ReflectionException
4142
*/
42-
public static function migrate(Event $event)
43+
public static function migrate(Event $event): void
4344
{
4445
$migrate = new Scripts();
4546
$migrate->runMigrate($event->getArguments());
@@ -53,7 +54,7 @@ public static function migrate(Event $event)
5354
* @throws KeyNotFoundException
5455
* @throws ReflectionException
5556
*/
56-
public static function genOpenApiDocs(Event $event)
57+
public static function genOpenApiDocs(Event $event): void
5758
{
5859
$build = new Scripts();
5960
$build->runGenOpenApiDocs($event->getArguments());
@@ -62,14 +63,16 @@ public static function genOpenApiDocs(Event $event)
6263
/**
6364
* @param Event $event
6465
* @return void
66+
* @throws ConfigException
6567
* @throws ConfigNotFoundException
6668
* @throws DependencyInjectionException
6769
* @throws InvalidArgumentException
70+
* @throws InvalidDateException
6871
* @throws KeyNotFoundException
6972
* @throws ReflectionException
70-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
73+
* @throws TemplateParseException
7174
*/
72-
public static function codeGenerator(Event $event)
75+
public static function codeGenerator(Event $event): void
7376
{
7477
$build = new Scripts();
7578
$build->runCodeGenerator($event->getArguments());
@@ -86,6 +89,7 @@ public static function codeGenerator(Event $event)
8689
* @throws ReflectionException
8790
* @throws ConfigException
8891
* @throws InvalidDateException
92+
* @throws Exception
8993
*/
9094
public function runMigrate($arguments): void
9195
{
@@ -179,12 +183,14 @@ public function runGenOpenApiDocs(array $arguments): void
179183
/**
180184
* @param array $arguments
181185
* @return void
186+
* @throws ConfigException
182187
* @throws ConfigNotFoundException
183188
* @throws DependencyInjectionException
184189
* @throws InvalidArgumentException
190+
* @throws InvalidDateException
185191
* @throws KeyNotFoundException
186192
* @throws ReflectionException
187-
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
193+
* @throws TemplateParseException
188194
* @throws Exception
189195
*/
190196
public function runCodeGenerator(array $arguments): void

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"migrate": "Builder\\Scripts::migrate",
3737
"codegen": "Builder\\Scripts::codeGenerator",
3838
"openapi": "Builder\\Scripts::genOpenApiDocs",
39-
"compile": "composer run openapi && composer run test",
39+
"compile": "git pull && composer run openapi && composer run test",
4040
"up-local-dev": "docker compose -f docker-compose-dev.yml up -d",
4141
"down-local-dev": "docker compose -f docker-compose-dev.yml down",
4242
"post-create-project-cmd": "Builder\\PostCreateScript::run"

config/config-dev.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ API_SERVER=localhost
55
API_SCHEMA=http
66
DBDRIVER_CONNECTION=mysql://root:mysqlp455w0rd@mysql-container/mydb
77
EMAIL_CONNECTION=smtp://username:password@mail.example.com
8-
EMAIL_TRANSACTIONAL_FROM=No Reply <noreply@kexample.com>
8+
EMAIL_TRANSACTIONAL_FROM='No Reply <noreply@kexample.com>'
99
CORS_SERVERS=.*

config/config-prod.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

33
use ByJG\Config\DependencyInjection as DI;
4+
use ByJG\JwtWrapper\JwtHashHmacSecret;
45
use ByJG\JwtWrapper\JwtKeyInterface;
56

67
return [
7-
JwtKeyInterface::class => DI::bind(\ByJG\JwtWrapper\JwtHashHmacSecret::class)
8+
JwtKeyInterface::class => DI::bind(JwtHashHmacSecret::class)
89
->withConstructorArgs(['jwt_super_secret_key'])
910
->toSingleton(),
1011
];

config/config-staging.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
use ByJG\Cache\Psr16\BaseCacheEngine;
44
use ByJG\Cache\Psr16\FileSystemCacheEngine;
55
use ByJG\Config\DependencyInjection as DI;
6+
use ByJG\JwtWrapper\JwtHashHmacSecret;
67
use ByJG\JwtWrapper\JwtKeyInterface;
78

89
return [
910

1011
BaseCacheEngine::class => DI::bind(FileSystemCacheEngine::class)->toSingleton(),
1112

12-
JwtKeyInterface::class => DI::bind(\ByJG\JwtWrapper\JwtHashHmacSecret::class)
13+
JwtKeyInterface::class => DI::bind(JwtHashHmacSecret::class)
1314
->withConstructorArgs(['jwt_super_secret_key'])
1415
->toSingleton(),
1516

config/config-test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

33
use ByJG\Config\DependencyInjection as DI;
4+
use ByJG\JwtWrapper\JwtHashHmacSecret;
45
use ByJG\JwtWrapper\JwtKeyInterface;
56

67
return [
7-
JwtKeyInterface::class => DI::bind(\ByJG\JwtWrapper\JwtHashHmacSecret::class)
8+
JwtKeyInterface::class => DI::bind(JwtHashHmacSecret::class)
89
->withConstructorArgs(['jwt_super_secret_key'])
910
->toSingleton(),
1011
];

docker/fpm/php/custom.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
expose_php = off
2+
13
date.timezone = UTC
24
max_execution_time = 300
35

src/Model/User.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
namespace RestReferenceArchitecture\Model;
44

5+
use ByJG\Authenticate\Definition\PasswordDefinition;
56
use ByJG\Authenticate\Model\UserModel;
67
use ByJG\Authenticate\Model\UserPropertiesModel;
8+
use ByJG\MicroOrm\Attributes\TableAttribute;
79
use ByJG\MicroOrm\Literal\HexUuidLiteral;
10+
use Exception;
811
use InvalidArgumentException;
912
use OpenApi\Attributes as OA;
13+
use RestReferenceArchitecture\Psr11;
1014

15+
#[TableAttribute("users")]
1116
#[OA\Schema(required: ["email"], type: "object", xml: new OA\Xml(name: "User"))]
1217
class User extends UserModel
1318
{
@@ -89,10 +94,13 @@ class User extends UserModel
8994
* @param string $username
9095
* @param string $password
9196
* @param string $admin
97+
* @throws Exception
9298
*/
9399
public function __construct(string $name = "", string $email = "", string $username = "", string $password = "", string $admin = "no")
94100
{
95101
parent::__construct($name, $email, $username, $password, $admin);
102+
103+
$this->withPasswordDefinition(Psr11::container()->get(PasswordDefinition::class));
96104
}
97105

98106

@@ -173,9 +181,11 @@ public function getPassword(): ?string
173181
*/
174182
public function setPassword(?string $password): void
175183
{
176-
// Password len equals to 40 means that the password is already encrypted with sha1
177-
if (!empty($password) && strlen($password) != 40 && !empty($this->passwordDefinition) && !$this->passwordDefinition->matchPassword($password)) {
178-
throw new InvalidArgumentException("Password does not match the password definition");
184+
if (!empty($this->passwordDefinition) && !empty($password) && strlen($password) != 40) {
185+
$result = $this->passwordDefinition->matchPassword($password);
186+
if ($result != PasswordDefinition::SUCCESS) {
187+
throw new InvalidArgumentException("Password does not match the password definition [{$result}]");
188+
}
179189
}
180190
$this->password = $password;
181191
}

src/OpenApiSpec.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525
#[OA\Schema(
2626
schema: 'error',
2727
properties: [
28-
new OA\Property('error', properties: [
29-
new OA\Property(property: 'type', description: 'A class de Exceção', type: 'string'),
30-
new OA\Property(property: 'message', description: 'A mensagem de erro', type: 'string'),
31-
new OA\Property(property: 'file', description: 'O arquivo que gerou o erro', type: 'string'),
32-
new OA\Property(property: 'line', description: 'A linha do erro', type: 'integer'),
33-
])
28+
new OA\Property(
29+
'error',
30+
properties: [
31+
new OA\Property(property: 'type', description: 'A class de Exceção', type: 'string'),
32+
new OA\Property(property: 'message', description: 'A mensagem de erro', type: 'string'),
33+
new OA\Property(property: 'file', description: 'O arquivo que gerou o erro', type: 'string'),
34+
new OA\Property(property: 'line', description: 'A linha do erro', type: 'integer'),
35+
]
36+
)
3437
],
3538
type: 'object'
3639
)]

src/Psr11.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use ByJG\Config\Environment;
99
use ByJG\Config\Exception\ConfigException;
1010
use ByJG\Config\Exception\ConfigNotFoundException;
11-
use ByJG\Config\Exception\InvalidDateException;
1211
use Psr\SimpleCache\InvalidArgumentException;
1312

1413
class Psr11
@@ -18,11 +17,10 @@ class Psr11
1817

1918
/**
2019
* @param string|null $env
21-
* @return Container
20+
* @return Container|null
2221
* @throws ConfigException
2322
* @throws ConfigNotFoundException
2423
* @throws InvalidArgumentException
25-
* @throws InvalidDateException
2624
*/
2725
public static function container(?string $env = null): ?Container
2826
{
@@ -53,7 +51,12 @@ public static function environment(): ?Definition
5351
->addEnvironment($test)
5452
->addEnvironment($staging)
5553
->addEnvironment($prod)
56-
;
54+
->withOSEnvironment(
55+
[
56+
'TAG_VERSION',
57+
'TAG_COMMIT',
58+
]
59+
);
5760
}
5861

5962
return self::$definition;

0 commit comments

Comments
 (0)