From 25e7cc61b3abb5e7ae67d4a10536246f300f0a81 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Sun, 5 Feb 2023 14:30:14 +0300 Subject: [PATCH 01/11] Add autoload-dev (#563) --- blog/composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blog/composer.json b/blog/composer.json index 90f0b422..9f4ceacf 100644 --- a/blog/composer.json +++ b/blog/composer.json @@ -110,6 +110,11 @@ "App\\": "src" } }, + "autoload-dev": { + "psr-4": { + "App\\Tests\\": "tests" + } + }, "scripts": { "serve": [ "Composer\\Config::disableProcessTimeout", From 231226fb8c9795f2d815955c1b6d9b40012fd6af Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 19 Feb 2023 18:24:35 +0300 Subject: [PATCH 02/11] New structure of configs (#570) --- blog-api/composer.json | 101 +++----------- blog-api/config/.gitignore | 1 - blog-api/config/bootstrap-web.php | 5 - blog-api/config/{ => common}/bootstrap.php | 0 blog-api/config/common/{ => di}/cache.php | 0 blog-api/config/common/{ => di}/cycle.php | 0 blog-api/config/common/{ => di}/logger.php | 0 blog-api/config/common/{ => di}/psr17.php | 0 blog-api/config/common/{ => di}/router.php | 0 .../config/common/{ => di}/translator.php | 0 blog-api/config/common/{ => di}/validator.php | 0 blog-api/config/{ => common}/params.php | 21 +-- blog-api/config/{ => common}/routes.php | 0 blog-api/config/console/.gitkeep | 0 blog-api/config/console/commands.php | 18 +++ blog-api/config/console/params.php | 9 ++ blog-api/config/delegates-console.php | 5 - blog-api/config/delegates-web.php | 5 - blog-api/config/delegates.php | 5 - .../config/{ => environments}/dev/params.php | 0 .../config/{ => environments}/prod/params.php | 0 .../config/{ => environments}/test/params.php | 2 +- blog-api/config/events-console.php | 5 - blog-api/config/events-web.php | 5 - blog-api/config/events.php | 5 - blog-api/config/providers-console.php | 5 - blog-api/config/providers-web.php | 7 - blog-api/config/providers.php | 6 - blog-api/config/web/{ => di}/application.php | 0 .../config/web/{ => di}/data-response.php | 0 .../config/web/{ => di}/error-handler.php | 0 .../web/{ => di}/middleware-dispatcher.php | 0 blog-api/config/web/{ => di}/user.php | 0 .../dev => blog-api/config/web}/params.php | 0 blog-api/configuration.php | 66 +++++++++ blog-api/public/index.php | 17 ++- blog-api/src/Blog/EditPostRequest.php | 6 +- .../tests/Functional/UserControllerTest.php | 4 +- blog-api/tests/Support/Data/database.db | Bin 114688 -> 114688 bytes blog-api/yii | 7 +- blog/composer.json | 125 ++++-------------- blog/config/bootstrap-console.php | 5 - blog/config/bootstrap-web.php | 5 - blog/config/{ => common}/bootstrap.php | 0 blog/config/common/{ => di}/cache.php | 0 blog/config/common/{ => di}/cycle.php | 0 blog/config/common/{ => di}/logger.php | 0 blog/config/common/{ => di}/psr17.php | 0 blog/config/common/{ => di}/rbac.php | 0 blog/config/common/{ => di}/router.php | 0 blog/config/common/{ => di}/sentry.php | 0 blog/config/common/{ => di}/translator.php | 0 blog/config/common/{ => di}/validator.php | 0 blog/config/{ => common}/params.php | 42 +----- blog/config/{ => common}/rbac-rules.php | 0 .../{ => common/routes}/routes-backend.php | 0 blog/config/{ => common/routes}/routes.php | 0 blog/config/console/commands.php | 15 +++ .../console/{ => di}/translator-extractor.php | 0 .../events.php} | 0 blog/config/console/params.php | 14 ++ blog/config/delegates-console.php | 5 - blog/config/delegates-web.php | 5 - blog/config/delegates.php | 5 - .../config/environments/dev/params.php | 0 .../config/{ => environments}/prod/params.php | 0 .../config/{ => environments}/test/params.php | 0 blog/config/events.php | 5 - blog/config/providers-console.php | 5 - blog/config/providers-web.php | 5 - blog/config/providers.php | 6 - blog/config/web/{ => di}/application.php | 0 blog/config/web/{ => di}/auth.php | 0 blog/config/web/{ => di}/comment-service.php | 0 blog/config/web/{ => di}/contact-mailer.php | 0 .../web/{ => di}/middleware-dispatcher.php | 0 blog/config/web/{ => di}/rate-limit.php | 0 .../config/{events-web.php => web/events.php} | 0 blog/config/web/params.php | 31 +++++ blog/config/widgets.php | 5 - blog/configuration.php | 80 +++++++++++ blog/public/index.php | 7 +- blog/src/Auth/Form/SignupForm.php | 6 +- .../EventListenerConfigurationTest.php | 27 +++- blog/tests/Functional/IndexControllerTest.php | 2 +- blog/yii | 7 +- 86 files changed, 336 insertions(+), 376 deletions(-) delete mode 100644 blog-api/config/bootstrap-web.php rename blog-api/config/{ => common}/bootstrap.php (100%) rename blog-api/config/common/{ => di}/cache.php (100%) rename blog-api/config/common/{ => di}/cycle.php (100%) rename blog-api/config/common/{ => di}/logger.php (100%) rename blog-api/config/common/{ => di}/psr17.php (100%) rename blog-api/config/common/{ => di}/router.php (100%) rename blog-api/config/common/{ => di}/translator.php (100%) rename blog-api/config/common/{ => di}/validator.php (100%) rename blog-api/config/{ => common}/params.php (84%) rename blog-api/config/{ => common}/routes.php (100%) delete mode 100644 blog-api/config/console/.gitkeep create mode 100644 blog-api/config/console/commands.php create mode 100644 blog-api/config/console/params.php delete mode 100644 blog-api/config/delegates-console.php delete mode 100644 blog-api/config/delegates-web.php delete mode 100644 blog-api/config/delegates.php rename blog-api/config/{ => environments}/dev/params.php (100%) rename blog-api/config/{ => environments}/prod/params.php (100%) rename blog-api/config/{ => environments}/test/params.php (87%) delete mode 100644 blog-api/config/events-console.php delete mode 100644 blog-api/config/events-web.php delete mode 100644 blog-api/config/events.php delete mode 100644 blog-api/config/providers-console.php delete mode 100644 blog-api/config/providers-web.php delete mode 100644 blog-api/config/providers.php rename blog-api/config/web/{ => di}/application.php (100%) rename blog-api/config/web/{ => di}/data-response.php (100%) rename blog-api/config/web/{ => di}/error-handler.php (100%) rename blog-api/config/web/{ => di}/middleware-dispatcher.php (100%) rename blog-api/config/web/{ => di}/user.php (100%) rename {blog/config/dev => blog-api/config/web}/params.php (100%) create mode 100644 blog-api/configuration.php delete mode 100644 blog/config/bootstrap-console.php delete mode 100644 blog/config/bootstrap-web.php rename blog/config/{ => common}/bootstrap.php (100%) rename blog/config/common/{ => di}/cache.php (100%) rename blog/config/common/{ => di}/cycle.php (100%) rename blog/config/common/{ => di}/logger.php (100%) rename blog/config/common/{ => di}/psr17.php (100%) rename blog/config/common/{ => di}/rbac.php (100%) rename blog/config/common/{ => di}/router.php (100%) rename blog/config/common/{ => di}/sentry.php (100%) rename blog/config/common/{ => di}/translator.php (100%) rename blog/config/common/{ => di}/validator.php (100%) rename blog/config/{ => common}/params.php (82%) rename blog/config/{ => common}/rbac-rules.php (100%) rename blog/config/{ => common/routes}/routes-backend.php (100%) rename blog/config/{ => common/routes}/routes.php (100%) create mode 100644 blog/config/console/commands.php rename blog/config/console/{ => di}/translator-extractor.php (100%) rename blog/config/{events-console.php => console/events.php} (100%) create mode 100644 blog/config/console/params.php delete mode 100644 blog/config/delegates-console.php delete mode 100644 blog/config/delegates-web.php delete mode 100644 blog/config/delegates.php rename blog-api/config/bootstrap-console.php => blog/config/environments/dev/params.php (100%) rename blog/config/{ => environments}/prod/params.php (100%) rename blog/config/{ => environments}/test/params.php (100%) delete mode 100644 blog/config/events.php delete mode 100644 blog/config/providers-console.php delete mode 100644 blog/config/providers-web.php delete mode 100644 blog/config/providers.php rename blog/config/web/{ => di}/application.php (100%) rename blog/config/web/{ => di}/auth.php (100%) rename blog/config/web/{ => di}/comment-service.php (100%) rename blog/config/web/{ => di}/contact-mailer.php (100%) rename blog/config/web/{ => di}/middleware-dispatcher.php (100%) rename blog/config/web/{ => di}/rate-limit.php (100%) rename blog/config/{events-web.php => web/events.php} (100%) create mode 100644 blog/config/web/params.php delete mode 100644 blog/config/widgets.php create mode 100644 blog/configuration.php diff --git a/blog-api/composer.json b/blog-api/composer.json index 85557faa..82f09937 100644 --- a/blog-api/composer.json +++ b/blog-api/composer.json @@ -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", @@ -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, diff --git a/blog-api/config/.gitignore b/blog-api/config/.gitignore index 704eb157..8b60a947 100644 --- a/blog-api/config/.gitignore +++ b/blog-api/config/.gitignore @@ -1,2 +1 @@ .merge-plan.php -*-local.php diff --git a/blog-api/config/bootstrap-web.php b/blog-api/config/bootstrap-web.php deleted file mode 100644 index 0dae23de..00000000 --- a/blog-api/config/bootstrap-web.php +++ /dev/null @@ -1,5 +0,0 @@ - [ 'aliases' => [ - '@root' => dirname(__DIR__), + '@root' => dirname(__DIR__, 2), '@assets' => '@public/assets', '@assetsUrl' => '@baseUrl/assets', '@baseUrl' => $_ENV['BASE_URL'], @@ -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' => [ @@ -90,7 +73,7 @@ ], 'connections' => [ 'sqlite' => new SQLiteDriverConfig( - new FileConnectionConfig(dirname(__DIR__) . '/runtime/database.db') + new FileConnectionConfig(dirname(__DIR__, 2) . '/runtime/database.db') ), ], ], diff --git a/blog-api/config/routes.php b/blog-api/config/common/routes.php similarity index 100% rename from blog-api/config/routes.php rename to blog-api/config/common/routes.php diff --git a/blog-api/config/console/.gitkeep b/blog-api/config/console/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/blog-api/config/console/commands.php b/blog-api/config/console/commands.php new file mode 100644 index 00000000..84f641b6 --- /dev/null +++ b/blog-api/config/console/commands.php @@ -0,0 +1,18 @@ + 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, +]; diff --git a/blog-api/config/console/params.php b/blog-api/config/console/params.php new file mode 100644 index 00000000..051a1859 --- /dev/null +++ b/blog-api/config/console/params.php @@ -0,0 +1,9 @@ + [ + 'commands' => require __DIR__ . '/commands.php', + ], +]; diff --git a/blog-api/config/delegates-console.php b/blog-api/config/delegates-console.php deleted file mode 100644 index 0dae23de..00000000 --- a/blog-api/config/delegates-console.php +++ /dev/null @@ -1,5 +0,0 @@ - [ 'connections' => [ 'sqlite' => new SQLiteDriverConfig( - new FileConnectionConfig(dirname(__DIR__, 2) . '/tests/Support/Data/database.db') + new FileConnectionConfig(dirname(__DIR__, 3) . '/tests/Support/Data/database.db') ), ], ], diff --git a/blog-api/config/events-console.php b/blog-api/config/events-console.php deleted file mode 100644 index 0dae23de..00000000 --- a/blog-api/config/events-console.php +++ /dev/null @@ -1,5 +0,0 @@ - [ + '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', + ], +]; diff --git a/blog-api/public/index.php b/blog-api/public/index.php index bc508b5e..fd3ded37 100644 --- a/blog-api/public/index.php +++ b/blog-api/public/index.php @@ -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(); diff --git a/blog-api/src/Blog/EditPostRequest.php b/blog-api/src/Blog/EditPostRequest.php index 42de4c17..d5c8464d 100644 --- a/blog-api/src/Blog/EditPostRequest.php +++ b/blog-api/src/Blog/EditPostRequest.php @@ -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; @@ -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(), diff --git a/blog-api/tests/Functional/UserControllerTest.php b/blog-api/tests/Functional/UserControllerTest.php index b18509cb..f9f056e9 100644 --- a/blog-api/tests/Functional/UserControllerTest.php +++ b/blog-api/tests/Functional/UserControllerTest.php @@ -22,7 +22,7 @@ public function testGetIndex() $method = 'GET'; $url = '/'; - $this->tester->bootstrapApplication('web', dirname(__DIR__, 2)); + $this->tester->bootstrapApplication(dirname(__DIR__, 2)); $response = $this->tester->doRequest($method, $url); $this->assertEquals( @@ -41,7 +41,7 @@ public function testGetIndexMockVersion() $method = 'GET'; $url = '/'; - $this->tester->bootstrapApplication('web', dirname(__DIR__, 2)); + $this->tester->bootstrapApplication(dirname(__DIR__, 2)); $this->tester->mockService(VersionProvider::class, new VersionProvider('3.0.0')); diff --git a/blog-api/tests/Support/Data/database.db b/blog-api/tests/Support/Data/database.db index 1ac562e360395590d4b6fe179defde15f0fb0892..e0fa3d1db9c7b25a931a6f212423a6ef320fe3d4 100644 GIT binary patch delta 281 zcmZo@U~gz(pOD1lJ#k}75XZ#E1Qs53CeDqGtW1;TxitjRjEv1qQ<5zcjg3o-Q;S$8 z-{)4FY|qWXjU=&o0{0otjT3ILur;!>H1RS{mzQH~*t|KAMtnC ztg2wmKXJmrNeMEWWeV6?fRa17C*RIj-K?l!50p5unZ1FJ87OMNPb{%ck$zL&OP7vof`yJ5LkP4R!R5$ zl6`w(c^U3lomzdf(Qa5eaziiOo;cC~Qj zS}}WOB;`&s=N}$7MkZ^1K0liKJpy&DznT2$arh;1Hu~spL6}iF@5dr@v;M7iqb0(( zYAU>}Z1qzk+Ea%PmQ!#f%&ru>ad?n94MFtsHdpW8) z8Zlc#nHsLthzpGb*GMuA2c88fj;RO|K%(yz$|_8aIe5Lv>?K? diff --git a/blog-api/yii b/blog-api/yii index 8d2bd2fa..ae28a32e 100755 --- a/blog-api/yii +++ b/blog-api/yii @@ -8,5 +8,10 @@ use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner; require_once __DIR__ . '/autoload.php'; // Run console application runner -$runner = new ConsoleApplicationRunner(__DIR__, $_ENV['YII_DEBUG'], $_ENV['YII_ENV']); +$runner = new ConsoleApplicationRunner( + rootPath: __DIR__, + debug: $_ENV['YII_DEBUG'], + checkEvents: $_ENV['YII_DEBUG'], + environment: $_ENV['YII_ENV'] +); $runner->run(); diff --git a/blog/composer.json b/blog/composer.json index 9f4ceacf..fc92d5f6 100644 --- a/blog/composer.json +++ b/blog/composer.json @@ -36,58 +36,58 @@ "symfony/console": "^6.0", "vlucas/phpdotenv": "^5.3", "yiisoft/access": "^1.0", - "yiisoft/aliases": "^2.0", - "yiisoft/assets": "^2.1", + "yiisoft/aliases": "^3.0", + "yiisoft/assets": "^4.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/cookies": "^1.2", - "yiisoft/csrf": "^1.2", + "yiisoft/csrf": "^2.0", "yiisoft/data": "^1.0", - "yiisoft/data-response": "^1.0", + "yiisoft/data-response": "^2.0", "yiisoft/definitions": "^3.0", "yiisoft/di": "^1.2", - "yiisoft/error-handler": "^2.0", + "yiisoft/error-handler": "^3.0", "yiisoft/factory": "^1.0", "yiisoft/form": "^1.0@dev", "yiisoft/html": "^3.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/mailer": "^5.0", - "yiisoft/mailer-symfony": "^2.1", + "yiisoft/mailer-symfony": "^3.0", "yiisoft/rate-limiter": "dev-master", "yiisoft/request-model": "dev-master", "yiisoft/rbac": "^1.0", "yiisoft/rbac-php": "^1.0", - "yiisoft/rbac-rules-container": "^1.1", - "yiisoft/router": "^2.1", - "yiisoft/router-fastroute": "^2.1", + "yiisoft/rbac-rules-container": "^2.0", + "yiisoft/router": "^3.0", + "yiisoft/router-fastroute": "^3.0", "yiisoft/security": "^1.0", - "yiisoft/session": "^1.0", - "yiisoft/translator": "^2.0", - "yiisoft/translator-message-php": "^1.1", - "yiisoft/user": "^1.0", + "yiisoft/session": "^2.0", + "yiisoft/translator": "^3.0", + "yiisoft/translator-message-php": "^1.1.1", + "yiisoft/user": "^2.0", "yiisoft/validator": "3.0.x-dev", "yiisoft/var-dumper": "^1.0", - "yiisoft/view": "^7.0", + "yiisoft/view": "^8.0", "yiisoft/widget": "^2.0", "yiisoft/yii-bootstrap5": "^3.0@dev", - "yiisoft/yii-console": "^1.0", + "yiisoft/yii-console": "^2.0", "yiisoft/yii-cycle": "dev-master", "yiisoft/yii-dataview": "^3.0@dev", "yiisoft/yii-debug": "^3.0@dev", "yiisoft/yii-debug-api": "^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-runner-console": "^1.0", - "yiisoft/yii-runner-http": "^1.1", + "yiisoft/yii-runner-console": "^2.0", + "yiisoft/yii-runner-http": "^2.0", "yiisoft/yii-sentry": "dev-master", - "yiisoft/yii-swagger": "^1.0", - "yiisoft/yii-view": "^5.0" + "yiisoft/yii-swagger": "^2.0", + "yiisoft/yii-view": "^6.0" }, "require-dev": { "codeception/c3": "^2.6", @@ -100,7 +100,7 @@ "roave/security-advisories": "dev-master", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.18", - "yiisoft/translator-extractor": "^1.1", + "yiisoft/translator-extractor": "^2.0", "yiisoft/yii-debug-viewer": "^3.0@dev", "yiisoft/yii-gii": "^3.0@dev", "yiisoft/yii-testing": "dev-master" @@ -134,82 +134,7 @@ "branch-alias": { "dev-master": "3.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-backend.php", - "routes.php" - ], - "bootstrap": "bootstrap.php", - "bootstrap-web": [ - "$bootstrap", - "bootstrap-web.php" - ], - "bootstrap-console": [ - "$bootstrap", - "bootstrap-console.php" - ], - "widgets": "widgets.php" - }, + "config-plugin-file": "configuration.php", "installer-types": [ "npm-asset" ], diff --git a/blog/config/bootstrap-console.php b/blog/config/bootstrap-console.php deleted file mode 100644 index 0dae23de..00000000 --- a/blog/config/bootstrap-console.php +++ /dev/null @@ -1,5 +0,0 @@ - [ - 'locales' => ['en' => 'en-US', 'ru' => 'ru-RU', 'id' => 'id-ID', 'sk' => 'sk-SK'], - 'ignoredRequests' => [ - '/debug**', - '/inspect**', - ], - ], 'mailer' => [ 'adminEmail' => 'admin@example.com', 'senderEmail' => 'sender@example.com', ], - 'middlewares' => [ - ErrorCatcher::class, - SentryMiddleware::class, - SessionMiddleware::class, - CookieMiddleware::class, - CookieLoginMiddleware::class, - Locale::class, - Router::class, - ], 'yiisoft/aliases' => [ 'aliases' => [ - '@root' => dirname(__DIR__), + '@root' => dirname(__DIR__, 2), '@assets' => '@root/public/assets', '@assetsUrl' => '@baseUrl/assets', '@baseUrl' => $_ENV['BASE_URL'], @@ -129,21 +104,6 @@ ], ], - 'yiisoft/yii-console' => [ - 'name' => Application::NAME, - 'version' => Application::VERSION, - 'autoExit' => false, - 'commands' => [ - 'serve' => Serve::class, - 'user/create' => App\User\Console\CreateCommand::class, - 'user/assignRole' => App\User\Console\AssignRoleCommand::class, - 'fixture/add' => App\Command\Fixture\AddCommand::class, - 'fixture/schema/clear' => App\Command\Fixture\SchemaClearCommand::class, - 'router/list' => App\Command\Router\ListCommand::class, - 'translator/translate' => App\Command\Translation\TranslateCommand::class, - ], - ], - 'yiisoft/yii-cycle' => [ // DBAL config 'dbal' => [ diff --git a/blog/config/rbac-rules.php b/blog/config/common/rbac-rules.php similarity index 100% rename from blog/config/rbac-rules.php rename to blog/config/common/rbac-rules.php diff --git a/blog/config/routes-backend.php b/blog/config/common/routes/routes-backend.php similarity index 100% rename from blog/config/routes-backend.php rename to blog/config/common/routes/routes-backend.php diff --git a/blog/config/routes.php b/blog/config/common/routes/routes.php similarity index 100% rename from blog/config/routes.php rename to blog/config/common/routes/routes.php diff --git a/blog/config/console/commands.php b/blog/config/console/commands.php new file mode 100644 index 00000000..61f56464 --- /dev/null +++ b/blog/config/console/commands.php @@ -0,0 +1,15 @@ + Serve::class, + 'user/create' => App\User\Console\CreateCommand::class, + 'user/assignRole' => App\User\Console\AssignRoleCommand::class, + 'fixture/add' => App\Command\Fixture\AddCommand::class, + 'fixture/schema/clear' => App\Command\Fixture\SchemaClearCommand::class, + 'router/list' => App\Command\Router\ListCommand::class, + 'translator/translate' => App\Command\Translation\TranslateCommand::class, +]; diff --git a/blog/config/console/translator-extractor.php b/blog/config/console/di/translator-extractor.php similarity index 100% rename from blog/config/console/translator-extractor.php rename to blog/config/console/di/translator-extractor.php diff --git a/blog/config/events-console.php b/blog/config/console/events.php similarity index 100% rename from blog/config/events-console.php rename to blog/config/console/events.php diff --git a/blog/config/console/params.php b/blog/config/console/params.php new file mode 100644 index 00000000..e2179062 --- /dev/null +++ b/blog/config/console/params.php @@ -0,0 +1,14 @@ + [ + 'name' => Application::NAME, + 'version' => Application::VERSION, + 'autoExit' => false, + 'commands' => require __DIR__ . '/commands.php', + ], +]; diff --git a/blog/config/delegates-console.php b/blog/config/delegates-console.php deleted file mode 100644 index 0dae23de..00000000 --- a/blog/config/delegates-console.php +++ /dev/null @@ -1,5 +0,0 @@ - [ + ErrorCatcher::class, + SentryMiddleware::class, + SessionMiddleware::class, + CookieMiddleware::class, + CookieLoginMiddleware::class, + Locale::class, + Router::class, + ], + + 'locale' => [ + 'locales' => ['en' => 'en-US', 'ru' => 'ru-RU', 'id' => 'id-ID', 'sk' => 'sk-SK'], + 'ignoredRequests' => [ + '/debug**', + '/inspect**', + ], + ], +]; diff --git a/blog/config/widgets.php b/blog/config/widgets.php deleted file mode 100644 index 0dae23de..00000000 --- a/blog/config/widgets.php +++ /dev/null @@ -1,5 +0,0 @@ - [ + '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', + 'web/events.php', + ], + 'events-console' => [ + '$events', + 'console/events.php', + ], + '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', + ], +]; diff --git a/blog/public/index.php b/blog/public/index.php index 1df961e3..beb3659f 100644 --- a/blog/public/index.php +++ b/blog/public/index.php @@ -31,5 +31,10 @@ require_once dirname(__DIR__) . '/autoload.php'; // Run HTTP application runner -$runner = new HttpApplicationRunner(dirname(__DIR__), $_ENV['YII_DEBUG'], environment: $_ENV['YII_ENV']); +$runner = new HttpApplicationRunner( + rootPath: dirname(__DIR__), + debug: $_ENV['YII_DEBUG'], + checkEvents: $_ENV['YII_DEBUG'], + environment: $_ENV['YII_ENV'] +); $runner->run(); diff --git a/blog/src/Auth/Form/SignupForm.php b/blog/src/Auth/Form/SignupForm.php index 9763f726..c8c905d3 100644 --- a/blog/src/Auth/Form/SignupForm.php +++ b/blog/src/Auth/Form/SignupForm.php @@ -10,7 +10,7 @@ use Yiisoft\Translator\TranslatorInterface; use Yiisoft\Validator\Result; use Yiisoft\Validator\Rule\Equal; -use Yiisoft\Validator\Rule\HasLength; +use Yiisoft\Validator\Rule\Length; use Yiisoft\Validator\Rule\Required; use Yiisoft\Validator\ValidatorInterface; @@ -69,7 +69,7 @@ public function getRules(): array return [ 'login' => [ new Required(), - new HasLength(min: 1, max: 48, skipOnError: true), + new Length(min: 1, max: 48, skipOnError: true), function ($value): Result { $result = new Result(); if ($this->userRepository->findByLogin($value) !== null) { @@ -81,7 +81,7 @@ function ($value): Result { ], 'password' => [ new Required(), - new HasLength(min: 8), + new Length(min: 8), ], 'passwordVerify' => [ new Required(), diff --git a/blog/tests/Functional/EventListenerConfigurationTest.php b/blog/tests/Functional/EventListenerConfigurationTest.php index 0e5f3fc6..f752ca32 100644 --- a/blog/tests/Functional/EventListenerConfigurationTest.php +++ b/blog/tests/Functional/EventListenerConfigurationTest.php @@ -4,26 +4,39 @@ namespace App\Tests\Functional; -use function dirname; +use Yiisoft\Config\Config; use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerInterface; use Yiisoft\Config\ConfigPaths; +use Yiisoft\Config\Modifier\RecursiveMerge; +use Yiisoft\Config\Modifier\ReverseMerge; use Yiisoft\Di\Container; use Yiisoft\Di\ContainerConfig; use Yiisoft\Yii\Event\ListenerConfigurationChecker; -use Yiisoft\Yii\Runner\ConfigFactory; class EventListenerConfigurationTest extends TestCase { public function testConsoleListenerConfiguration(): void { - $config = ConfigFactory::create(new ConfigPaths(dirname(__DIR__, 2), 'config'), $_ENV['YII_ENV']); + $config = new Config( + new ConfigPaths(dirname(__DIR__, 2), 'config'), + $_ENV['YII_ENV'], + [ + ReverseMerge::groups('events', 'events-web', 'events-console'), + RecursiveMerge::groups('params', 'params-web', 'params-console', 'events', 'events-web', 'events-console'), + ], + 'params', + ); + + $container = new Container( + ContainerConfig::create() + ->withDefinitions($config->get('di-console')) + ->withProviders($config->get('di-providers-console')) + ); - $containerConfig = ContainerConfig::create() - ->withDefinitions($config->get('console')); - $container = (new Container($containerConfig))->get(ContainerInterface::class); $checker = $container->get(ListenerConfigurationChecker::class); + $checker->check($config->get('events-console')); + $checker->check($config->get('events-web')); self::assertInstanceOf(ListenerConfigurationChecker::class, $checker); } diff --git a/blog/tests/Functional/IndexControllerTest.php b/blog/tests/Functional/IndexControllerTest.php index a6643188..4da8e7d6 100644 --- a/blog/tests/Functional/IndexControllerTest.php +++ b/blog/tests/Functional/IndexControllerTest.php @@ -21,7 +21,7 @@ public function testGetIndex() $method = 'GET'; $url = '/'; - $this->tester->bootstrapApplication('web', dirname(__DIR__, 2)); + $this->tester->bootstrapApplication(dirname(__DIR__, 2)); $response = $this->tester->doRequest($method, $url); $this->assertStringContainsString('Hello, everyone', $response->getContent()); diff --git a/blog/yii b/blog/yii index 0289ec8b..ae28a32e 100755 --- a/blog/yii +++ b/blog/yii @@ -8,5 +8,10 @@ use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner; require_once __DIR__ . '/autoload.php'; // Run console application runner -$runner = new ConsoleApplicationRunner(__DIR__, $_ENV['YII_DEBUG'], environment: $_ENV['YII_ENV']); +$runner = new ConsoleApplicationRunner( + rootPath: __DIR__, + debug: $_ENV['YII_DEBUG'], + checkEvents: $_ENV['YII_DEBUG'], + environment: $_ENV['YII_ENV'] +); $runner->run(); From 20e27abd37d3d31838bd7dab80be1ab65812d9c6 Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Thu, 2 Mar 2023 01:40:00 +0500 Subject: [PATCH 03/11] Adapt `SubFolder` middleware changes (#571) --- blog-api/composer.json | 4 ++-- blog-api/config/common/bootstrap.php | 7 +------ blog-api/config/common/params.php | 2 +- blog-api/config/web/di/application.php | 5 +++++ blog/composer.json | 2 +- blog/config/common/bootstrap.php | 7 +------ blog/config/common/params.php | 2 +- blog/config/web/di/application.php | 6 ++++++ blog/config/web/params.php | 2 ++ 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/blog-api/composer.json b/blog-api/composer.json index 82f09937..f18c873c 100644 --- a/blog-api/composer.json +++ b/blog-api/composer.json @@ -60,9 +60,9 @@ "yiisoft/translator": "^3.0", "yiisoft/translator-message-php": "^1.1", "yiisoft/user": "^2.0", - "yiisoft/validator": "^3.0@dev", + "yiisoft/validator": "^1.0", "yiisoft/yii-console": "^2.0", - "yiisoft/yii-cycle": "^3.0@dev", + "yiisoft/yii-cycle": "dev-master", "yiisoft/yii-debug": "^3.0@dev", "yiisoft/yii-event": "^2.0", "yiisoft/yii-http": "^1.0", diff --git a/blog-api/config/common/bootstrap.php b/blog-api/config/common/bootstrap.php index 49544496..0dae23de 100644 --- a/blog-api/config/common/bootstrap.php +++ b/blog-api/config/common/bootstrap.php @@ -2,9 +2,4 @@ declare(strict_types=1); -return [ - function (Psr\Container\ContainerInterface $container) { - $urlGenerator = $container->get(\Yiisoft\Router\UrlGeneratorInterface::class); - $urlGenerator->setUriPrefix($_ENV['BASE_URL']); - }, -]; +return []; diff --git a/blog-api/config/common/params.php b/blog-api/config/common/params.php index 5860aa9e..cf7f266b 100644 --- a/blog-api/config/common/params.php +++ b/blog-api/config/common/params.php @@ -36,7 +36,7 @@ '@root' => dirname(__DIR__, 2), '@assets' => '@public/assets', '@assetsUrl' => '@baseUrl/assets', - '@baseUrl' => $_ENV['BASE_URL'], + '@baseUrl' => '', '@data' => '@root/data', '@messages' => '@resources/messages', '@public' => '@root/public', diff --git a/blog-api/config/web/di/application.php b/blog-api/config/web/di/application.php index 3fbffc59..bc898db2 100644 --- a/blog-api/config/web/di/application.php +++ b/blog-api/config/web/di/application.php @@ -26,4 +26,9 @@ 'ignoredRequests' => $params['locale']['ignoredRequests'], ], ], + \Yiisoft\Yii\Middleware\SubFolder::class => [ + '__construct()' => [ + 'prefix' => !empty(trim($_ENV['BASE_URL'] ?? '', '/')) ? $_ENV['BASE_URL'] : null, + ], + ], ]; diff --git a/blog/composer.json b/blog/composer.json index fc92d5f6..4fa637eb 100644 --- a/blog/composer.json +++ b/blog/composer.json @@ -70,7 +70,7 @@ "yiisoft/translator": "^3.0", "yiisoft/translator-message-php": "^1.1.1", "yiisoft/user": "^2.0", - "yiisoft/validator": "3.0.x-dev", + "yiisoft/validator": "^1.0", "yiisoft/var-dumper": "^1.0", "yiisoft/view": "^8.0", "yiisoft/widget": "^2.0", diff --git a/blog/config/common/bootstrap.php b/blog/config/common/bootstrap.php index 49544496..0dae23de 100644 --- a/blog/config/common/bootstrap.php +++ b/blog/config/common/bootstrap.php @@ -2,9 +2,4 @@ declare(strict_types=1); -return [ - function (Psr\Container\ContainerInterface $container) { - $urlGenerator = $container->get(\Yiisoft\Router\UrlGeneratorInterface::class); - $urlGenerator->setUriPrefix($_ENV['BASE_URL']); - }, -]; +return []; diff --git a/blog/config/common/params.php b/blog/config/common/params.php index e67641d2..fe4e56c8 100644 --- a/blog/config/common/params.php +++ b/blog/config/common/params.php @@ -30,7 +30,7 @@ '@root' => dirname(__DIR__, 2), '@assets' => '@root/public/assets', '@assetsUrl' => '@baseUrl/assets', - '@baseUrl' => $_ENV['BASE_URL'], + '@baseUrl' => '', '@messages' => '@resources/messages', '@npm' => '@root/node_modules', '@public' => '@root/public', diff --git a/blog/config/web/di/application.php b/blog/config/web/di/application.php index d273ce84..edb21888 100644 --- a/blog/config/web/di/application.php +++ b/blog/config/web/di/application.php @@ -7,6 +7,7 @@ use Yiisoft\Definitions\Reference; use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher; use Yiisoft\Yii\Middleware\Locale; +use Yiisoft\Yii\Middleware\SubFolder; /** @var array $params */ @@ -26,4 +27,9 @@ 'ignoredRequests' => $params['locale']['ignoredRequests'], ], ], + SubFolder::class => [ + '__construct()' => [ + 'prefix' => !empty(trim($_ENV['BASE_URL'] ?? '', '/')) ? $_ENV['BASE_URL'] : null, + ], + ], ]; diff --git a/blog/config/web/params.php b/blog/config/web/params.php index 4cec13b6..8a1c1413 100644 --- a/blog/config/web/params.php +++ b/blog/config/web/params.php @@ -8,6 +8,7 @@ use Yiisoft\Session\SessionMiddleware; use Yiisoft\User\Login\Cookie\CookieLoginMiddleware; use Yiisoft\Yii\Middleware\Locale; +use Yiisoft\Yii\Middleware\SubFolder; use Yiisoft\Yii\Sentry\SentryMiddleware; return [ @@ -17,6 +18,7 @@ SessionMiddleware::class, CookieMiddleware::class, CookieLoginMiddleware::class, + SubFolder::class, Locale::class, Router::class, ], From 3ba9cfff45eaf1683784f8d54a18f31878b0b464 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Tue, 21 Mar 2023 09:22:03 +0300 Subject: [PATCH 04/11] Set up crontab for certbot renew (#578) * Set up crontab for certbot renew * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot --- .../certbot/tasks/update_certificates.yml | 20 ++++++++++++ blog-api/config/web/di/application.php | 2 +- blog-api/src/Auth/AuthController.php | 13 ++++++++ blog-api/src/Auth/AuthRequest.php | 1 + blog-api/src/Blog/BlogController.php | 31 +++++++++++++++++++ blog-api/src/Blog/EditPostRequest.php | 1 + blog-api/src/Blog/PostFormatter.php | 1 + blog-api/src/Dto/ApiResponseData.php | 1 + blog-api/src/Formatter/PaginatorFormatter.php | 1 + blog-api/src/InfoController.php | 4 +++ blog-api/src/User/UserController.php | 11 +++++++ blog-api/src/User/UserFormatter.php | 1 + blog/config/common/routes/routes.php | 4 +-- blog/src/Controller/Actions/ApiInfo.php | 1 + .../src/User/Controller/ApiUserController.php | 4 +++ 15 files changed, 93 insertions(+), 3 deletions(-) diff --git a/ansible/roles/certbot/tasks/update_certificates.yml b/ansible/roles/certbot/tasks/update_certificates.yml index 02f79c58..7dc919a9 100644 --- a/ansible/roles/certbot/tasks/update_certificates.yml +++ b/ansible/roles/certbot/tasks/update_certificates.yml @@ -16,3 +16,23 @@ args: chdir: /home/deploy/demo.yiiframework.com shell: docker-compose -f docker-compose.yml exec gateway nginx -t && docker-compose -f docker-compose.yml exec gateway nginx -s reload + +# Crontab file location is /var/spool/cron/crontabs/deploy +# Every 2nd month on 15th day of month +# See https://crontab.guru/#0_0_15_*/2_* +- name: Set periodic certificates update + cron: + name: certbot-renew + user: deploy + minute: '0' + hour: '0' + day: '15' + month: '*/2' + job: > + /bin/bash -c " + cd /home/deploy/demo.yiiframework.com && + docker-compose -f docker-compose.yml up certbot && + sleep 180 && + docker-compose -f docker-compose.yml exec -T gateway nginx -t && + docker-compose -f docker-compose.yml exec -T gateway nginx -s reload + " diff --git a/blog-api/config/web/di/application.php b/blog-api/config/web/di/application.php index bc898db2..8128fae3 100644 --- a/blog-api/config/web/di/application.php +++ b/blog-api/config/web/di/application.php @@ -14,7 +14,7 @@ Yiisoft\Yii\Http\Application::class => [ '__construct()' => [ 'dispatcher' => DynamicReference::to(static function (Injector $injector) use ($params) { - return ($injector->make(MiddlewareDispatcher::class)) + return $injector->make(MiddlewareDispatcher::class) ->withMiddlewares($params['middlewares']); }), 'fallbackHandler' => Reference::to(NotFoundHandler::class), diff --git a/blog-api/src/Auth/AuthController.php b/blog-api/src/Auth/AuthController.php index 5aa01a48..d28d20d5 100644 --- a/blog-api/src/Auth/AuthController.php +++ b/blog-api/src/Auth/AuthController.php @@ -42,13 +42,17 @@ public function __construct( * path="/auth/", * summary="Authenticate by params", * description="", + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="data", * type="object", @@ -58,15 +62,20 @@ public function __construct( * }, * ) * ), + * * @OA\Response( * response="400", * description="Bad request", + * * @OA\JsonContent(ref="#/components/schemas/BadResponse") * ), + * * @OA\RequestBody( * required=true, + * * @OA\MediaType( * mediaType="application/json", + * * @OA\Schema(ref="#/components/schemas/AuthRequest"), * ), * ), @@ -93,14 +102,18 @@ public function login(AuthRequest $request): ResponseInterface * summary="Logout", * description="", * security={{"ApiKey": {}}}, + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent(ref="#/components/schemas/Response") * ), + * * @OA\Response( * response="400", * description="Bad request", + * * @OA\JsonContent(ref="#/components/schemas/BadResponse") * ), * ) diff --git a/blog-api/src/Auth/AuthRequest.php b/blog-api/src/Auth/AuthRequest.php index b6d3415b..00496706 100644 --- a/blog-api/src/Auth/AuthRequest.php +++ b/blog-api/src/Auth/AuthRequest.php @@ -12,6 +12,7 @@ /** * @OA\Schema( * schema="AuthRequest", + * * @OA\Property(example="Opal1144", property="login", format="string"), * @OA\Property(example="Opal1144", property="password", format="string"), * ) diff --git a/blog-api/src/Blog/BlogController.php b/blog-api/src/Blog/BlogController.php index 13e27255..92c46baf 100644 --- a/blog-api/src/Blog/BlogController.php +++ b/blog-api/src/Blog/BlogController.php @@ -17,7 +17,9 @@ * name="blog", * description="Blog" * ) + * * @OA\Parameter( + * * @OA\Schema( * type="int", * example="2" @@ -55,22 +57,29 @@ public function __construct( * path="/blog/", * summary="Returns paginated blog posts", * description="", + * * @OA\Parameter(ref="#/components/parameters/PageRequest"), + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="data", * type="object", * @OA\Property( * property="posts", * type="array", + * * @OA\Items(ref="#/components/schemas/Post") * ), + * * @OA\Property( * property="paginator", * type="object", @@ -105,19 +114,25 @@ public function index(PaginatorFormatter $paginatorFormatter, #[Query('page')] i * path="/blog/{id}", * summary="Returns a post with a given ID", * description="", + * * @OA\Parameter( + * * @OA\Schema(type="int", example="2"), * in="path", * name="id", * parameter="id" * ), + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="data", * type="object", @@ -131,13 +146,17 @@ public function index(PaginatorFormatter $paginatorFormatter, #[Query('page')] i * }, * ) * ), + * * @OA\Response( * response="404", * description="Not found", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/BadResponse"), * @OA\Schema( + * * @OA\Property(property="error_message", example="Entity not found"), * @OA\Property(property="error_code", nullable=true, example=404) * ), @@ -164,17 +183,22 @@ public function view(#[Route('id')] int $id): Response * summary="Creates a blog post", * description="", * security={{"ApiKey": {}}}, + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * ref="#/components/schemas/Response" * ) * ), + * * @OA\RequestBody( * required=true, + * * @OA\MediaType( * mediaType="application/json", + * * @OA\Schema(ref="#/components/schemas/EditPostRequest"), * ), * ), @@ -197,23 +221,30 @@ public function create(EditPostRequest $postRequest, UserRequest $userRequest): * summary="Updates a blog post with a given ID", * description="", * security={{"ApiKey": {}}}, + * * @OA\Parameter( + * * @OA\Schema(type="int", example="2"), * in="path", * name="id", * parameter="id" * ), + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * ref="#/components/schemas/Response" * ) * ), + * * @OA\RequestBody( * required=true, + * * @OA\MediaType( * mediaType="application/json", + * * @OA\Schema(ref="#/components/schemas/EditPostRequest"), * ), * ) diff --git a/blog-api/src/Blog/EditPostRequest.php b/blog-api/src/Blog/EditPostRequest.php index d5c8464d..375e02de 100644 --- a/blog-api/src/Blog/EditPostRequest.php +++ b/blog-api/src/Blog/EditPostRequest.php @@ -14,6 +14,7 @@ /** * @OA\Schema( * schema="EditPostRequest", + * * @OA\Property(example="Title post", property="title", format="string"), * @OA\Property(example="Text post", property="text", format="string"), * @OA\Property(example=1, property="status", format="int"), diff --git a/blog-api/src/Blog/PostFormatter.php b/blog-api/src/Blog/PostFormatter.php index 5363a030..3193d4bc 100644 --- a/blog-api/src/Blog/PostFormatter.php +++ b/blog-api/src/Blog/PostFormatter.php @@ -9,6 +9,7 @@ /** * @OA\Schema( * schema="Post", + * * @OA\Property(example="100", property="id", format="int"), * @OA\Property(example="Title", property="title", format="string"), * @OA\Property(example="Text", property="content", format="string"), diff --git a/blog-api/src/Dto/ApiResponseData.php b/blog-api/src/Dto/ApiResponseData.php index ba7492f4..65e85c9e 100644 --- a/blog-api/src/Dto/ApiResponseData.php +++ b/blog-api/src/Dto/ApiResponseData.php @@ -15,6 +15,7 @@ * allOf={ * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="status", * example="failed", diff --git a/blog-api/src/Formatter/PaginatorFormatter.php b/blog-api/src/Formatter/PaginatorFormatter.php index 84221d5c..983c6eef 100644 --- a/blog-api/src/Formatter/PaginatorFormatter.php +++ b/blog-api/src/Formatter/PaginatorFormatter.php @@ -10,6 +10,7 @@ /** * @OA\Schema( * schema="Paginator", + * * @OA\Property(example="10", property="pageSize", format="int"), * @OA\Property(example="1", property="currentPage", format="int"), * @OA\Property(example="3", property="totalPages", format="int"), diff --git a/blog-api/src/InfoController.php b/blog-api/src/InfoController.php index c02fe1d7..3ce6fafb 100644 --- a/blog-api/src/InfoController.php +++ b/blog-api/src/InfoController.php @@ -22,13 +22,17 @@ public function __construct(private VersionProvider $versionProvider) * path="/", * summary="Returns info about the API", * description="", + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="data", * type="object", diff --git a/blog-api/src/User/UserController.php b/blog-api/src/User/UserController.php index ee7ecf30..4baea2f6 100644 --- a/blog-api/src/User/UserController.php +++ b/blog-api/src/User/UserController.php @@ -42,19 +42,24 @@ public function __construct( * summary="Returns paginated users", * description="", * security={{"ApiKey": {}}}, + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="data", * type="object", * @OA\Property( * property="users", * type="array", + * * @OA\Items(ref="#/components/schemas/User") * ), * ), @@ -86,19 +91,25 @@ public function list(): ResponseInterface * summary="Returns a user with a given ID", * description="", * security={{"ApiKey": {}}}, + * * @OA\Parameter( + * * @OA\Schema(type="int", example="2"), * in="path", * name="id", * parameter="id" * ), + * * @OA\Response( * response="200", * description="Success", + * * @OA\JsonContent( * allOf={ + * * @OA\Schema(ref="#/components/schemas/Response"), * @OA\Schema( + * * @OA\Property( * property="data", * type="object", diff --git a/blog-api/src/User/UserFormatter.php b/blog-api/src/User/UserFormatter.php index 4b44e09a..115280f4 100644 --- a/blog-api/src/User/UserFormatter.php +++ b/blog-api/src/User/UserFormatter.php @@ -9,6 +9,7 @@ /** * @OA\Schema( * schema="User", + * * @OA\Property(example="UserName", property="login", format="string"), * @OA\Property(example="13.12.2020 00:04:20", property="created_at", format="string"), * ) diff --git a/blog/config/common/routes/routes.php b/blog/config/common/routes/routes.php index d06a4a7a..0b0275b1 100644 --- a/blog/config/common/routes/routes.php +++ b/blog/config/common/routes/routes.php @@ -101,7 +101,7 @@ // Blog routes Group::create('/blog') ->routes( - // Index + // Index Route::get('[/page{page:\d+}]') ->middleware( fn (HttpCache $httpCache, PostRepository $postRepository) => $httpCache->withLastModified(function (ServerRequestInterface $request, $params) use ($postRepository) { @@ -144,7 +144,7 @@ // Archive Group::create('/archive') ->routes( - // Index page + // Index page Route::get('') ->action([ArchiveController::class, 'index']) ->name('blog/archive/index'), diff --git a/blog/src/Controller/Actions/ApiInfo.php b/blog/src/Controller/Actions/ApiInfo.php index b2aad8e2..dc83f1c0 100644 --- a/blog/src/Controller/Actions/ApiInfo.php +++ b/blog/src/Controller/Actions/ApiInfo.php @@ -26,6 +26,7 @@ public function __construct(DataResponseFactoryInterface $responseFactory) /** * @OA\Get( * path="/api/info/v2", + * * @OA\Response(response="200", description="Get api version") * ) */ diff --git a/blog/src/User/Controller/ApiUserController.php b/blog/src/User/Controller/ApiUserController.php index 1f3bb769..9f0c4e55 100644 --- a/blog/src/User/Controller/ApiUserController.php +++ b/blog/src/User/Controller/ApiUserController.php @@ -28,6 +28,7 @@ public function __construct(private DataResponseFactoryInterface $responseFactor * @OA\Get( * path="/api/user", * tags={"user"}, + * * @OA\Response(response="200", description="Get users list") * ) */ @@ -52,12 +53,15 @@ public function index(UserRepository $userRepository): ResponseInterface * @OA\Get( * path="/api/user/{login}", * tags={"user"}, + * * @OA\Parameter( + * * @OA\Schema(type="string"), * in="path", * name="login", * parameter="login" * ), + * * @OA\Response(response="200", description="Get user info") * ) */ From da8c4b474ab1f183d4f9960cd03c6a07b875eb8c Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 31 Mar 2023 17:40:53 +0300 Subject: [PATCH 05/11] Update .styleci.yml (#580) * Update .styleci.yml * Update .styleci.yml --- .styleci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 2b00d631..76e29ece 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,7 +1,7 @@ preset: psr12 risky: true -version: 8 +version: 8.1 finder: exclude: @@ -60,7 +60,6 @@ enabled: - phpdoc_order - phpdoc_property - phpdoc_scalar - - phpdoc_separation - phpdoc_singular_inheritdoc - phpdoc_trim - phpdoc_trim_consecutive_blank_line_separation @@ -82,3 +81,9 @@ enabled: - trailing_comma_in_multiline_array - unalign_double_arrow - unalign_equals + - empty_loop_body_braces + - integer_literal_case + - union_type_without_spaces + +disabled: + - function_declaration From a83c1702051aa5e02927bfc8b283ebc83c3adffc Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Thu, 13 Apr 2023 11:47:07 +0500 Subject: [PATCH 06/11] Fix CI build & adapt form-model changes (#574) --- .github/workflows/blog-api_build.yml | 2 +- .github/workflows/blog_build.yml | 2 +- blog-api/.env.test | 1 + blog-api/tests/Acceptance.suite.yml | 2 +- blog-api/tests/Functional.suite.yml | 2 +- .../{UserControllerTest.php => IndexControllerTest.php} | 6 +++--- blog/.env.test | 3 ++- blog/src/Auth/Form/LoginForm.php | 3 ++- blog/src/Auth/Form/SignupForm.php | 3 ++- blog/src/Contact/ContactForm.php | 3 ++- blog/tests/Acceptance.suite.yml | 2 +- blog/tests/Functional.suite.yml | 2 +- 12 files changed, 18 insertions(+), 13 deletions(-) rename blog-api/tests/Functional/{UserControllerTest.php => IndexControllerTest.php} (90%) diff --git a/.github/workflows/blog-api_build.yml b/.github/workflows/blog-api_build.yml index 297590dd..9ad9ca26 100644 --- a/.github/workflows/blog-api_build.yml +++ b/.github/workflows/blog-api_build.yml @@ -34,7 +34,7 @@ jobs: name: PHP ${{ matrix.php }}-${{ matrix.os }} env: - extensions: fileinfo, pdo, pdo_sqlite, intl + extensions: fileinfo, pdo, pdo_sqlite, intl, pcntl key: cache-v1 YII_C3: true working_directory: blog-api diff --git a/.github/workflows/blog_build.yml b/.github/workflows/blog_build.yml index d1b87bca..4a010ae6 100644 --- a/.github/workflows/blog_build.yml +++ b/.github/workflows/blog_build.yml @@ -37,7 +37,7 @@ jobs: extensions: fileinfo, pdo, pdo_sqlite, intl key: cache-v1 YII_C3: true - working_directory: blog-api + working_directory: blog runs-on: ${{ matrix.os }} diff --git a/blog-api/.env.test b/blog-api/.env.test index dbdcc044..88165731 100644 --- a/blog-api/.env.test +++ b/blog-api/.env.test @@ -1,2 +1,3 @@ YII_ENV=test YII_DEBUG=true +BASE_URL=/ diff --git a/blog-api/tests/Acceptance.suite.yml b/blog-api/tests/Acceptance.suite.yml index 42dc406f..d8821110 100644 --- a/blog-api/tests/Acceptance.suite.yml +++ b/blog-api/tests/Acceptance.suite.yml @@ -7,7 +7,7 @@ extensions: modules: enabled: - REST: - url: http://127.0.0.1:8881 + url: http://127.0.0.1:8881%BASE_URL% depends: PhpBrowser - Db: dsn: 'sqlite:tests/Support/Data/database.db' diff --git a/blog-api/tests/Functional.suite.yml b/blog-api/tests/Functional.suite.yml index 289db888..125f6c5b 100644 --- a/blog-api/tests/Functional.suite.yml +++ b/blog-api/tests/Functional.suite.yml @@ -7,6 +7,6 @@ extensions: modules: enabled: - PhpBrowser: - url: http://127.0.0.1:8881 + url: http://127.0.0.1:8881%BASE_URL% - \App\Tests\Support\Helper\Functional step_decorators: ~ diff --git a/blog-api/tests/Functional/UserControllerTest.php b/blog-api/tests/Functional/IndexControllerTest.php similarity index 90% rename from blog-api/tests/Functional/UserControllerTest.php rename to blog-api/tests/Functional/IndexControllerTest.php index f9f056e9..781f79ec 100644 --- a/blog-api/tests/Functional/UserControllerTest.php +++ b/blog-api/tests/Functional/IndexControllerTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Yii\Testing\FunctionalTester; -final class UserControllerTest extends TestCase +final class IndexControllerTest extends TestCase { private ?FunctionalTester $tester; @@ -17,7 +17,7 @@ protected function setUp(): void $this->tester = new FunctionalTester(); } - public function testGetIndex() + public function testGetIndex(): void { $method = 'GET'; $url = '/'; @@ -36,7 +36,7 @@ public function testGetIndex() ); } - public function testGetIndexMockVersion() + public function testGetIndexMockVersion(): void { $method = 'GET'; $url = '/'; diff --git a/blog/.env.test b/blog/.env.test index 454ab143..76b1f81a 100644 --- a/blog/.env.test +++ b/blog/.env.test @@ -1,3 +1,4 @@ YII_ENV=test -YII_DEBUG=false +YII_DEBUG=true SENTRY_DSN= +BASE_URL=/ diff --git a/blog/src/Auth/Form/LoginForm.php b/blog/src/Auth/Form/LoginForm.php index 98e49308..985c9d52 100644 --- a/blog/src/Auth/Form/LoginForm.php +++ b/blog/src/Auth/Form/LoginForm.php @@ -10,8 +10,9 @@ use Yiisoft\Validator\Result; use Yiisoft\Validator\Rule\Callback; use Yiisoft\Validator\Rule\Required; +use Yiisoft\Validator\RulesProviderInterface; -final class LoginForm extends FormModel +final class LoginForm extends FormModel implements RulesProviderInterface { private string $login = ''; private string $password = ''; diff --git a/blog/src/Auth/Form/SignupForm.php b/blog/src/Auth/Form/SignupForm.php index c8c905d3..30984ef2 100644 --- a/blog/src/Auth/Form/SignupForm.php +++ b/blog/src/Auth/Form/SignupForm.php @@ -12,9 +12,10 @@ use Yiisoft\Validator\Rule\Equal; use Yiisoft\Validator\Rule\Length; use Yiisoft\Validator\Rule\Required; +use Yiisoft\Validator\RulesProviderInterface; use Yiisoft\Validator\ValidatorInterface; -final class SignupForm extends FormModel +final class SignupForm extends FormModel implements RulesProviderInterface { private string $login = ''; private string $password = ''; diff --git a/blog/src/Contact/ContactForm.php b/blog/src/Contact/ContactForm.php index 18257021..ec76a96d 100644 --- a/blog/src/Contact/ContactForm.php +++ b/blog/src/Contact/ContactForm.php @@ -7,8 +7,9 @@ use Yiisoft\Form\FormModel; use Yiisoft\Validator\Rule\Email; use Yiisoft\Validator\Rule\Required; +use Yiisoft\Validator\RulesProviderInterface; -final class ContactForm extends FormModel +final class ContactForm extends FormModel implements RulesProviderInterface { private string $name = ''; private string $email = ''; diff --git a/blog/tests/Acceptance.suite.yml b/blog/tests/Acceptance.suite.yml index 94370b4a..d4c578c4 100644 --- a/blog/tests/Acceptance.suite.yml +++ b/blog/tests/Acceptance.suite.yml @@ -7,6 +7,6 @@ extensions: modules: enabled: - PhpBrowser: - url: http://127.0.0.1:8881 + url: http://127.0.0.1:8881%BASE_URL% - \App\Tests\Support\Helper\Acceptance step_decorators: ~ diff --git a/blog/tests/Functional.suite.yml b/blog/tests/Functional.suite.yml index 289db888..125f6c5b 100644 --- a/blog/tests/Functional.suite.yml +++ b/blog/tests/Functional.suite.yml @@ -7,6 +7,6 @@ extensions: modules: enabled: - PhpBrowser: - url: http://127.0.0.1:8881 + url: http://127.0.0.1:8881%BASE_URL% - \App\Tests\Support\Helper\Functional step_decorators: ~ From 5bc01f16d41410139bfe0dc755c897657869be4a Mon Sep 17 00:00:00 2001 From: Evgeniy Zyubin Date: Sun, 7 May 2023 01:55:56 +0300 Subject: [PATCH 07/11] Allow psr/http-message v2 (#582) --- blog-api/composer.json | 4 ++-- blog/composer.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/blog-api/composer.json b/blog-api/composer.json index f18c873c..a4180e96 100644 --- a/blog-api/composer.json +++ b/blog-api/composer.json @@ -27,11 +27,11 @@ "cycle/entity-behavior": "^1.0", "cycle/orm": "^2.0", "doctrine/collections": "^2.0", - "httpsoft/http-message": "^1.0.5", + "httpsoft/http-message": "^1.1", "myclabs/php-enum": "^1.7", "psr/container": "^1.0|^2.0", "psr/http-factory": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.1|^2.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", "psr/log": "^3.0", diff --git a/blog/composer.json b/blog/composer.json index 4fa637eb..b22d57e3 100644 --- a/blog/composer.json +++ b/blog/composer.json @@ -25,11 +25,11 @@ "cycle/orm": "^2.0", "doctrine/collections": "^1.6", "fakerphp/faker": "^1.14", - "httpsoft/http-message": "^1.0.5", + "httpsoft/http-message": "^1.1", "php-http/guzzle7-adapter": "^1.0", "psr/container": "^2.0", "psr/http-factory": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.1|^2.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", "psr/log": "^3.0", From 3846c2e89b1a4c887a5cc5c07d3aa453eb62e4d8 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Mon, 15 May 2023 14:46:47 +0300 Subject: [PATCH 08/11] Adapt to last changes in `Locale` middleware (#583) --- blog-api/config/web/di/application.php | 4 ++-- blog/config/web/di/application.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/blog-api/config/web/di/application.php b/blog-api/config/web/di/application.php index 8128fae3..995f4b9a 100644 --- a/blog-api/config/web/di/application.php +++ b/blog-api/config/web/di/application.php @@ -22,8 +22,8 @@ ], \Yiisoft\Yii\Middleware\Locale::class => [ '__construct()' => [ - 'locales' => $params['locale']['locales'], - 'ignoredRequests' => $params['locale']['ignoredRequests'], + 'supportedLocales' => $params['locale']['locales'], + 'ignoredRequestUrlPatterns' => $params['locale']['ignoredRequests'], ], ], \Yiisoft\Yii\Middleware\SubFolder::class => [ diff --git a/blog/config/web/di/application.php b/blog/config/web/di/application.php index edb21888..68957bf3 100644 --- a/blog/config/web/di/application.php +++ b/blog/config/web/di/application.php @@ -23,8 +23,8 @@ ], Locale::class => [ '__construct()' => [ - 'locales' => $params['locale']['locales'], - 'ignoredRequests' => $params['locale']['ignoredRequests'], + 'supportedLocales' => $params['locale']['locales'], + 'ignoredRequestUrlPatterns' => $params['locale']['ignoredRequests'], ], ], SubFolder::class => [ From d1ec6332a6743cc624558b5bde6652a5f4b97737 Mon Sep 17 00:00:00 2001 From: Ihor Sychevskyi Date: Sat, 20 May 2023 19:46:01 +0300 Subject: [PATCH 09/11] update irc link (#584) --- blog-api/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog-api/composer.json b/blog-api/composer.json index a4180e96..5845337c 100644 --- a/blog-api/composer.json +++ b/blog-api/composer.json @@ -14,7 +14,7 @@ "issues": "https://github.com/yiisoft/demo-api/issues?state=open", "forum": "https://www.yiiframework.com/forum/", "wiki": "https://www.yiiframework.com/wiki/", - "irc": "irc://irc.freenode.net/yii", + "irc": "ircs://irc.libera.chat:6697/yii", "source": "https://github.com/yiisoft/demo-api" }, "minimum-stability": "dev", From a5d1bd2e8f110e0cd84b49aaff3a8c210b1bf63d Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 25 May 2023 11:27:37 +0600 Subject: [PATCH 10/11] Sync with middleware (#586) * Sync with middleware * Disallow http discovery --- blog-api/composer.json | 2 +- blog-api/config/common/params.php | 4 ++-- blog-api/config/web/di/application.php | 2 +- blog/composer.json | 7 ++++--- blog/config/web/di/application.php | 4 ++-- blog/config/web/params.php | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/blog-api/composer.json b/blog-api/composer.json index 5845337c..3eacedb2 100644 --- a/blog-api/composer.json +++ b/blog-api/composer.json @@ -66,7 +66,7 @@ "yiisoft/yii-debug": "^3.0@dev", "yiisoft/yii-event": "^2.0", "yiisoft/yii-http": "^1.0", - "yiisoft/yii-middleware": "dev-master", + "yiisoft/yii-middleware": "^1.0", "yiisoft/yii-queue": "3.0.x-dev", "yiisoft/yii-runner-console": "^2.0", "yiisoft/yii-runner-http": "^2.0", diff --git a/blog-api/config/common/params.php b/blog-api/config/common/params.php index cf7f266b..cd550e12 100644 --- a/blog-api/config/common/params.php +++ b/blog-api/config/common/params.php @@ -12,7 +12,7 @@ use Yiisoft\Yii\Cycle\Schema\Provider\PhpFileSchemaProvider; use Yiisoft\Yii\Cycle\Schema\SchemaProviderInterface; use Yiisoft\Yii\Middleware\Locale; -use Yiisoft\Yii\Middleware\SubFolder; +use Yiisoft\Yii\Middleware\Subfolder; use Yiisoft\Yii\Queue\Adapter\SynchronousAdapter; return [ @@ -26,7 +26,7 @@ 'supportEmail' => 'support@example.com', 'middlewares' => [ ErrorCatcher::class, - SubFolder::class, + Subfolder::class, Locale::class, Router::class, ], diff --git a/blog-api/config/web/di/application.php b/blog-api/config/web/di/application.php index 995f4b9a..709f69e3 100644 --- a/blog-api/config/web/di/application.php +++ b/blog-api/config/web/di/application.php @@ -26,7 +26,7 @@ 'ignoredRequestUrlPatterns' => $params['locale']['ignoredRequests'], ], ], - \Yiisoft\Yii\Middleware\SubFolder::class => [ + \Yiisoft\Yii\Middleware\Subfolder::class => [ '__construct()' => [ 'prefix' => !empty(trim($_ENV['BASE_URL'] ?? '', '/')) ? $_ENV['BASE_URL'] : null, ], diff --git a/blog/composer.json b/blog/composer.json index b22d57e3..7fd7fec3 100644 --- a/blog/composer.json +++ b/blog/composer.json @@ -59,10 +59,10 @@ "yiisoft/mailer": "^5.0", "yiisoft/mailer-symfony": "^3.0", "yiisoft/rate-limiter": "dev-master", - "yiisoft/request-model": "dev-master", "yiisoft/rbac": "^1.0", "yiisoft/rbac-php": "^1.0", "yiisoft/rbac-rules-container": "^2.0", + "yiisoft/request-model": "dev-master", "yiisoft/router": "^3.0", "yiisoft/router-fastroute": "^3.0", "yiisoft/security": "^1.0", @@ -82,7 +82,7 @@ "yiisoft/yii-debug-api": "^3.0@dev", "yiisoft/yii-event": "^2.0", "yiisoft/yii-http": "^1.0", - "yiisoft/yii-middleware": "dev-master", + "yiisoft/yii-middleware": "^1.0", "yiisoft/yii-runner-console": "^2.0", "yiisoft/yii-runner-http": "^2.0", "yiisoft/yii-sentry": "dev-master", @@ -152,7 +152,8 @@ "composer/installers": true, "composer/package-versions-deprecated": true, "infection/extension-installer": true, - "yiisoft/config": true + "yiisoft/config": true, + "php-http/discovery": false } }, "repositories": [ diff --git a/blog/config/web/di/application.php b/blog/config/web/di/application.php index 68957bf3..76fc28ae 100644 --- a/blog/config/web/di/application.php +++ b/blog/config/web/di/application.php @@ -7,7 +7,7 @@ use Yiisoft\Definitions\Reference; use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher; use Yiisoft\Yii\Middleware\Locale; -use Yiisoft\Yii\Middleware\SubFolder; +use Yiisoft\Yii\Middleware\Subfolder; /** @var array $params */ @@ -27,7 +27,7 @@ 'ignoredRequestUrlPatterns' => $params['locale']['ignoredRequests'], ], ], - SubFolder::class => [ + Subfolder::class => [ '__construct()' => [ 'prefix' => !empty(trim($_ENV['BASE_URL'] ?? '', '/')) ? $_ENV['BASE_URL'] : null, ], diff --git a/blog/config/web/params.php b/blog/config/web/params.php index 8a1c1413..90d18da2 100644 --- a/blog/config/web/params.php +++ b/blog/config/web/params.php @@ -8,7 +8,7 @@ use Yiisoft\Session\SessionMiddleware; use Yiisoft\User\Login\Cookie\CookieLoginMiddleware; use Yiisoft\Yii\Middleware\Locale; -use Yiisoft\Yii\Middleware\SubFolder; +use Yiisoft\Yii\Middleware\Subfolder; use Yiisoft\Yii\Sentry\SentryMiddleware; return [ @@ -18,7 +18,7 @@ SessionMiddleware::class, CookieMiddleware::class, CookieLoginMiddleware::class, - SubFolder::class, + Subfolder::class, Locale::class, Router::class, ], From 45e8379e44dcf2ca33c37a36d313550ca51f6031 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Wed, 21 Jun 2023 18:32:46 +0300 Subject: [PATCH 11/11] Add cors for swagger (#590) --- blog-api/config/common/routes.php | 4 +++- blog/config/common/routes/routes.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/blog-api/config/common/routes.php b/blog-api/config/common/routes.php index 6e01dbe7..2d39e0ab 100644 --- a/blog-api/config/common/routes.php +++ b/blog-api/config/common/routes.php @@ -15,6 +15,7 @@ use Yiisoft\Router\UrlGeneratorInterface; use Yiisoft\Swagger\Middleware\SwaggerJson; use Yiisoft\Swagger\Middleware\SwaggerUi; +use Yiisoft\Yii\Middleware\CorsAllowAll; return [ Route::get('/') @@ -61,6 +62,7 @@ }), Route::get('/openapi.json') ->middleware(FormatDataResponseAsJson::class) - ->action(SwaggerJson::class), + ->middleware(CorsAllowAll::class) + ->action([SwaggerJson::class, 'handle']), ), ]; diff --git a/blog/config/common/routes/routes.php b/blog/config/common/routes/routes.php index 0b0275b1..0d5156ae 100644 --- a/blog/config/common/routes/routes.php +++ b/blog/config/common/routes/routes.php @@ -31,6 +31,7 @@ use Yiisoft\Router\UrlGeneratorInterface; use Yiisoft\Swagger\Middleware\SwaggerJson; use Yiisoft\Swagger\Middleware\SwaggerUi; +use Yiisoft\Yii\Middleware\CorsAllowAll; use Yiisoft\Yii\Middleware\HttpCache; use Yiisoft\Yii\RateLimiter\Counter; use Yiisoft\Yii\RateLimiter\LimitRequestsMiddleware; @@ -174,6 +175,7 @@ ->name('swagger/index'), Route::get('/openapi.json') ->middleware(FormatDataResponseAsJson::class) - ->action(SwaggerJson::class), + ->middleware(CorsAllowAll::class) + ->action([SwaggerJson::class, 'handle']), ), ];