Skip to content

Commit

Permalink
New structure of configs (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Feb 19, 2023
1 parent 25e7cc6 commit 231226f
Show file tree
Hide file tree
Showing 86 changed files with 336 additions and 376 deletions.
101 changes: 15 additions & 86 deletions blog-api/composer.json
Expand Up @@ -38,39 +38,39 @@
"vlucas/phpdotenv": "^5.3",
"yiisoft/access": "^1.0",
"yiisoft/auth": "^3.0",
"yiisoft/cache": "^2.0",
"yiisoft/cache-file": "^2.0",
"yiisoft/cache": "^3.0",
"yiisoft/cache-file": "^3.0",
"yiisoft/config": "^1.0",
"yiisoft/data": "^1.0",
"yiisoft/data-response": "^1.0",
"yiisoft/data-response": "^2.0",
"yiisoft/definitions": "^3.0",
"yiisoft/di": "^1.0",
"yiisoft/error-handler": "^2.0",
"yiisoft/error-handler": "^3.0",
"yiisoft/factory": "^1.0",
"yiisoft/files": "^2.0",
"yiisoft/http": "^1.2",
"yiisoft/injector": "^1.0",
"yiisoft/log": "^2.0",
"yiisoft/log-target-file": "^2.0",
"yiisoft/log-target-file": "^3.0",
"yiisoft/request-body-parser": "^1.1",
"yiisoft/request-model": "dev-master",
"yiisoft/router": "^2.1",
"yiisoft/router-fastroute": "^2.1",
"yiisoft/router": "^3.0",
"yiisoft/router-fastroute": "^3.0",
"yiisoft/security": "^1.0",
"yiisoft/translator": "^2.0",
"yiisoft/translator": "^3.0",
"yiisoft/translator-message-php": "^1.1",
"yiisoft/user": "^1.0",
"yiisoft/user": "^2.0",
"yiisoft/validator": "^3.0@dev",
"yiisoft/yii-console": "^1.0",
"yiisoft/yii-console": "^2.0",
"yiisoft/yii-cycle": "^3.0@dev",
"yiisoft/yii-debug": "^3.0@dev",
"yiisoft/yii-event": "^1.0",
"yiisoft/yii-event": "^2.0",
"yiisoft/yii-http": "^1.0",
"yiisoft/yii-middleware": "dev-master",
"yiisoft/yii-queue": "3.0.x-dev",
"yiisoft/yii-runner-console": "^1.0",
"yiisoft/yii-runner-http": "^1.0",
"yiisoft/yii-swagger": "^1.0"
"yiisoft/yii-runner-console": "^2.0",
"yiisoft/yii-runner-http": "^2.0",
"yiisoft/yii-swagger": "^2.0"
},
"require-dev": {
"codeception/c3": "^2.6",
Expand Down Expand Up @@ -118,78 +118,7 @@
"branch-alias": {
"dev-master": "1.0.x-dev"
},
"config-plugin-options": {
"source-directory": "config"
},
"config-plugin-environments": {
"dev": {
"params": [
"test/params.php"
]
},
"prod": {
"params": [
"test/params.php"
]
},
"test": {
"params": [
"test/params.php"
]
}
},
"config-plugin": {
"common": "common/*.php",
"params": [
"params.php",
"?params-local.php"
],
"web": [
"$common",
"web/*.php"
],
"console": [
"$common",
"console/*.php"
],
"events": "events.php",
"events-web": [
"$events",
"events-web.php"
],
"events-console": [
"$events",
"events-console.php"
],
"providers": "providers.php",
"providers-web": [
"$providers",
"providers-web.php"
],
"providers-console": [
"$providers",
"providers-console.php"
],
"delegates": "delegates.php",
"delegates-web": [
"$delegates",
"delegates-web.php"
],
"delegates-console": [
"$delegates",
"delegates-console.php"
],
"routes": "routes.php",
"bootstrap": "bootstrap.php",
"bootstrap-web": [
"$bootstrap",
"bootstrap-web.php"
],
"bootstrap-console": [
"$bootstrap",
"bootstrap-console.php"
]
}
"config-plugin-file": "configuration.php"
},
"config": {
"sort-packages": true,
Expand Down
1 change: 0 additions & 1 deletion blog-api/config/.gitignore
@@ -1,2 +1 @@
.merge-plan.php
*-local.php
5 changes: 0 additions & 5 deletions blog-api/config/bootstrap-web.php

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 2 additions & 19 deletions blog-api/config/params.php → blog-api/config/common/params.php
Expand Up @@ -7,8 +7,6 @@
use Cycle\Database\Config\SQLiteDriverConfig;
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
use Yiisoft\Router\Middleware\Router;
use Yiisoft\Yii\Cycle\Command\Migration;
use Yiisoft\Yii\Cycle\Command\Schema;
use Yiisoft\Yii\Cycle\Schema\Conveyor\AttributedSchemaConveyor;
use Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider;
use Yiisoft\Yii\Cycle\Schema\Provider\PhpFileSchemaProvider;
Expand All @@ -35,7 +33,7 @@

'yiisoft/aliases' => [
'aliases' => [
'@root' => dirname(__DIR__),
'@root' => dirname(__DIR__, 2),
'@assets' => '@public/assets',
'@assetsUrl' => '@baseUrl/assets',
'@baseUrl' => $_ENV['BASE_URL'],
Expand All @@ -61,21 +59,6 @@
'defaultCategory' => 'app',
],

// Console commands
'yiisoft/yii-console' => [
'commands' => [
'cycle/schema' => Schema\SchemaCommand::class,
'cycle/schema/php' => Schema\SchemaPhpCommand::class,
'cycle/schema/clear' => Schema\SchemaClearCommand::class,
'cycle/schema/rebuild' => Schema\SchemaRebuildCommand::class,
'migrate/create' => Migration\CreateCommand::class,
'migrate/generate' => Migration\GenerateCommand::class,
'migrate/up' => Migration\UpCommand::class,
'migrate/down' => Migration\DownCommand::class,
'migrate/list' => Migration\ListCommand::class,
],
],

'yiisoft/yii-cycle' => [
// DBAL config
'dbal' => [
Expand All @@ -90,7 +73,7 @@
],
'connections' => [
'sqlite' => new SQLiteDriverConfig(
new FileConnectionConfig(dirname(__DIR__) . '/runtime/database.db')
new FileConnectionConfig(dirname(__DIR__, 2) . '/runtime/database.db')
),
],
],
Expand Down
File renamed without changes.
Empty file removed blog-api/config/console/.gitkeep
Empty file.
18 changes: 18 additions & 0 deletions blog-api/config/console/commands.php
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Yiisoft\Yii\Cycle\Command\Migration;
use Yiisoft\Yii\Cycle\Command\Schema;

return [
'cycle/schema' => Schema\SchemaCommand::class,
'cycle/schema/php' => Schema\SchemaPhpCommand::class,
'cycle/schema/clear' => Schema\SchemaClearCommand::class,
'cycle/schema/rebuild' => Schema\SchemaRebuildCommand::class,
'migrate/create' => Migration\CreateCommand::class,
'migrate/generate' => Migration\GenerateCommand::class,
'migrate/up' => Migration\UpCommand::class,
'migrate/down' => Migration\DownCommand::class,
'migrate/list' => Migration\ListCommand::class,
];
9 changes: 9 additions & 0 deletions blog-api/config/console/params.php
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

return [
'yiisoft/yii-console' => [
'commands' => require __DIR__ . '/commands.php',
],
];
5 changes: 0 additions & 5 deletions blog-api/config/delegates-console.php

This file was deleted.

5 changes: 0 additions & 5 deletions blog-api/config/delegates-web.php

This file was deleted.

5 changes: 0 additions & 5 deletions blog-api/config/delegates.php

This file was deleted.

File renamed without changes.
File renamed without changes.
Expand Up @@ -14,7 +14,7 @@
'dbal' => [
'connections' => [
'sqlite' => new SQLiteDriverConfig(
new FileConnectionConfig(dirname(__DIR__, 2) . '/tests/Support/Data/database.db')
new FileConnectionConfig(dirname(__DIR__, 3) . '/tests/Support/Data/database.db')
),
],
],
Expand Down
5 changes: 0 additions & 5 deletions blog-api/config/events-console.php

This file was deleted.

5 changes: 0 additions & 5 deletions blog-api/config/events-web.php

This file was deleted.

5 changes: 0 additions & 5 deletions blog-api/config/events.php

This file was deleted.

5 changes: 0 additions & 5 deletions blog-api/config/providers-console.php

This file was deleted.

7 changes: 0 additions & 7 deletions blog-api/config/providers-web.php

This file was deleted.

6 changes: 0 additions & 6 deletions blog-api/config/providers.php

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions blog-api/configuration.php
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

return [
'config-plugin' => [
'params' => [
'common/params.php',
],
'params-web' => [
'$params',
'web/params.php',
],
'params-console' => [
'$params',
'console/params.php',
],
'di' => 'common/di/*.php',
'di-web' => [
'$di',
'web/di/*.php',
],
'di-console' => '$di',
'di-providers' => [],
'di-providers-web' => [
'$di-providers',
],
'di-providers-console' => [
'$di-providers',
],
'di-delegates' => [],
'di-delegates-web' => [
'$di-delegates',
],
'di-delegates-console' => [
'$di-delegates',
],
'events' => [],
'events-web' => '$events',
'events-console' => '$events',
'routes' => 'common/routes.php',
'bootstrap' => 'common/bootstrap.php',
'bootstrap-web' => '$bootstrap',
'bootstrap-console' => '$bootstrap',
],
'config-plugin-environments' => [
'dev' => [
'params' => [
'environments/dev/params.php',
],
],
'prod' => [
'params' => [
'environments/prod/params.php',
],
],
'test' => [
'params' => [
'environments/test/params.php',
],
],
],
'config-plugin-options' => [
'source-directory' => 'config',
],
];
17 changes: 12 additions & 5 deletions blog-api/public/index.php
Expand Up @@ -35,9 +35,16 @@
}

// Run HTTP application runner
$runner = (new HttpApplicationRunner(dirname(__DIR__), $_ENV['YII_DEBUG'], $_ENV['YII_ENV']))
->withTemporaryErrorHandler(new ErrorHandler(
new Logger([new FileTarget(dirname(__DIR__) . '/runtime/logs/app.log')]),
new JsonRenderer(),
));
$runner = (new HttpApplicationRunner(
rootPath: dirname(__DIR__),
debug: $_ENV['YII_DEBUG'],
checkEvents: $_ENV['YII_DEBUG'],
environment: $_ENV['YII_ENV']
))
->withTemporaryErrorHandler(
new ErrorHandler(
new Logger([new FileTarget(dirname(__DIR__) . '/runtime/logs/app.log')]),
new JsonRenderer(),
)
);
$runner->run();
6 changes: 3 additions & 3 deletions blog-api/src/Blog/EditPostRequest.php
Expand Up @@ -7,7 +7,7 @@
use OpenApi\Annotations as OA;
use Yiisoft\RequestModel\RequestModel;
use Yiisoft\Validator\Result;
use Yiisoft\Validator\Rule\HasLength;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\RulesProviderInterface;

Expand Down Expand Up @@ -46,11 +46,11 @@ public function getRules(): array
return [
'body.title' => [
new Required(),
new HasLength(min: 5, max: 255),
new Length(min: 5, max: 255),
],
'body.text' => [
new Required(),
new HasLength(min: 5, max: 1000),
new Length(min: 5, max: 1000),
],
'body.status' => [
new Required(),
Expand Down

0 comments on commit 231226f

Please sign in to comment.