Skip to content

Commit

Permalink
More new features
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Dec 9, 2023
1 parent b24d1e7 commit 6d7b8af
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 170 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
*.md text eol=lf
*.gitattributes text eol=lf
*.gitignore text eol=lf
*.php text eol=lf
*.env text eol=lf
9 changes: 8 additions & 1 deletion .github/workflows/build-app-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ on:
inputs:
push:
description: 'Push Image (true or false)'
type: choice
options:
- "true"
- "false"
required: true
default: 'true'
run_tests:
description: 'Run unit tests (true or false)'
type: choice
options:
- "true"
- "false"
required: true
default: 'true'

Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ node_modules
.mysql
.phpunit.result.cache
TODO

thunder-tests

.secrets
.env
ignore.txt
21 changes: 20 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "PHPUnit Debug (Current file)",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/vendor/bin/phpunit",
"args": [
"${file}"
],
"cwd": "${workspaceFolder}",
"port": 9003,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"APP_ENV": "test",
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
}
]
}
}
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"php": ">=8.1",
"ext-json": "*",
"ext-openssl": "*",
"ext-curl": "*",
"byjg/config": "4.9.x-dev",
"byjg/anydataset-db": "4.9.x-dev",
"byjg/micro-orm": "4.9.*",
"byjg/authuser": "4.9.*",
"byjg/micro-orm": "4.9.x-dev",
"byjg/authuser": "4.9.x-dev",
"byjg/mailwrapper": "4.9.*",
"byjg/restserver": "4.9.x-dev",
"zircote/swagger-php": "^4.6.1",
Expand All @@ -35,6 +36,7 @@
"migrate": "Builder\\Scripts::migrate",
"codegen": "Builder\\Scripts::codeGenerator",
"openapi": "Builder\\Scripts::genOpenApiDocs",
"compile": "composer run openapi && composer run test",
"up-local-dev": "docker compose -f docker-compose-dev.yml up -d",
"down-local-dev": "docker compose -f docker-compose-dev.yml down",
"post-create-project-cmd": "Builder\\PostCreateScript::run"
Expand Down
51 changes: 8 additions & 43 deletions config/config-dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use ByJG\Mail\Wrapper\FakeSenderWrapper;
use ByJG\Mail\Wrapper\MailgunApiWrapper;
use ByJG\Mail\Wrapper\MailWrapperInterface;
use ByJG\MicroOrm\Literal;
use ByJG\RestServer\HttpRequestHandler;
use ByJG\RestServer\Middleware\CorsMiddleware;
use ByJG\RestServer\OutputProcessor\JsonCleanOutputProcessor;
Expand All @@ -28,7 +27,7 @@
use RestTemplate\Psr11;
use RestTemplate\Repository\DummyHexRepository;
use RestTemplate\Repository\DummyRepository;
use RestTemplate\Util\HexUuidLiteral;
use RestTemplate\Repository\UserDefinition as UserDefinitionAlias;

return [

Expand Down Expand Up @@ -88,58 +87,24 @@
]])
->toSingleton(),

UserDefinition::class => DI::bind(UserDefinition::class)
UserDefinition::class => DI::bind(UserDefinitionAlias::class)
->withConstructorArgs(
[
'users', // Table name
User::class, // User class
UserDefinition::LOGIN_IS_EMAIL,
[
// Field name in the User class => Field name in the database
'userid' => 'userid',
'name' => 'name',
'email' => 'email',
'userid' => 'userid',
'name' => 'name',
'email' => 'email',
'username' => 'username',
'password' => 'password',
'created' => 'created',
'admin' => 'admin'
'created' => 'created',
'admin' => 'admin'
]
]
)
->withMethodCall("markPropertyAsReadOnly", ["uuid"])
->withMethodCall("markPropertyAsReadOnly", ["created"])
->withMethodCall("markPropertyAsReadOnly", ["updated"])
->withMethodCall("defineGenerateKeyClosure",
[
function () {
return new Literal("X'" . Psr11::container()->get(DbDriverInterface::class)->getScalar("SELECT hex(uuid_to_bin(uuid()))") . "'");
}
]
)
->withMethodCall("defineClosureForSelect", [
"userid",
function ($value, $instance) {
if (!method_exists($instance, 'getUuid')) {
return $value;
}
if (!empty($instance->getUuid())) {
return $instance->getUuid();
}
return $value;
}
])
->withMethodCall("defineClosureForUpdate", [
'userid',
function ($value, $instance) {
if (empty($value)) {
return null;
}
if (!($value instanceof Literal)) {
$value = new HexUuidLiteral($value);
}
return $value;
}
])
->toSingleton(),

UserPropertiesDefinition::class => DI::bind(UserPropertiesDefinition::class)
Expand All @@ -149,7 +114,7 @@ function ($value, $instance) {
->withInjectedConstructor()
->toSingleton(),

'CORS_SERVER_LIST' => function () {
'CORS_SERVER_LIST' => function () {
return preg_split('/,(?![^{}]*})/', Psr11::container()->get('CORS_SERVERS'));
},

Expand Down
2 changes: 2 additions & 0 deletions docs/getting_started_03_create_rest_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public function putExampleCrudStatus(HttpResponse $response, HttpRequest $reques
The last step is to return the result as specified in the OpenAPI attributes.

```php
public function putExampleCrudStatus(HttpResponse $response, HttpRequest $request)
{
...
$response->write([
"result" => "ok"
Expand Down
5 changes: 2 additions & 3 deletions public/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

require_once __DIR__ . '/../vendor/autoload.php';

use RestTemplate\Psr11;
use ByJG\RestServer\HttpRequestHandler;
use ByJG\RestServer\Middleware\CorsMiddleware;
use ByJG\RestServer\Route\OpenApiRouteList;
use RestTemplate\Psr11;

class App
{
public static function run()
{
$server = Psr11::container()->get(HttpRequestHandler::class);
$server = Psr11::container()->get(HttpRequestHandler::class);
$server->handle(Psr11::container()->get(OpenApiRouteList::class));
}
}
Expand Down
6 changes: 3 additions & 3 deletions public/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>OpenAPI Viewer</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui.css" >
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.7.2/swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<style>
.topbar {
Expand All @@ -14,8 +14,8 @@

<body>
<div id="swagger-ui"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-bundle.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-standalone-preset.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.7.2/swagger-ui-bundle.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.7.2/swagger-ui-standalone-preset.js"> </script>
<script src="./require.js"> </script>
<script src="./openapi.js"> </script>
</body>
Expand Down
31 changes: 28 additions & 3 deletions public/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
"summary": "Create a new Dummy",
"operationId": "POST::/dummy::RestTemplate\\Rest\\DummyRest::postDummy",
"requestBody": {
"description": "The object DummyHex to be created",
"description": "The object Dummy to be created",
"required": true,
"content": {
"application/json": {
Expand Down Expand Up @@ -929,14 +929,39 @@
"email"
],
"properties": {
"userid": {
"type": "string",
"format": "string"
},
"name": {
"type": "string",
"format": "string"
},
"email": {
"type": "string",
"format": "string"
},
"username": {
"type": "string",
"format": "string"
},
"password": {
"type": "string",
"format": "string"
},
"created": {
"type": "string",
"format": "string"
},
"updated": {
"type": "string",
"format": "string"
},
"uuid": {
"admin": {
"type": "string",
"format": "string"
}
},
"uuid": {}
},
"type": "object",
"xml": {
Expand Down
2 changes: 1 addition & 1 deletion src/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class User extends UserModel
public function __construct(string $name = "", string $email = "", string $username = "", string $password = "", string $admin = "")
{
parent::__construct($name, $email, $username, $password, $admin);

$this->withPasswordDefinition(Psr11::container()->get(PasswordDefinition::class));
}

Expand Down
10 changes: 3 additions & 7 deletions src/Psr11.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ public static function environment(): ?Definition
if (is_null(self::$definition)) {
self::$definition = (new Definition())
->addConfig('dev')
->addConfig('test')
->inheritFrom('dev')
->addConfig('staging')
->inheritFrom('dev')
->addConfig('prod')
->inheritFrom('staging')
->inheritFrom('dev')
->addConfig('test' , inheritFrom: ['dev'])
->addConfig('staging', inheritFrom: ['dev'])
->addConfig('prod', inheritFrom: ['staging', 'dev'])
->setCache(['dev', 'test'], new NoCacheEngine())
->setCache(['prod', 'staging'], new FileSystemCacheEngine())
;
Expand Down
Loading

0 comments on commit 6d7b8af

Please sign in to comment.