From 0b9a43afcfb00da837e8b3623d234113c13f68d6 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Mon, 14 Nov 2022 16:11:24 +0300
Subject: [PATCH 01/29] Add support `yiisoft/router` version `^2.0` (#59)
---
README.md | 4 ++--
composer.json | 5 +++--
tests/TestCase.php | 6 +++---
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index bcd2152d..76d7b231 100644
--- a/README.md
+++ b/README.md
@@ -27,8 +27,8 @@ Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
-```
-composer require --prefer-dist yiisoft/yii-gii
+```shell
+composer require yiisoft/yii-gii
```
Usage
diff --git a/composer.json b/composer.json
index 646e9707..839ef057 100644
--- a/composer.json
+++ b/composer.json
@@ -28,7 +28,7 @@
"yiisoft/injector": "^1.1",
"yiisoft/json": "^1.0",
"yiisoft/request-model": "dev-master",
- "yiisoft/router": "^1.2",
+ "yiisoft/router": "^1.2|^2.0",
"yiisoft/strings": "^2.1",
"yiisoft/validator": "^3.0@dev",
"yiisoft/yii-console": "^1.3",
@@ -43,10 +43,11 @@
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.27",
"yiisoft/di": "^1.1",
+ "yiisoft/dummy-provider": "^1.0",
"yiisoft/event-dispatcher": "^1.0",
"yiisoft/files": "^2.0",
"yiisoft/log": "^2.0",
- "yiisoft/router-fastroute": "^1.0"
+ "yiisoft/translator": "^2.0"
},
"autoload": {
"psr-4": {
diff --git a/tests/TestCase.php b/tests/TestCase.php
index c1b90d9f..1b0f8e0f 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -64,9 +64,9 @@ protected function setUp(): void
TranslatorInterface::class => [
'class' => Translator::class,
'__construct()' => [
- 'en',
- 'en',
- Reference::to(EventDispatcherInterface::class),
+ 'locale' => 'en',
+ 'fallbackLocale' => 'en',
+ 'eventDispatcher' => Reference::to(EventDispatcherInterface::class),
],
],
RuleHandlerResolverInterface::class => RuleHandlerContainer::class,
From 41c9753de6e0bd1ddd18d3f546cba2020369da50 Mon Sep 17 00:00:00 2001
From: Dmitriy Derepko
Date: Sun, 4 Dec 2022 15:49:38 +0300
Subject: [PATCH 02/29] Enhance cors middleware (#60)
---
src/Middleware/Cors.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/Middleware/Cors.php b/src/Middleware/Cors.php
index 65577b39..437727f1 100644
--- a/src/Middleware/Cors.php
+++ b/src/Middleware/Cors.php
@@ -23,8 +23,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
->withHeader(Header::ALLOW, '*')
->withHeader(Header::VARY, 'Origin')
->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*')
- ->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD')
+ ->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE')
->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*')
- ->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true');
+ ->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true')
+ ->withHeader(Header::ACCESS_CONTROL_MAX_AGE, '86400');
}
}
From 5bb75f22e1a450a92da81788be27affe0806fc25 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Mon, 12 Dec 2022 09:48:52 +0300
Subject: [PATCH 03/29] Adapt to last changes in validator (#64)
---
src/Controller/DefaultController.php | 2 +-
tests/TestCase.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php
index 44bfec2a..119f4466 100644
--- a/src/Controller/DefaultController.php
+++ b/src/Controller/DefaultController.php
@@ -11,7 +11,7 @@
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use Yiisoft\Http\Status;
use Yiisoft\RequestModel\Attribute\Query;
-use Yiisoft\Validator\RulesDumper;
+use Yiisoft\Validator\Helper\RulesDumper;
use Yiisoft\Validator\RulesProvider\AttributesRulesProvider;
use Yiisoft\Yii\Gii\Component\CodeFile\CodeFile;
use Yiisoft\Yii\Gii\Component\CodeFile\CodeFileWriteOperationEnum;
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 1b0f8e0f..b6470b2c 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -18,7 +18,7 @@
use Yiisoft\Files\FileHelper;
use Yiisoft\Translator\Translator;
use Yiisoft\Translator\TranslatorInterface;
-use Yiisoft\Validator\RuleHandlerContainer;
+use Yiisoft\Validator\RuleHandlerResolver\RuleHandlerContainer;
use Yiisoft\Validator\RuleHandlerResolverInterface;
use Yiisoft\Validator\Validator;
use Yiisoft\Validator\ValidatorInterface;
From 592850e7fd8cebab5a9a141b262ffeefe812d8a2 Mon Sep 17 00:00:00 2001
From: Ihor Sychevskyi
Date: Sat, 17 Dec 2022 09:20:57 +0200
Subject: [PATCH 04/29] update links (http=>https) (#67)
---
.github/CODE_OF_CONDUCT.md | 6 +++---
README.md | 4 ++--
docs/guide-ja/basic-usage.md | 4 ++--
docs/guide-ja/installation.md | 2 +-
docs/guide-pt-BR/basic-usage.md | 4 ++--
docs/guide-pt-BR/installation.md | 2 +-
docs/guide-ru/basic-usage.md | 2 +-
docs/guide-ru/installation.md | 2 +-
docs/guide-uk/basic-usage.md | 4 ++--
docs/guide-uk/installation.md | 2 +-
docs/guide-zh-CN/basic-usage.md | 4 ++--
docs/guide-zh-CN/installation.md | 2 +-
docs/guide/basic-usage.md | 4 ++--
docs/guide/installation.md | 2 +-
14 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md
index 803e0007..eb64a881 100644
--- a/.github/CODE_OF_CONDUCT.md
+++ b/.github/CODE_OF_CONDUCT.md
@@ -61,7 +61,7 @@ the project's leadership.
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4.0, available at
-[http://contributor-covenant.org/version/1/4/][version]
+[https://contributor-covenant.org/version/1/4/][version]
-[homepage]: http://contributor-covenant.org
-[version]: http://contributor-covenant.org/version/1/4/
+[homepage]: https://contributor-covenant.org
+[version]: https://contributor-covenant.org/version/1/4/
diff --git a/README.md b/README.md
index 76d7b231..d0b79e5d 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
-This extension provides a Web-based code generator, called Gii, for [Yii framework](http://www.yiiframework.com) applications.
+This extension provides a Web-based code generator, called Gii, for [Yii framework](https://www.yiiframework.com) applications.
You can use Gii to quickly generate models, forms, modules, CRUD, etc.
For license information check the [LICENSE](LICENSE.md)-file.
@@ -25,7 +25,7 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
Installation
------------
-The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
+The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
```shell
composer require yiisoft/yii-gii
diff --git a/docs/guide-ja/basic-usage.md b/docs/guide-ja/basic-usage.md
index 6b8f7460..67ec115c 100644
--- a/docs/guide-ja/basic-usage.md
+++ b/docs/guide-ja/basic-usage.md
@@ -25,8 +25,8 @@ Gii にアクセスすると、最初に、ジェネレータを選択できる
その場合は、どのファイルを上書きし、どのファイルを上書きしないかを選択することも出来ます。
> Tip: データベースに変更を加えた後で、モデル・ジェネレータを使ってモデルを更新したい場合は、Gii のプレビューからコードをコピーして、あなたのコードに変更をマージすることが出来ます。
-PHPStorm の [クリップボードと比較](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html) のような IDE の機能を使うと良いでしょう。
-[Aptana Studio](http://www.aptana.com/products/studio3/download) や [Eclipse](http://www.eclipse.org/pdt/) ベースのエディタも [AnyEdit tools plugin](http://andrei.gmxhome.de/anyedit/) を使って [クリップボードと比較](http://andrei.gmxhome.de/anyedit/examples.html) をすることが出来ます。
+PHPStorm の [クリップボードと比較](https://www.jetbrains.com/help/phpstorm/comparing-files-and-folders.html) のような IDE の機能を使うと良いでしょう。
+[Aptana Studio](http://www.aptana.com/products/studio3/download) や [Eclipse](https://www.eclipse.org/pdt/) ベースのエディタも [AnyEdit tools plugin](https://andrei.gmxhome.de/anyedit/) を使って [クリップボードと比較](https://andrei.gmxhome.de/anyedit/examples.html) をすることが出来ます。
この機能を使うと、関係のある変更だけを取り込んで、あなた自身のコードを取り消すような他の変更は放っておくことが出来ます。
コードをレビューして、生成すべきファイルを選択し、"Generate" ボタンをクリックするとファイルが生成されます。
diff --git a/docs/guide-ja/installation.md b/docs/guide-ja/installation.md
index 9bb2c508..70830778 100644
--- a/docs/guide-ja/installation.md
+++ b/docs/guide-ja/installation.md
@@ -3,7 +3,7 @@
## Composer パッケージを取得する
-このエクステンションをインストールするのに推奨される方法は [composer](http://getcomposer.org/download/) によるものです。
+このエクステンションをインストールするのに推奨される方法は [composer](https://getcomposer.org/download/) によるものです。
下記のコマンドを実行してください。
diff --git a/docs/guide-pt-BR/basic-usage.md b/docs/guide-pt-BR/basic-usage.md
index 07e46d9c..854b26ec 100644
--- a/docs/guide-pt-BR/basic-usage.md
+++ b/docs/guide-pt-BR/basic-usage.md
@@ -30,7 +30,7 @@ e o que vai ser gerado. Neste caso, você também pode escolher quais arquivos d
> Dica: Ao utilizar o Modelo Generator para atualizar modelos após a mudança de banco de dados, você pode copiar o código da pré-visualização do Gii
e mesclar as alterações com o seu próprio código. Você pode usar recursos de uma IDE como PHPStorms.
- [compare with clipboard](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html), [Aptana Studio](http://www.aptana.com/products/studio3/download) ou [Eclipse](http://www.eclipse.org/pdt/) based também permitem [compare with clipboard](http://andrei.gmxhome.de/anyedit/examples.html) por usar [AnyEdit tools plugin](http://andrei.gmxhome.de/anyedit/) para isso, que lhe permite unir as mudanças relevantes e deixar de fora outros que podem reverter o seu próprio código.
+ [compare with clipboard](https://www.jetbrains.com/help/phpstorm/comparing-files-and-folders.html), [Aptana Studio](http://www.aptana.com/products/studio3/download) ou [Eclipse](https://www.eclipse.org/pdt/) based também permitem [compare with clipboard](https://andrei.gmxhome.de/anyedit/examples.html) por usar [AnyEdit tools plugin](https://andrei.gmxhome.de/anyedit/) para isso, que lhe permite unir as mudanças relevantes e deixar de fora outros que podem reverter o seu próprio código.
Depois de revisar o código e selecionar os arquivos a serem gerados você pode clicar no botão "Gerar" para criar
os arquivos. Se tudo correu bem está pronto. Quando você vê erros que Gii não é capaz de gerar os arquivos e que você tem que
@@ -40,4 +40,4 @@ ajustar as permissões do diretório do seu servidor web permitindo ser capaz de
para você criar novas coisas mais rapidamente mas não é algo que cria código pronto para uso.
Muitas vezes vemos pessoas que utilizam os modelos gerados pelo GII, sem alteração e basta apenas estendê-los para ajustar
algumas partes dele. Esta não é a forma para ele ser usado. Código gerado pelo GII é incompleto, ou incorreto, de deve ser alterado para atender às suas necessidades de que que você possa usa-lo realmente.
-
\ No newline at end of file
+
diff --git a/docs/guide-pt-BR/installation.md b/docs/guide-pt-BR/installation.md
index c043815b..c899e748 100644
--- a/docs/guide-pt-BR/installation.md
+++ b/docs/guide-pt-BR/installation.md
@@ -3,7 +3,7 @@ Instalação
## Instalado o pocote composer
-A maneira preferida para instalar essa extensão é via [composer](http://getcomposer.org/download/).
+A maneira preferida para instalar essa extensão é via [composer](https://getcomposer.org/download/).
Então rode
diff --git a/docs/guide-ru/basic-usage.md b/docs/guide-ru/basic-usage.md
index 82a16b8c..f70c7f8f 100644
--- a/docs/guide-ru/basic-usage.md
+++ b/docs/guide-ru/basic-usage.md
@@ -28,7 +28,7 @@
В этом случае, выбор остается за Вами - какие файлы оставить как есть, а какие перезаписать.
> Tip: При использовании Model-генератора для обновления моделей после изменений в БД, просто скопируйте код из превью и
- встройте его в свой код. Вы можете использовать возможности разных IDE: [сравнение с буфером обмена](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html) в PHPStorm, [Aptana Studio](http://www.aptana.com/products/studio3/download). В редакторах, основанных на [Eclipse](http://www.eclipse.org/pdt/) можно [сравнивать код с буфером обмена](http://andrei.gmxhome.de/anyedit/examples.html), используя для этого [AnyEdit tools plugin](http://andrei.gmxhome.de/anyedit/). Всё это позволит вам объединить только нужные изменения и пропустить изменения, которые заменят уже существующий полезный код.
+ встройте его в свой код. Вы можете использовать возможности разных IDE: [сравнение с буфером обмена](https://www.jetbrains.com/help/phpstorm/comparing-files-and-folders.html) в PHPStorm, [Aptana Studio](http://www.aptana.com/products/studio3/download). В редакторах, основанных на [Eclipse](https://www.eclipse.org/pdt/) можно [сравнивать код с буфером обмена](https://andrei.gmxhome.de/anyedit/examples.html), используя для этого [AnyEdit tools plugin](https://andrei.gmxhome.de/anyedit/). Всё это позволит вам объединить только нужные изменения и пропустить изменения, которые заменят уже существующий полезный код.
После просмотра кода и выбора файлов для генерирования кликните на кнопке "Generate" чтобы создать файлы. Если нет ошибок - на этом всё!
Если появятся ошибки, значит Gii не смог сгенерировать файлы и Вам нужно установить права на запись для директорий, чтобы веб-сервер мог
diff --git a/docs/guide-ru/installation.md b/docs/guide-ru/installation.md
index dd784075..14bc9e88 100644
--- a/docs/guide-ru/installation.md
+++ b/docs/guide-ru/installation.md
@@ -3,7 +3,7 @@
## Установка composer-пакета
-Предпочтительнее установить это расширение через [composer](http://getcomposer.org/download/).
+Предпочтительнее установить это расширение через [composer](https://getcomposer.org/download/).
Либо запустите
diff --git a/docs/guide-uk/basic-usage.md b/docs/guide-uk/basic-usage.md
index 41854d0f..e0313f25 100644
--- a/docs/guide-uk/basic-usage.md
+++ b/docs/guide-uk/basic-usage.md
@@ -30,8 +30,8 @@
> Підказка: Коли використовуєте генератор моделі для оновлення моделей після змін у базі даних, ви можете скопіювати код із попереднього перегляду Gii
та поєднати зміни з вашим власним кодом. Ви можете використовувати функціонал Інтегрованого Середовища Розробки (IDE), як наприклад,
- [порівняння з буфером обміну в PHPStorms](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html).
- [Aptana Studio](http://www.aptana.com/products/studio3/download) або редактори на базі [Eclipse](http://www.eclipse.org/pdt/) також дозволяють [порівняння з буфером обміну](http://andrei.gmxhome.de/anyedit/examples.html) при використанні [плагіну інструментів AnyEdit](http://andrei.gmxhome.de/anyedit/) для цього, який дозволяє вам приєднувати актуальні зміни, не враховуючи те, що повторює ваш власний код.
+ [порівняння з буфером обміну в PHPStorms](https://www.jetbrains.com/help/phpstorm/comparing-files-and-folders.html).
+ [Aptana Studio](http://www.aptana.com/products/studio3/download) або редактори на базі [Eclipse](https://www.eclipse.org/pdt/) також дозволяють [порівняння з буфером обміну](https://andrei.gmxhome.de/anyedit/examples.html) при використанні [плагіну інструментів AnyEdit](https://andrei.gmxhome.de/anyedit/) для цього, який дозволяє вам приєднувати актуальні зміни, не враховуючи те, що повторює ваш власний код.
Після того, як ви оглянули код та обрали файли для генерування, ви можете натиснути на кнопку "Generate" для створення
diff --git a/docs/guide-uk/installation.md b/docs/guide-uk/installation.md
index 39245078..e751e63e 100644
--- a/docs/guide-uk/installation.md
+++ b/docs/guide-uk/installation.md
@@ -3,7 +3,7 @@
## Встановлення через Composer
-Рекомендується встановлювати це розширення за допомогою [Composer](http://getcomposer.org/download/).
+Рекомендується встановлювати це розширення за допомогою [Composer](https://getcomposer.org/download/).
Виконайте
diff --git a/docs/guide-zh-CN/basic-usage.md b/docs/guide-zh-CN/basic-usage.md
index 5cf8ba22..0fbbed10 100644
--- a/docs/guide-zh-CN/basic-usage.md
+++ b/docs/guide-zh-CN/basic-usage.md
@@ -21,9 +21,9 @@
单击文件名可以查看将为该文件生成的代码的预览。
当文件已经存在时,Gii 还提供了一个 diff 视图,它显示了存在的代码和将要生成的代码之间的区别。 在这种情况下,还可以选择应覆盖哪些文件,哪些不覆盖。
-> 提示:在使用模型生成器在数据库更改后更新模型时,可以从 Gii 预览复制代码,并将更改与您自己的代码合并。可以使用IDE功能,如 PHPStorms [compare with clipboard(与剪贴板比较)](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html),[Aptana Studio](http://www.aptana.com/products/studio3/download) 或者使用 [Eclipse](http://www.eclipse.org/pdt/) 通过 [AnyEdit tools plugin](http://andrei.gmxhome.de/anyedit/) 也允许 [compare with clipboard(与剪贴板比较)](http://andrei.gmxhome.de/anyedit/examples.html),这样可以合并相关的更改,并省略其他可能被自己还原的代码。
+> 提示:在使用模型生成器在数据库更改后更新模型时,可以从 Gii 预览复制代码,并将更改与您自己的代码合并。可以使用IDE功能,如 PHPStorms [compare with clipboard(与剪贴板比较)](https://www.jetbrains.com/help/phpstorm/comparing-files-and-folders.html),[Aptana Studio](http://www.aptana.com/products/studio3/download) 或者使用 [Eclipse](https://www.eclipse.org/pdt/) 通过 [AnyEdit tools plugin](https://andrei.gmxhome.de/anyedit/) 也允许 [compare with clipboard(与剪贴板比较)](https://andrei.gmxhome.de/anyedit/examples.html),这样可以合并相关的更改,并省略其他可能被自己还原的代码。
在检查代码并选择要生成的文件后,可以单击 "Generate" 按钮创建文件即可。 如果看到Gii无法生成文件的错误时,则需调整目录权限,以便的Web服务器能够写入目录并创建文件。
> 注意:Gii 生成的代码只是一个根据自己的需要进行调整的模板。 它可以帮助你快速创建新的代码,但它不是创建准备使用于正式项目的代码。我们经常看到人们使用 Gii 生成的 model 没有改变,只是通过扩展它们从而调整部分 model 的功能。 这不是我们编写它的初衷。 Gii 生成的代码可能不完整或不正确,必须根据自己的需要进行更改才能使用它。
-
\ No newline at end of file
+
diff --git a/docs/guide-zh-CN/installation.md b/docs/guide-zh-CN/installation.md
index ef1a738b..cd411adc 100644
--- a/docs/guide-zh-CN/installation.md
+++ b/docs/guide-zh-CN/installation.md
@@ -3,7 +3,7 @@
## 获取 Composer 包
-安装此扩展的首选方法是通过 [composer](http://getcomposer.org/download/).
+安装此扩展的首选方法是通过 [composer](https://getcomposer.org/download/).
执行
diff --git a/docs/guide/basic-usage.md b/docs/guide/basic-usage.md
index 5c9160e2..5d8a5a23 100644
--- a/docs/guide/basic-usage.md
+++ b/docs/guide/basic-usage.md
@@ -30,7 +30,7 @@ and the one that will be generated. In this case you can also choose which files
> Tip: When using the Model Generator to update models after database change, you can copy the code from Gii preview
and merge the changes with your own code. You can use IDE features like PHPStorms
- [compare with clipboard](http://www.jetbrains.com/phpstorm/webhelp/comparing-files.html), [Aptana Studio](http://www.aptana.com/products/studio3/download) or [Eclipse](http://www.eclipse.org/pdt/) based editor also allows [compare with clipboard](http://andrei.gmxhome.de/anyedit/examples.html) by using [AnyEdit tools plugin](http://andrei.gmxhome.de/anyedit/) for this, which allows you to merge in relevant changes and leave out others that may revert your own code.
+ [compare with clipboard](https://www.jetbrains.com/help/phpstorm/comparing-files-and-folders.html), [Aptana Studio](http://www.aptana.com/products/studio3/download) or [Eclipse](https://www.eclipse.org/pdt/) based editor also allows [compare with clipboard](https://andrei.gmxhome.de/anyedit/examples.html) by using [AnyEdit tools plugin](https://andrei.gmxhome.de/anyedit/) for this, which allows you to merge in relevant changes and leave out others that may revert your own code.
After you have reviewed the code and selected the files to be generated you can click the "Generate" button to create
@@ -42,4 +42,4 @@ adjust directory permissions so that your webserver is able to write to the dire
We often see people using the models generated by Gii without change and just extend them to adjust
some parts of it. This is not how it is meant to be used. Code generated by Gii may be incomplete or incorrect
and has to be changed to fit your needs before you can use it.
-
\ No newline at end of file
+
diff --git a/docs/guide/installation.md b/docs/guide/installation.md
index dd4590f1..96e18863 100644
--- a/docs/guide/installation.md
+++ b/docs/guide/installation.md
@@ -3,7 +3,7 @@ Installation
## Getting Composer package
-The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
+The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
Either run
From 87dcd4335da90e80e13c653b6f46f2ff052f89d4 Mon Sep 17 00:00:00 2001
From: Dmitriy Derepko
Date: Fri, 23 Dec 2022 19:51:06 +0300
Subject: [PATCH 05/29] Adjust validator changes (#70)
* Adjust validator changes
* Adjust validator changes
* Apply fixes from StyleCI
* Adjust validator changes
* Fix psalm
Co-authored-by: StyleCI Bot
---
src/Command/BaseGenerateCommand.php | 13 +++++++++++--
src/Validator/ClassExistsRule.php | 3 ++-
src/Validator/NewClassRule.php | 3 ++-
src/Validator/ReservedKeywordRule.php | 3 ++-
src/Validator/TemplateRule.php | 3 ++-
src/Validator/TemplateRuleHandler.php | 14 ++++++++------
6 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/Command/BaseGenerateCommand.php b/src/Command/BaseGenerateCommand.php
index 2a624b4d..c0648b9c 100644
--- a/src/Command/BaseGenerateCommand.php
+++ b/src/Command/BaseGenerateCommand.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Gii\Command;
use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -169,7 +170,11 @@ abstract protected function createGeneratorCommand(InputInterface $input): Gener
protected function confirm(InputInterface $input, OutputInterface $output)
{
$question = new ConfirmationQuestion("\nReady to generate the selected files? (yes|no) [yes]:", true);
- return $this->getHelper('question')->ask($input, $output, $question);
+ /**
+ * @var QuestionHelper $helper
+ */
+ $helper = $this->getHelper('question');
+ return $helper->ask($input, $output, $question);
}
/**
@@ -186,7 +191,11 @@ protected function choice(InputInterface $input, OutputInterface $output)
'na' => 'Skip this and the rest of the changed files.',
]
);
- return $this->getHelper('question')->ask($input, $output, $question);
+ /**
+ * @var QuestionHelper $helper
+ */
+ $helper = $this->getHelper('question');
+ return $helper->ask($input, $output, $question);
}
private function areAllFilesSkipped(array $answers): bool
diff --git a/src/Validator/ClassExistsRule.php b/src/Validator/ClassExistsRule.php
index ef761cf8..4528ffd8 100644
--- a/src/Validator/ClassExistsRule.php
+++ b/src/Validator/ClassExistsRule.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Gii\Validator;
use Attribute;
+use Yiisoft\Validator\RuleHandlerInterface;
use Yiisoft\Validator\RuleInterface;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
@@ -15,7 +16,7 @@ public function getName(): string
return 'gii_class_exists';
}
- public function getHandlerClassName(): string
+ public function getHandler(): string|RuleHandlerInterface
{
return ClassExistsHandler::class;
}
diff --git a/src/Validator/NewClassRule.php b/src/Validator/NewClassRule.php
index 625af8e2..cda0b4a7 100644
--- a/src/Validator/NewClassRule.php
+++ b/src/Validator/NewClassRule.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Gii\Validator;
use Attribute;
+use Yiisoft\Validator\RuleHandlerInterface;
use Yiisoft\Validator\RuleInterface;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
@@ -15,7 +16,7 @@ public function getName(): string
return 'gii_new_class';
}
- public function getHandlerClassName(): string
+ public function getHandler(): string|RuleHandlerInterface
{
return NewClassHandler::class;
}
diff --git a/src/Validator/ReservedKeywordRule.php b/src/Validator/ReservedKeywordRule.php
index dc443c60..3f92c664 100644
--- a/src/Validator/ReservedKeywordRule.php
+++ b/src/Validator/ReservedKeywordRule.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Gii\Validator;
use Attribute;
+use Yiisoft\Validator\RuleHandlerInterface;
use Yiisoft\Validator\RuleInterface;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
@@ -15,7 +16,7 @@ public function getName(): string
return 'gii_reserved_keyword';
}
- public function getHandlerClassName(): string
+ public function getHandler(): string|RuleHandlerInterface
{
return ReservedKeywordHandler::class;
}
diff --git a/src/Validator/TemplateRule.php b/src/Validator/TemplateRule.php
index b785493d..06e73c03 100644
--- a/src/Validator/TemplateRule.php
+++ b/src/Validator/TemplateRule.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Gii\Validator;
use Attribute;
+use Yiisoft\Validator\RuleHandlerInterface;
use Yiisoft\Validator\RuleInterface;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
@@ -15,7 +16,7 @@ public function getName(): string
return 'gii_template_rule';
}
- public function getHandlerClassName(): string
+ public function getHandler(): string|RuleHandlerInterface
{
return TemplateRuleHandler::class;
}
diff --git a/src/Validator/TemplateRuleHandler.php b/src/Validator/TemplateRuleHandler.php
index 791f1600..d1d3bda9 100644
--- a/src/Validator/TemplateRuleHandler.php
+++ b/src/Validator/TemplateRuleHandler.php
@@ -6,7 +6,6 @@
use RuntimeException;
use Yiisoft\Aliases\Aliases;
-use Yiisoft\Validator\DataSet\ObjectDataSet;
use Yiisoft\Validator\Exception\UnexpectedRuleException;
use Yiisoft\Validator\Result;
use Yiisoft\Validator\RuleHandlerInterface;
@@ -40,9 +39,12 @@ public function validate(mixed $value, object $rule, ValidationContext $context)
if ($value === 'default') {
return $result;
}
- $command = $context->getDataSet();
- if (!$command instanceof ObjectDataSet || !$command->getObject() instanceof GeneratorCommandInterface) {
- throw new RuntimeException('Unsupported dataset class.');
+ $command = $context->getRawData();
+ if (!$command instanceof GeneratorCommandInterface) {
+ throw new RuntimeException(sprintf(
+ 'Unsupported dataset class "%s".',
+ get_debug_type($command)
+ ));
}
$generator = $this->getGenerator($command);
$templates = $this->parametersProvider->getTemplates($generator::getId());
@@ -74,10 +76,10 @@ public function validate(mixed $value, object $rule, ValidationContext $context)
return $result;
}
- private function getGenerator(ObjectDataSet $dataSet): GeneratorInterface
+ private function getGenerator(GeneratorCommandInterface $dataSet): GeneratorInterface
{
foreach ($this->gii->getGenerators() as $generator) {
- if ($generator::getCommandClass() === $dataSet->getObject()::class) {
+ if ($generator::getCommandClass() === $dataSet::class) {
return $generator;
}
}
From b93c6b190b262f619decdbf65a94c87b965e8506 Mon Sep 17 00:00:00 2001
From: Alexander Makarov
Date: Tue, 17 Jan 2023 02:40:02 +0400
Subject: [PATCH 06/29] Allow yiisoft/arrays ^3.0
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 839ef057..4e19a274 100644
--- a/composer.json
+++ b/composer.json
@@ -22,7 +22,7 @@
"php": "^8.1",
"phpspec/php-diff": "^1.1.3",
"yiisoft/aliases": "^2.0",
- "yiisoft/arrays": "^2.1",
+ "yiisoft/arrays": "^2.1|^3.0",
"yiisoft/data-response": "^1.0",
"yiisoft/http": "^1.2",
"yiisoft/injector": "^1.1",
From 7a2989935de59fa92ec04ec31d5272334438d6b7 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Sun, 19 Feb 2023 13:03:36 +0300
Subject: [PATCH 07/29] Adapt configuration group names to Yii conventions
(#82)
---
composer.json | 6 +-----
config/console.php | 6 ------
config/{common.php => di.php} | 0
3 files changed, 1 insertion(+), 11 deletions(-)
delete mode 100644 config/console.php
rename config/{common.php => di.php} (100%)
diff --git a/composer.json b/composer.json
index 4e19a274..80c8df6f 100644
--- a/composer.json
+++ b/composer.json
@@ -68,11 +68,7 @@
},
"config-plugin": {
"params": "params.php",
- "console": [
- "$common",
- "console.php"
- ],
- "common": "common.php",
+ "di": "di.php",
"routes": "routes.php"
}
},
diff --git a/config/console.php b/config/console.php
deleted file mode 100644
index 1f6a841d..00000000
--- a/config/console.php
+++ /dev/null
@@ -1,6 +0,0 @@
-
Date: Sun, 19 Feb 2023 17:12:18 +0300
Subject: [PATCH 08/29] Update Yii dependencies (#85)
---
composer.json | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/composer.json b/composer.json
index 80c8df6f..22c58b3f 100644
--- a/composer.json
+++ b/composer.json
@@ -21,17 +21,17 @@
"require": {
"php": "^8.1",
"phpspec/php-diff": "^1.1.3",
- "yiisoft/aliases": "^2.0",
+ "yiisoft/aliases": "^3.0",
"yiisoft/arrays": "^2.1|^3.0",
- "yiisoft/data-response": "^1.0",
+ "yiisoft/data-response": "^2.0",
"yiisoft/http": "^1.2",
"yiisoft/injector": "^1.1",
"yiisoft/json": "^1.0",
"yiisoft/request-model": "dev-master",
- "yiisoft/router": "^1.2|^2.0",
+ "yiisoft/router": "^3.0",
"yiisoft/strings": "^2.1",
"yiisoft/validator": "^3.0@dev",
- "yiisoft/yii-console": "^1.3",
+ "yiisoft/yii-console": "^2.0",
"yiisoft/yii-middleware": "dev-master"
},
"require-dev": {
@@ -47,7 +47,7 @@
"yiisoft/event-dispatcher": "^1.0",
"yiisoft/files": "^2.0",
"yiisoft/log": "^2.0",
- "yiisoft/translator": "^2.0"
+ "yiisoft/translator": "^3.0"
},
"autoload": {
"psr-4": {
From d9d40e9f69dd6680866418d325895bd86ef39d85 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Fri, 24 Feb 2023 10:24:15 +0300
Subject: [PATCH 09/29] Update contributor code of conduct (#89)
---
.github/CODE_OF_CONDUCT.md | 117 ++++++++++++++++++++++++-------------
1 file changed, 76 insertions(+), 41 deletions(-)
diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md
index eb64a881..2400eec3 100644
--- a/.github/CODE_OF_CONDUCT.md
+++ b/.github/CODE_OF_CONDUCT.md
@@ -2,66 +2,101 @@
## Our Pledge
-As contributors and maintainers of this project, and in order to keep Yii community open and welcoming, we ask to respect all community members.
+As contributors and maintainers of this project, and in order to keep Yii community open and welcoming, we ask to
+respect all community members.
## Our Standards
-Examples of behavior that contributes to creating a positive environment include:
+Examples of behavior that contributes to a positive environment for our community include:
-* Using welcoming and inclusive language
-* Being respectful of differing viewpoints and experiences
-* Gracefully accepting constructive criticism
-* Focusing on what is best for the community
-* Showing empathy towards other community members
+* Demonstrating empathy and kindness toward other people
+* Being respectful of differing opinions, viewpoints, and experiences
+* Giving and gracefully accepting constructive feedback
+* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
+* Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior by participants include:
-* The use of sexualized language or imagery and unwelcome sexual attention or
- advances
-* Personal attacks
-* Trolling or insulting/derogatory comments, and personal or political attacks
+* The use of sexualized language or imagery, and sexual attention or advances of any kind
+* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
-* Publishing other's private information, such as physical or electronic
- addresses, without explicit permission
-* Other conduct which could reasonably be considered inappropriate in
- a professional setting
+* Publishing others' private information, such as a physical or email address, without their explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
-## Our Responsibilities
+## Enforcement Responsibilities
-Project maintainers are responsible for clarifying the standards of acceptable
-behavior and are expected to take appropriate and fair corrective action in response
-to any instances of unacceptable behavior.
+Core team members are responsible for clarifying and enforcing our standards of acceptable behavior and will take
+appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive,
+or harmful.
-Project maintainers have the right and responsibility to remove, edit, or reject comments,
-commits, code, wiki edits, issues, and other contributions that are not aligned to this
-Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors
-that they deem inappropriate, threatening, offensive, or harmful.
+Core team members have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits,
+issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for
+moderation decisions when appropriate.
## Scope
-This Code of Conduct applies both within project spaces and in public spaces when
-an individual is representing the project or its community. Examples of representing
-a project or community include posting via an official social media account,
-within project GitHub, official forum or acting as an appointed representative at
-an online or offline event.
+This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing
+the community in public spaces. Examples of representing a project or community include using an official e-mail
+address, posting via an official social media account, within project GitHub, official forum or acting as an appointed
+representative at an online or offline event.
## Enforcement
-Instances of abusive, harassing, or otherwise unacceptable behavior may be reported
-by contacting core team members. All complaints will be reviewed and investigated
-and will result in a response that is deemed necessary and appropriate to the circumstances.
-The project team is obligated to maintain confidentiality with regard to the reporter of
-an incident. Further details of specific enforcement policies may be posted separately.
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting core team members. All
+complaints will be reviewed and investigated promptly and fairly.
-Project maintainers who do not follow or enforce the Code of Conduct in good faith
-may face temporary or permanent repercussions as determined by other members of
-the project's leadership.
+All core team members are obligated to respect the privacy and security of the reporter of any incident.
+
+## Enforcement Guidelines
+
+Core team members will follow these Community Impact Guidelines in determining the consequences for any action they
+deem in violation of this Code of Conduct:
+
+### 1. Correction
+
+**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in
+the community.
+
+**Consequence**: A private, written warning from core team members, providing clarity around the nature of the violation
+and an explanation of why the behavior was inappropriate. A public apology may be requested.
+
+### 2. Warning
+
+**Community Impact**: A violation through a single incident or series of actions.
+
+**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including
+unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding
+interactions in community spaces as well as external channels like social media. Violating these terms may lead to
+a temporary or permanent ban.
+
+### 3. Temporary Ban
+
+**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
+
+**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified
+period of time. No public or private interaction with the people involved, including unsolicited interaction with those
+enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
+
+### 4. Permanent Ban
+
+**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate
+behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
+
+**Consequence**: A permanent ban from any sort of public interaction within the community.
## Attribution
-This Code of Conduct is adapted from the [Contributor Covenant][homepage],
-version 1.4.0, available at
-[https://contributor-covenant.org/version/1/4/][version]
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at
+[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
+
+Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
+
+For answers to common questions about this code of conduct, see the FAQ at
+[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
+[https://www.contributor-covenant.org/translations][translations].
-[homepage]: https://contributor-covenant.org
-[version]: https://contributor-covenant.org/version/1/4/
+[homepage]: https://www.contributor-covenant.org
+[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
+[Mozilla CoC]: https://github.com/mozilla/diversity
+[FAQ]: https://www.contributor-covenant.org/faq
+[translations]: https://www.contributor-covenant.org/translations
From 116f234bff078db4b41a86acd524cea391580d7c Mon Sep 17 00:00:00 2001
From: Rustam Mamadaminov
Date: Thu, 2 Mar 2023 01:00:41 +0500
Subject: [PATCH 10/29] Use stable validator (#90)
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 22c58b3f..2cfd39f5 100644
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,7 @@
"yiisoft/request-model": "dev-master",
"yiisoft/router": "^3.0",
"yiisoft/strings": "^2.1",
- "yiisoft/validator": "^3.0@dev",
+ "yiisoft/validator": "^1.0",
"yiisoft/yii-console": "^2.0",
"yiisoft/yii-middleware": "dev-master"
},
From 2bcc5b1eeb9e7c97890bf3ee1da9decf6643a440 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Fri, 31 Mar 2023 18:17:34 +0300
Subject: [PATCH 11/29] Update StyleCI config (#95)
* Update StyleCI config
* Apply fixes from StyleCI
---------
Co-authored-by: StyleCI Bot
---
.styleci.yml | 17 +++++++----------
tests/templates/custom/controller.php | 2 ++
tests/templates/custom/view.php | 2 ++
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/.styleci.yml b/.styleci.yml
index 63e26a59..1ab379b4 100644
--- a/.styleci.yml
+++ b/.styleci.yml
@@ -1,20 +1,12 @@
preset: psr12
risky: true
-version: 8
+version: 8.1
finder:
exclude:
- docs
- vendor
- - resources
- - views
- - public
- - templates
- not-name:
- - UnionCar.php
- - TimerUnionTypes.php
- - schema1.php
enabled:
- alpha_ordered_traits
@@ -64,7 +56,6 @@ enabled:
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- - phpdoc_separation
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
@@ -86,3 +77,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
diff --git a/tests/templates/custom/controller.php b/tests/templates/custom/controller.php
index fd7ffd7a..04c044dd 100644
--- a/tests/templates/custom/controller.php
+++ b/tests/templates/custom/controller.php
@@ -1,3 +1,5 @@
Date: Thu, 25 May 2023 11:28:00 +0600
Subject: [PATCH 12/29] Sync with middleware (#98)
---
composer.json | 2 +-
config/routes.php | 4 ++--
src/Middleware/Cors.php | 31 -------------------------------
3 files changed, 3 insertions(+), 34 deletions(-)
delete mode 100644 src/Middleware/Cors.php
diff --git a/composer.json b/composer.json
index 2cfd39f5..146e877f 100644
--- a/composer.json
+++ b/composer.json
@@ -32,7 +32,7 @@
"yiisoft/strings": "^2.1",
"yiisoft/validator": "^1.0",
"yiisoft/yii-console": "^2.0",
- "yiisoft/yii-middleware": "dev-master"
+ "yiisoft/yii-middleware": "^1.0"
},
"require-dev": {
"jetbrains/phpstorm-attributes": "^1.0",
diff --git a/config/routes.php b/config/routes.php
index 001f6c8d..80d98d63 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -12,7 +12,7 @@
use Yiisoft\Router\Route;
use Yiisoft\Validator\ValidatorInterface;
use Yiisoft\Yii\Gii\Controller\DefaultController;
-use Yiisoft\Yii\Gii\Middleware\Cors;
+use Yiisoft\Yii\Middleware\CorsAllowAll;
use Yiisoft\Yii\Middleware\IpFilter;
if (!(bool) ($params['yiisoft/yii-gii']['enabled'] ?? false)) {
@@ -21,7 +21,7 @@
return [
Group::create('/gii/api')
- ->withCors(Cors::class)
+ ->withCors(CorsAllowAll::class)
->middleware(
static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $validator) use ($params) {
return new IpFilter(
diff --git a/src/Middleware/Cors.php b/src/Middleware/Cors.php
deleted file mode 100644
index 437727f1..00000000
--- a/src/Middleware/Cors.php
+++ /dev/null
@@ -1,31 +0,0 @@
-handle($request);
-
- return $response
- ->withHeader(Header::ALLOW, '*')
- ->withHeader(Header::VARY, 'Origin')
- ->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*')
- ->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE')
- ->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*')
- ->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true')
- ->withHeader(Header::ACCESS_CONTROL_MAX_AGE, '86400');
- }
-}
From 6216ccd82ea0b84793af3282a655e1f7bbd6d1f6 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 24 Jul 2023 16:55:58 +0300
Subject: [PATCH 13/29] Update rector, imporve config it and apply suggestions
(#106)
---
.github/workflows/rector.yml | 2 +
composer.json | 2 +-
rector.php | 17 ++++++---
src/Controller/DefaultController.php | 4 +-
.../InvalidGeneratorCommandException.php | 2 +-
src/Generator/AbstractGenerator.php | 5 +--
.../Controller/ControllerCommand.php | 38 ++++++++-----------
src/Request/GeneratorRequest.php | 2 +-
src/Validator/NewClassHandler.php | 2 +-
src/Validator/TemplateRuleHandler.php | 6 +--
tests/Generators/ControllerGeneratorTest.php | 2 +-
11 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml
index c9030d7e..0bf491f3 100644
--- a/.github/workflows/rector.yml
+++ b/.github/workflows/rector.yml
@@ -14,6 +14,8 @@ name: rector
jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
+ secrets:
+ token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
os: >-
['ubuntu-latest']
diff --git a/composer.json b/composer.json
index 146e877f..3b849c0f 100644
--- a/composer.json
+++ b/composer.json
@@ -38,7 +38,7 @@
"jetbrains/phpstorm-attributes": "^1.0",
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^9.5",
- "rector/rector": "^0.14.3",
+ "rector/rector": "^0.17.7",
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.27",
diff --git a/rector.php b/rector.php
index 37b177c2..6dd991ed 100644
--- a/rector.php
+++ b/rector.php
@@ -4,7 +4,10 @@
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
-use Rector\Php70\Rector\FuncCall\NonVariableToVariableOnFunctionCallRector;
+use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
+use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
+use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
+use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
@@ -16,11 +19,15 @@
// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
- $rectorConfig->skip([
- NonVariableToVariableOnFunctionCallRector::class,
- ]);
// define sets of rules
$rectorConfig->sets([
- LevelSetList::UP_TO_PHP_80,
+ LevelSetList::UP_TO_PHP_81,
+ ]);
+
+ $rectorConfig->skip([
+ ClosureToArrowFunctionRector::class,
+ AddDefaultValueForUndefinedVariableRector::class,
+ NullToStrictStringFuncCallArgRector::class,
+ RemoveExtraParametersRector::class => [__DIR__ . '/src/Generator/AbstractGenerator.php'],
]);
};
diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php
index 119f4466..a49a99ef 100644
--- a/src/Controller/DefaultController.php
+++ b/src/Controller/DefaultController.php
@@ -27,8 +27,8 @@
final class DefaultController
{
public function __construct(
- private DataResponseFactoryInterface $responseFactory,
- private ParametersProvider $parametersProvider,
+ private readonly DataResponseFactoryInterface $responseFactory,
+ private readonly ParametersProvider $parametersProvider,
) {
}
diff --git a/src/Exception/InvalidGeneratorCommandException.php b/src/Exception/InvalidGeneratorCommandException.php
index 8c6ec43c..1bdb0ad1 100644
--- a/src/Exception/InvalidGeneratorCommandException.php
+++ b/src/Exception/InvalidGeneratorCommandException.php
@@ -9,7 +9,7 @@
final class InvalidGeneratorCommandException extends Exception
{
- public function __construct(private Result $result)
+ public function __construct(private readonly Result $result)
{
parent::__construct('Invalid generator data.');
}
diff --git a/src/Generator/AbstractGenerator.php b/src/Generator/AbstractGenerator.php
index d3c11164..dfdfa1b6 100644
--- a/src/Generator/AbstractGenerator.php
+++ b/src/Generator/AbstractGenerator.php
@@ -122,10 +122,7 @@ protected function render(GeneratorCommandInterface $command, string $templateFi
ob_start();
ob_implicit_flush(false);
try {
- /**
- * @noRector \Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector
- * @psalm-suppress PossiblyInvalidFunctionCall
- */
+ /** @psalm-suppress PossiblyInvalidFunctionCall */
$renderer->bindTo($this)($file, array_merge($params, ['command' => $command]));
return ob_get_clean();
} catch (Throwable $e) {
diff --git a/src/Generator/Controller/ControllerCommand.php b/src/Generator/Controller/ControllerCommand.php
index 8c839afb..adb24d6e 100644
--- a/src/Generator/Controller/ControllerCommand.php
+++ b/src/Generator/Controller/ControllerCommand.php
@@ -15,56 +15,50 @@
final class ControllerCommand extends AbstractGeneratorCommand
{
+ #[Each([
+ new Regex(
+ pattern: '/^[a-z][a-z0-9]*$/',
+ message: 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'
+ ),
+ ])]
+ private readonly array $actions;
+
public function __construct(
#[Required]
#[Regex(
pattern: '/^(?:[a-z][a-z0-9]*)(?:\\\\[a-z][a-z0-9]*)*$/i',
message: 'Invalid namespace'
)]
- private string $controllerNamespace = 'App\\Controller',
+ private readonly string $controllerNamespace = 'App\\Controller',
#[Required]
#[Regex(
pattern: '/^[A-Z][a-zA-Z0-9]*Controller$/',
message: 'Only word characters are allowed, and the class name must start with a capital letter and end with "Controller".'
)]
#[NewClassRule]
- /**
- * @var string the controller class name
- */
- private string $controllerClass = 'IndexController',
+ private readonly string $controllerClass = 'IndexController',
/**
* @var string the controller path
*/
- private string $controllerPath = '@src/Controller',
+ private readonly string $controllerPath = '@src/Controller',
/**
* @var string the controller's views path
*/
- private string $viewsPath = '@views/',
+ private readonly string $viewsPath = '@views/',
#[Regex(
pattern: '/^[a-z\\\\]*$/i',
message: 'Only word characters and backslashes are allowed.',
skipOnEmpty: true,
)]
- /**
- * @var string the base class of the controller or null if no parent class present
- */
- private string $baseClass = '',
- #[Each([
- new Regex(
- pattern: '/^[a-z][a-z0-9]*$/',
- message: 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'
- ),
- ])]
- /**
- * @var string[] list of action IDs
- */
- private array $actions = ['index'],
+ private readonly string $baseClass = '',
+ array $actions = ['index'],
#[Required(message: 'A code template must be selected.')]
#[TemplateRule]
protected string $template = 'default',
) {
parent::__construct($template);
- sort($this->actions);
+ sort($actions);
+ $this->actions = $actions;
}
/**
diff --git a/src/Request/GeneratorRequest.php b/src/Request/GeneratorRequest.php
index 4fee64bc..70c9fe25 100644
--- a/src/Request/GeneratorRequest.php
+++ b/src/Request/GeneratorRequest.php
@@ -10,7 +10,7 @@
final class GeneratorRequest extends RequestModel
{
- public function __construct(private GiiInterface $gii)
+ public function __construct(private readonly GiiInterface $gii)
{
}
diff --git a/src/Validator/NewClassHandler.php b/src/Validator/NewClassHandler.php
index 87da369f..dec73ddd 100644
--- a/src/Validator/NewClassHandler.php
+++ b/src/Validator/NewClassHandler.php
@@ -14,7 +14,7 @@
final class NewClassHandler implements RuleHandlerInterface
{
public function __construct(
- private Aliases $aliases,
+ private readonly Aliases $aliases,
) {
}
diff --git a/src/Validator/TemplateRuleHandler.php b/src/Validator/TemplateRuleHandler.php
index d1d3bda9..e2bb4faa 100644
--- a/src/Validator/TemplateRuleHandler.php
+++ b/src/Validator/TemplateRuleHandler.php
@@ -18,9 +18,9 @@
final class TemplateRuleHandler implements RuleHandlerInterface
{
public function __construct(
- private Aliases $aliases,
- private GiiInterface $gii,
- private ParametersProvider $parametersProvider,
+ private readonly Aliases $aliases,
+ private readonly GiiInterface $gii,
+ private readonly ParametersProvider $parametersProvider,
) {
}
diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php
index b467c1ad..058f63b7 100644
--- a/tests/Generators/ControllerGeneratorTest.php
+++ b/tests/Generators/ControllerGeneratorTest.php
@@ -30,7 +30,7 @@ public function testValidGenerator(): void
$this->assertNotEmpty($files);
}
- public function testInvalidGenerator(): void
+ public function testInvalidGenerator(): never
{
$generator = $this->createGenerator(
templates: [
From 8f6a06e5cabfe893f4156f9a8539241f4b8b6a17 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 25 Jul 2023 07:19:12 +0300
Subject: [PATCH 14/29] Update psalm, improve config it and add CI in PHP 8.2
(#100)
Co-authored-by: Sergei Predvoditelev
---
.github/workflows/static.yml | 2 +-
composer.json | 2 +-
psalm.xml | 11 ++++++++---
src/Generator/AbstractGenerator.php | 2 +-
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml
index 58b54078..301ab7c1 100644
--- a/.github/workflows/static.yml
+++ b/.github/workflows/static.yml
@@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
- ['8.1']
+ ['8.1', '8.2']
diff --git a/composer.json b/composer.json
index 3b849c0f..4c98d057 100644
--- a/composer.json
+++ b/composer.json
@@ -41,7 +41,7 @@
"rector/rector": "^0.17.7",
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
- "vimeo/psalm": "^4.27",
+ "vimeo/psalm": "^5.13",
"yiisoft/di": "^1.1",
"yiisoft/dummy-provider": "^1.0",
"yiisoft/event-dispatcher": "^1.0",
diff --git a/psalm.xml b/psalm.xml
index 81eb3520..19c8d795 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,15 +1,20 @@
-
+
-
-
+
+
+
+
+
diff --git a/src/Generator/AbstractGenerator.php b/src/Generator/AbstractGenerator.php
index dfdfa1b6..3fee61e6 100644
--- a/src/Generator/AbstractGenerator.php
+++ b/src/Generator/AbstractGenerator.php
@@ -122,7 +122,7 @@ protected function render(GeneratorCommandInterface $command, string $templateFi
ob_start();
ob_implicit_flush(false);
try {
- /** @psalm-suppress PossiblyInvalidFunctionCall */
+ /** @psalm-suppress PossiblyNullFunctionCall */
$renderer->bindTo($this)($file, array_merge($params, ['command' => $command]));
return ob_get_clean();
} catch (Throwable $e) {
From 83d964f98ef0aaf706da1c61ac80c358c4e85e15 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 25 Jul 2023 20:24:01 +0300
Subject: [PATCH 15/29] Migrate to PHPUnit 10 (#107)
* Update phpunit/phpunit requirement from ^9.5 to ^10.2
Updates the requirements on [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) to permit the latest version.
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.2.6/ChangeLog-10.2.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.0...10.2.6)
---
updated-dependencies:
- dependency-name: phpunit/phpunit
dependency-type: direct:development
...
Signed-off-by: dependabot[bot]
* Migrate to PHPUnit 10
---------
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sergei Predvoditelev
---
.gitignore | 3 +--
composer.json | 2 +-
phpunit.xml.dist | 30 +++++++++++++++---------------
tests/CodeFileTest.php | 9 +++++----
4 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/.gitignore b/.gitignore
index ed1669b6..cd0943ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,8 +27,7 @@ phpunit.phar
/tests/data/config.local.php
/tests/docker
/tests/dockerids
+/.phpunit.cache
# node js
/node_modules
-
-.phpunit.result.cache
diff --git a/composer.json b/composer.json
index 4c98d057..629f8305 100644
--- a/composer.json
+++ b/composer.json
@@ -37,7 +37,7 @@
"require-dev": {
"jetbrains/phpstorm-attributes": "^1.0",
"nyholm/psr7": "^1.5",
- "phpunit/phpunit": "^9.5",
+ "phpunit/phpunit": "^10.2",
"rector/rector": "^0.17.7",
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 3e43103c..4ce94439 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,16 +1,16 @@
-
-
+
@@ -21,9 +21,9 @@
-
+
+
diff --git a/tests/CodeFileTest.php b/tests/CodeFileTest.php
index d84e8069..937ecc59 100644
--- a/tests/CodeFileTest.php
+++ b/tests/CodeFileTest.php
@@ -4,6 +4,7 @@
namespace Yiisoft\Yii\Gii\Tests;
+use PHPUnit\Framework\Attributes\DataProvider;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Yii\Gii\Component\CodeFile\CodeFile;
use Yiisoft\Yii\Gii\Component\CodeFile\CodeFileWriteOperationEnum;
@@ -132,7 +133,7 @@ public function customMethod() {
];
}
- public function dataProviderPreview(): array
+ public static function dataProviderPreview(): array
{
return [
[
@@ -153,7 +154,7 @@ public function dataProviderPreview(): array
];
}
- public function dataProviderConstruct(): array
+ public static function dataProviderConstruct(): array
{
return [
[
@@ -171,7 +172,7 @@ public function dataProviderConstruct(): array
];
}
- /** @dataProvider dataProviderConstruct */
+ #[DataProvider('dataProviderConstruct')]
public function testConstruct(string $path, CodeFileWriteOperationEnum $expectedOperation): void
{
$codeFile = new CodeFile($this->aliases->get($path), '');
@@ -206,7 +207,7 @@ public function testDiffSameContent(): void
$this->assertEquals($codeFile->diff(), '');
}
- /** @dataProvider dataProviderPreview */
+ #[DataProvider('dataProviderPreview')]
public function testPreview(string $path, string $content, $result): void
{
$codeFile = new CodeFile($this->aliases->get($path), $content);
From 9f540e9cd0ba4dfbf72ad51035e7511cfcd9ac4a Mon Sep 17 00:00:00 2001
From: Dmitriy Derepko
Date: Sun, 3 Sep 2023 17:14:00 +0300
Subject: [PATCH 16/29] Active Record generator (#110)
* Add AR generator, fix body parsing
* Apply fixes from StyleCI
* Add table name validator
* Apply fixes from StyleCI
* Expose base class and add validator
* Fix labels and hints
* Fix tests
* Fix tests
* Apply fixes from StyleCI
* Fix db tests
* Uncomment line
* Add properties
* Apply fixes from StyleCI
---------
Co-authored-by: StyleCI Bot
---
composer.json | 4 +
config/params.php | 8 +-
config/routes.php | 6 +
src/Command/ControllerCommand.php | 6 +-
src/Generator/ActiveRecord/Command.php | 94 +++++++++++++++
src/Generator/ActiveRecord/Generator.php | 110 ++++++++++++++++++
src/Generator/ActiveRecord/default/model.php | 38 ++++++
.../{ControllerCommand.php => Command.php} | 2 +-
...{ControllerGenerator.php => Generator.php} | 10 +-
.../Controller/default/controller.php | 2 +-
src/Generator/Controller/default/view.php | 2 +-
src/GeneratorInterface.php | 2 +-
src/ParametersProvider.php | 2 +-
src/Validator/TableExistsHandler.php | 40 +++++++
src/Validator/TableExistsRule.php | 23 ++++
src/Validator/TemplateRuleHandler.php | 2 +-
tests/CodeFileTest.php | 2 +-
.../Generators/ActiveRecordGeneratorTest.php | 93 +++++++++++++++
tests/Generators/ControllerGeneratorTest.php | 38 +++---
tests/GiiTest.php | 2 +-
tests/Support/test.db | Bin 0 -> 8192 bytes
tests/TestCase.php | 98 +++++++++-------
tests/templates/active-record/model.php | 18 +++
.../{custom => controller}/controller.php | 0
.../templates/{custom => controller}/view.php | 0
25 files changed, 524 insertions(+), 78 deletions(-)
create mode 100644 src/Generator/ActiveRecord/Command.php
create mode 100644 src/Generator/ActiveRecord/Generator.php
create mode 100644 src/Generator/ActiveRecord/default/model.php
rename src/Generator/Controller/{ControllerCommand.php => Command.php} (98%)
rename src/Generator/Controller/{ControllerGenerator.php => Generator.php} (89%)
create mode 100644 src/Validator/TableExistsHandler.php
create mode 100644 src/Validator/TableExistsRule.php
create mode 100644 tests/Generators/ActiveRecordGeneratorTest.php
create mode 100644 tests/Support/test.db
create mode 100644 tests/templates/active-record/model.php
rename tests/templates/{custom => controller}/controller.php (100%)
rename tests/templates/{custom => controller}/view.php (100%)
diff --git a/composer.json b/composer.json
index 629f8305..db74eac2 100644
--- a/composer.json
+++ b/composer.json
@@ -20,6 +20,7 @@
"prefer-stable": true,
"require": {
"php": "^8.1",
+ "httpsoft/http-basis": "^1.1",
"phpspec/php-diff": "^1.1.3",
"yiisoft/aliases": "^3.0",
"yiisoft/arrays": "^2.1|^3.0",
@@ -42,6 +43,9 @@
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.13",
+ "yiisoft/active-record": "^3.0@dev",
+ "yiisoft/cache": "^3.0",
+ "yiisoft/db-sqlite": "^1.0",
"yiisoft/di": "^1.1",
"yiisoft/dummy-provider": "^1.0",
"yiisoft/event-dispatcher": "^1.0",
diff --git a/config/params.php b/config/params.php
index f3523b8f..818fb455 100644
--- a/config/params.php
+++ b/config/params.php
@@ -3,7 +3,7 @@
declare(strict_types=1);
use Yiisoft\Yii\Gii\Command\ControllerCommand;
-use Yiisoft\Yii\Gii\Generator\Controller\ControllerGenerator;
+use Yiisoft\Yii\Gii\Generator as Generators;
return [
'yiisoft/yii-debug' => [
@@ -26,7 +26,11 @@
'allowedIPs' => ['127.0.0.1', '::1'],
'generators' => [
[
- 'class' => ControllerGenerator::class,
+ 'class' => Generators\Controller\Generator::class,
+ 'parameters' => [],
+ ],
+ [
+ 'class' => Generators\ActiveRecord\Generator::class,
'parameters' => [],
],
],
diff --git a/config/routes.php b/config/routes.php
index 80d98d63..b457c242 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -6,7 +6,9 @@
* @var array $params
*/
+use HttpSoft\Basis\Middleware\BodyParamsMiddleware;
use Psr\Http\Message\ResponseFactoryInterface;
+use Yiisoft\Csrf\CsrfMiddleware;
use Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson;
use Yiisoft\Router\Group;
use Yiisoft\Router\Route;
@@ -22,6 +24,7 @@
return [
Group::create('/gii/api')
->withCors(CorsAllowAll::class)
+ ->disableMiddleware(CsrfMiddleware::class)
->middleware(
static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $validator) use ($params) {
return new IpFilter(
@@ -43,12 +46,15 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $
->action([DefaultController::class, 'get'])
->name('generator'),
Route::post('/{generator}/preview')
+ ->middleware(BodyParamsMiddleware::class)
->action([DefaultController::class, 'preview'])
->name('preview'),
Route::post('/{generator}/generate')
+ ->middleware(BodyParamsMiddleware::class)
->action([DefaultController::class, 'generate'])
->name('generate'),
Route::post('/{generator}/diff')
+ ->middleware(BodyParamsMiddleware::class)
->action([DefaultController::class, 'diff'])
->name('diff')
)
diff --git a/src/Command/ControllerCommand.php b/src/Command/ControllerCommand.php
index d2bf22a6..ab7dd64e 100644
--- a/src/Command/ControllerCommand.php
+++ b/src/Command/ControllerCommand.php
@@ -6,7 +6,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
-use Yiisoft\Yii\Gii\Generator\Controller\ControllerGenerator;
+use Yiisoft\Yii\Gii\Generator\Controller\Generator;
use Yiisoft\Yii\Gii\GeneratorCommandInterface;
use Yiisoft\Yii\Gii\GeneratorInterface;
@@ -36,7 +36,7 @@ protected function configure(): void
public function getGenerator(): GeneratorInterface
{
- return $this->gii->getGenerator(ControllerGenerator::getId());
+ return $this->gii->getGenerator(Generator::getId());
}
protected function createGeneratorCommand(InputInterface $input): GeneratorCommandInterface
@@ -47,7 +47,7 @@ protected function createGeneratorCommand(InputInterface $input): GeneratorComma
$template = $input->getOption('template');
$template ??= 'default';
- return new \Yiisoft\Yii\Gii\Generator\Controller\ControllerCommand(
+ return new \Yiisoft\Yii\Gii\Generator\Controller\Command(
controllerClass: $input->getArgument('controllerClass'),
viewsPath: (string)$input->getOption('viewsPath'),
baseClass: (string)$input->getOption('baseClass'),
diff --git a/src/Generator/ActiveRecord/Command.php b/src/Generator/ActiveRecord/Command.php
new file mode 100644
index 00000000..ae26fd44
--- /dev/null
+++ b/src/Generator/ActiveRecord/Command.php
@@ -0,0 +1,94 @@
+namespace;
+ }
+
+ public function getBaseClass(): string
+ {
+ return $this->baseClass;
+ }
+
+ public function getTableName(): string
+ {
+ return $this->tableName;
+ }
+
+ public function getModelName(): string
+ {
+ return (new Inflector())->tableToClass($this->tableName);
+ }
+
+ public static function getAttributeLabels(): array
+ {
+ return [
+ 'namespace' => 'Model namespace',
+ 'baseClass' => 'Base class',
+ 'tableName' => 'Table name',
+ 'template' => 'Template',
+ ];
+ }
+
+ public static function getHints(): array
+ {
+ return [
+ 'namespace' => 'Namespace for the model class to store it in the related directory.',
+ 'baseClass' => 'Parent class for the new model class.',
+ 'tableName' => 'Corresponded table name for the model class.',
+ ];
+ }
+
+ public static function getAttributes(): array
+ {
+ return [
+ 'namespace',
+ 'tableName',
+ 'baseClass',
+ 'template',
+ ];
+ }
+}
diff --git a/src/Generator/ActiveRecord/Generator.php b/src/Generator/ActiveRecord/Generator.php
new file mode 100644
index 00000000..1c8d690f
--- /dev/null
+++ b/src/Generator/ActiveRecord/Generator.php
@@ -0,0 +1,110 @@
+aliases->get('@root');
+
+ $properties = [];
+ if ($schema = $this->connection->getTableSchema($command->getTableName(), true)) {
+ foreach ($schema->getColumns() as $columnSchema) {
+ $properties[] = [
+ 'name' => $columnSchema->getName(),
+ 'type' => match ($columnSchema->getPhpType()) {
+ 'integer' => 'int',
+ default => 'string',
+ },
+ 'isAllowNull' => $columnSchema->isAllowNull(),
+ 'defaultValue' => $columnSchema->getDefaultValue(),
+ ];
+ }
+ }
+ $path = $this->getControllerFile($command);
+ $codeFile = (new CodeFile(
+ $path,
+ $this->render($command, 'model.php', ['properties' => $properties])
+ ))->withBasePath($rootPath);
+ $files[$codeFile->getId()] = $codeFile;
+
+ return $files;
+ }
+
+ /**
+ * @return string the controller class file path
+ */
+ private function getControllerFile(Command $command): string
+ {
+ $directory = '@src/Model/';
+
+ return $this->aliases->get(
+ str_replace(
+ ['\\', '//'],
+ '/',
+ sprintf(
+ '%s/%s.php',
+ $directory,
+ $command->getModelName(),
+ ),
+ ),
+ );
+ }
+
+ public static function getCommandClass(): string
+ {
+ return Command::class;
+ }
+}
diff --git a/src/Generator/ActiveRecord/default/model.php b/src/Generator/ActiveRecord/default/model.php
new file mode 100644
index 00000000..6eff74b7
--- /dev/null
+++ b/src/Generator/ActiveRecord/default/model.php
@@ -0,0 +1,38 @@
+ $properties
+ */
+
+echo "
+
+declare(strict_types=1);
+
+namespace = $command->getNamespace() ?>;
+
+use = $command->getBaseClass() ?>;
+
+final class = $command->getModelName(); ?> extends = StringHelper::baseName($command->getBaseClass()) . PHP_EOL ?>
+{
+
+ private =sprintf(
+ '%s%s $%s',
+ $property['isAllowNull'] ? '?' : '',
+ $property['type'],
+ $property['name'],
+ )?>;
+
+
+ public function tableName(): string
+ {
+ return '= $command->getTableName() ?>';
+ }
+}
diff --git a/src/Generator/Controller/ControllerCommand.php b/src/Generator/Controller/Command.php
similarity index 98%
rename from src/Generator/Controller/ControllerCommand.php
rename to src/Generator/Controller/Command.php
index adb24d6e..f4ef38cb 100644
--- a/src/Generator/Controller/ControllerCommand.php
+++ b/src/Generator/Controller/Command.php
@@ -13,7 +13,7 @@
use Yiisoft\Yii\Gii\Validator\NewClassRule;
use Yiisoft\Yii\Gii\Validator\TemplateRule;
-final class ControllerCommand extends AbstractGeneratorCommand
+final class Command extends AbstractGeneratorCommand
{
#[Each([
new Regex(
diff --git a/src/Generator/Controller/ControllerGenerator.php b/src/Generator/Controller/Generator.php
similarity index 89%
rename from src/Generator/Controller/ControllerGenerator.php
rename to src/Generator/Controller/Generator.php
index a02f6678..e8098448 100644
--- a/src/Generator/Controller/ControllerGenerator.php
+++ b/src/Generator/Controller/Generator.php
@@ -12,7 +12,7 @@
/**
* This generator will generate a controller and one or a few action view files.
*/
-final class ControllerGenerator extends AbstractGenerator
+final class Generator extends AbstractGenerator
{
public static function getId(): string
{
@@ -40,7 +40,7 @@ public function getRequiredTemplates(): array
public function doGenerate(GeneratorCommandInterface $command): array
{
- if (!$command instanceof ControllerCommand) {
+ if (!$command instanceof Command) {
throw new InvalidArgumentException();
}
@@ -68,7 +68,7 @@ public function doGenerate(GeneratorCommandInterface $command): array
/**
* @return string the controller class file path
*/
- private function getControllerFile(ControllerCommand $command): string
+ private function getControllerFile(Command $command): string
{
$directory = empty($command->getDirectory()) ? '@src/Controller/' : $command->getDirectory();
@@ -90,7 +90,7 @@ private function getControllerFile(ControllerCommand $command): string
*
* @return string the action view file path
*/
- public function getViewFile(ControllerCommand $command, string $action): string
+ public function getViewFile(Command $command, string $action): string
{
$directory = empty($command->getViewsPath()) ? '@views/' : $command->getViewsPath();
@@ -110,6 +110,6 @@ public function getViewFile(ControllerCommand $command, string $action): string
public static function getCommandClass(): string
{
- return ControllerCommand::class;
+ return Command::class;
}
}
diff --git a/src/Generator/Controller/default/controller.php b/src/Generator/Controller/default/controller.php
index fc5b6533..bf2c307e 100644
--- a/src/Generator/Controller/default/controller.php
+++ b/src/Generator/Controller/default/controller.php
@@ -6,7 +6,7 @@
use Yiisoft\Strings\StringHelper;
-/* @var $command Yiisoft\Yii\Gii\Generator\Controller\ControllerCommand */
+/* @var $command Yiisoft\Yii\Gii\Generator\Controller\Command */
$classDefinitionParts = [];
$classDefinitionParts[] = StringHelper::baseName($command->getControllerClass());
diff --git a/src/Generator/Controller/default/view.php b/src/Generator/Controller/default/view.php
index c0b546d3..d3fc5dc0 100644
--- a/src/Generator/Controller/default/view.php
+++ b/src/Generator/Controller/default/view.php
@@ -4,7 +4,7 @@
* This is the template for generating an action view file.
*/
-/* @var $command Yiisoft\Yii\Gii\Generator\Controller\ControllerCommand */
+/* @var $command Yiisoft\Yii\Gii\Generator\Controller\Command */
/* @var $action string the action ID */
echo "> a list of available code templates. The array keys are the template names,
* and the array values are the corresponding template paths or path aliases.
*/
- private array $templates = [],
+ private readonly array $templates = [],
) {
}
diff --git a/src/Validator/TableExistsHandler.php b/src/Validator/TableExistsHandler.php
new file mode 100644
index 00000000..6f550940
--- /dev/null
+++ b/src/Validator/TableExistsHandler.php
@@ -0,0 +1,40 @@
+connection->getTableSchema($value);
+
+ if ($tableSchema === null) {
+ $result->addError(sprintf('Table "%s" does not exist.', $value));
+ return $result;
+ }
+
+ return $result;
+ }
+}
diff --git a/src/Validator/TableExistsRule.php b/src/Validator/TableExistsRule.php
new file mode 100644
index 00000000..1f5a3ef7
--- /dev/null
+++ b/src/Validator/TableExistsRule.php
@@ -0,0 +1,23 @@
+createGenerator();
+ $command = new Command(
+ namespace: 'App\\Model',
+ tableName: 'user',
+ baseClass: ActiveRecord::class,
+ template: 'default',
+ );
+
+ $files = $generator->generate($command);
+
+ $this->assertNotEmpty($files);
+ }
+
+ public function testInvalidTableName(): void
+ {
+ $generator = $this->createGenerator();
+ $command = new Command(
+ namespace: 'App\\Model',
+ tableName: 'user2',
+ baseClass: ActiveRecord::class,
+ template: 'default',
+ );
+
+ $this->expectException(InvalidGeneratorCommandException::class);
+ $generator->generate($command);
+ }
+
+ public function testInvalidGenerator(): void
+ {
+ $generator = $this->createGenerator(
+ templates: [
+ 'default' => dirname(__DIR__ . '../templates'),
+ ],
+ );
+ $command = new Command(
+ namespace: '0App',
+ template: 'test',
+ );
+
+ $this->expectException(InvalidGeneratorCommandException::class);
+ $generator->generate($command);
+ }
+
+ public function testCustomTemplate(): void
+ {
+ $generator = $this->createGenerator(
+ templates: [
+ Generator::getId() => [
+ 'custom' => '@src/templates/active-record',
+ ],
+ ],
+ );
+ $command = new Command(
+ namespace: 'App\\Model',
+ tableName: 'user',
+ baseClass: ActiveRecord::class,
+ template: 'custom',
+ );
+
+ $files = $generator->generate($command);
+ $this->assertNotEmpty($files);
+ $this->assertMatchesRegularExpression('/final custom class/', reset($files)->getContent());
+ }
+
+ private function createGenerator(...$params): Generator
+ {
+ $injector = new Injector(
+ $this->getContainer([
+ ParametersProvider::class => new ParametersProvider(...$params),
+ ])
+ );
+
+ return $injector->make(Generator::class);
+ }
+}
diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php
index 058f63b7..307bf748 100644
--- a/tests/Generators/ControllerGeneratorTest.php
+++ b/tests/Generators/ControllerGeneratorTest.php
@@ -6,20 +6,17 @@
use Yiisoft\Injector\Injector;
use Yiisoft\Yii\Gii\Exception\InvalidGeneratorCommandException;
-use Yiisoft\Yii\Gii\Generator\Controller\ControllerCommand;
-use Yiisoft\Yii\Gii\Generator\Controller\ControllerGenerator as ControllerGenerator;
+use Yiisoft\Yii\Gii\Generator\Controller\Command;
+use Yiisoft\Yii\Gii\Generator\Controller\Generator;
use Yiisoft\Yii\Gii\ParametersProvider;
use Yiisoft\Yii\Gii\Tests\TestCase;
-/**
- * ControllerGeneratorTest checks that Gii controller generator produces valid results
- */
-class ControllerGeneratorTest extends TestCase
+final class ControllerGeneratorTest extends TestCase
{
public function testValidGenerator(): void
{
$generator = $this->createGenerator();
- $command = new ControllerCommand(
+ $command = new Command(
controllerClass: 'TestController',
actions: ['index', 'edit', 'view'],
template: 'default',
@@ -37,7 +34,7 @@ public function testInvalidGenerator(): never
'default' => dirname(__DIR__ . '../templates'),
],
);
- $command = new ControllerCommand(
+ $command = new Command(
controllerClass: 'Wr0ngContr0ller',
actions: ['index', 'ed1t', 'view'],
template: 'test',
@@ -58,25 +55,32 @@ public function testCustomTemplate(): void
{
$generator = $this->createGenerator(
templates: [
- 'custom' => '@src/templates/custom',
+ Generator::getId() => [
+ 'custom' => '@src/templates/controller',
+ ],
],
);
- $command = new ControllerCommand(
+ $command = new Command(
controllerClass: 'TestController',
actions: ['index', 'edit', 'view'],
template: 'custom',
);
- $this->expectException(InvalidGeneratorCommandException::class);
- $generator->generate($command);
+ $files = $generator->generate($command);
+ $this->assertNotEmpty($files);
+ foreach ($files as $file) {
+ $this->assertEmpty($file->getContent());
+ }
}
- private function createGenerator(...$params): ControllerGenerator
+ private function createGenerator(...$params): Generator
{
- $injector = new Injector($this->getContainer());
+ $injector = new Injector(
+ $this->getContainer([
+ ParametersProvider::class => new ParametersProvider(...$params),
+ ])
+ );
- return $injector->make(ControllerGenerator::class, [
- new ParametersProvider(...$params),
- ]);
+ return $injector->make(Generator::class);
}
}
diff --git a/tests/GiiTest.php b/tests/GiiTest.php
index 16a183c5..483cf389 100644
--- a/tests/GiiTest.php
+++ b/tests/GiiTest.php
@@ -10,7 +10,7 @@
/**
* GiiTestCase is the base class for all gii related test cases
*/
-class GiiTest extends TestCase
+final class GiiTest extends TestCase
{
public function testUnknownGeneratorInstance(): void
{
diff --git a/tests/Support/test.db b/tests/Support/test.db
new file mode 100644
index 0000000000000000000000000000000000000000..32e7cfb5ac46f1cdd02b650bf1646c7215bb2600
GIT binary patch
literal 8192
zcmeI#u?oU45XSMlB2G$Oij#13QVw%G&qrDN3by++$y3XdO_o~hN3l(-^Q`-f|C>wr
c?v6MkfB*srAbwithDefinitions([
- GiiInterface::class => function (ContainerInterface $container) {
- $generators = [
- 'controller' => ControllerGenerator::class,
- ];
- $generatorsInstances = [];
- foreach ($generators as $class) {
- $generatorsInstances[] = $container->get($class);
- }
- return new Gii($generatorsInstances);
- },
- Aliases::class => new Aliases(
- [
- '@src' => __DIR__,
- '@views' => '@src/runtime',
- '@view' => '@src/runtime',
- '@root' => '@src/runtime',
- ]
- ),
- EventDispatcherInterface::class => Dispatcher::class,
- ListenerProviderInterface::class => Provider::class,
- LoggerInterface::class => NullLogger::class,
- TranslatorInterface::class => [
- 'class' => Translator::class,
- '__construct()' => [
- 'locale' => 'en',
- 'fallbackLocale' => 'en',
- 'eventDispatcher' => Reference::to(EventDispatcherInterface::class),
- ],
- ],
- RuleHandlerResolverInterface::class => RuleHandlerContainer::class,
- ValidatorInterface::class => Validator::class,
- ]);
- $this->container = new Container($config);
}
protected function tearDown(): void
@@ -82,8 +48,54 @@ protected function tearDown(): void
$this->container = null;
}
- protected function getContainer(): ContainerInterface
+ protected function getContainer(array $definitions = []): ContainerInterface
{
+ if ($this->container === null) {
+ $config = ContainerConfig::create()
+ ->withDefinitions([
+ GiiInterface::class => function (ContainerInterface $container) {
+ $generators = [
+ Generators\Controller\Generator::getId() => Generators\Controller\Generator::class,
+ Generators\ActiveRecord\Generator::getId() => Generators\ActiveRecord\Generator::class,
+ ];
+ $generatorsInstances = [];
+ foreach ($generators as $class) {
+ $generatorsInstances[] = $container->get($class);
+ }
+ return new Gii($generatorsInstances);
+ },
+ Aliases::class => new Aliases(
+ [
+ '@src' => __DIR__,
+ '@views' => '@src/runtime',
+ '@view' => '@src/runtime',
+ '@root' => '@src/runtime',
+ ]
+ ),
+ EventDispatcherInterface::class => Dispatcher::class,
+ ListenerProviderInterface::class => Provider::class,
+ LoggerInterface::class => NullLogger::class,
+ TranslatorInterface::class => [
+ 'class' => Translator::class,
+ '__construct()' => [
+ 'locale' => 'en',
+ 'fallbackLocale' => 'en',
+ 'eventDispatcher' => Reference::to(EventDispatcherInterface::class),
+ ],
+ ],
+ RuleHandlerResolverInterface::class => RuleHandlerContainer::class,
+ ValidatorInterface::class => Validator::class,
+ CacheInterface::class => NullCache::class,
+ ConnectionInterface::class => [
+ 'class' => SqliteConnection::class,
+ '__construct()' => [
+ new Driver('sqlite:' . __DIR__ . '/Support/test.db'),
+ ],
+ ],
+ ...$definitions,
+ ]);
+ $this->container = new Container($config);
+ }
return $this->container;
}
}
diff --git a/tests/templates/active-record/model.php b/tests/templates/active-record/model.php
new file mode 100644
index 00000000..4c89e7ee
--- /dev/null
+++ b/tests/templates/active-record/model.php
@@ -0,0 +1,18 @@
+
+
+declare(strict_types=1);
+
+namespace = $command->getNamespace() ?>;
+
+use = $command->getBaseClass() ?>;
+
+final custom class = $command->getModelName(); ?>
diff --git a/tests/templates/custom/controller.php b/tests/templates/controller/controller.php
similarity index 100%
rename from tests/templates/custom/controller.php
rename to tests/templates/controller/controller.php
diff --git a/tests/templates/custom/view.php b/tests/templates/controller/view.php
similarity index 100%
rename from tests/templates/custom/view.php
rename to tests/templates/controller/view.php
From d0be0507c59293dc47aba205e028534dcb648872 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 26 Sep 2023 11:17:25 +0300
Subject: [PATCH 17/29] Update rector/rector requirement from ^0.17.7 to
^0.18.4 (#114)
Co-authored-by: Sergei Predvoditelev
---
composer.json | 2 +-
rector.php | 2 --
src/Generator/ActiveRecord/Generator.php | 2 +-
3 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/composer.json b/composer.json
index db74eac2..d462b375 100644
--- a/composer.json
+++ b/composer.json
@@ -39,7 +39,7 @@
"jetbrains/phpstorm-attributes": "^1.0",
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^10.2",
- "rector/rector": "^0.17.7",
+ "rector/rector": "^0.18.4",
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.13",
diff --git a/rector.php b/rector.php
index 6dd991ed..8a6cdc9e 100644
--- a/rector.php
+++ b/rector.php
@@ -4,7 +4,6 @@
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
-use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
@@ -26,7 +25,6 @@
$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
- AddDefaultValueForUndefinedVariableRector::class,
NullToStrictStringFuncCallArgRector::class,
RemoveExtraParametersRector::class => [__DIR__ . '/src/Generator/AbstractGenerator.php'],
]);
diff --git a/src/Generator/ActiveRecord/Generator.php b/src/Generator/ActiveRecord/Generator.php
index 1c8d690f..c625fe62 100644
--- a/src/Generator/ActiveRecord/Generator.php
+++ b/src/Generator/ActiveRecord/Generator.php
@@ -22,7 +22,7 @@ public function __construct(
Aliases $aliases,
ValidatorInterface $validator,
ParametersProvider $parametersProvider,
- private ConnectionInterface $connection,
+ private readonly ConnectionInterface $connection,
) {
parent::__construct($aliases, $validator, $parametersProvider);
}
From e10310cdfea611b17a3b851d17fb66e689055248 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Thu, 5 Oct 2023 15:59:43 +0300
Subject: [PATCH 18/29] Remove generators from params (#115)
---
config/params.php | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/config/params.php b/config/params.php
index 818fb455..56e71694 100644
--- a/config/params.php
+++ b/config/params.php
@@ -3,7 +3,6 @@
declare(strict_types=1);
use Yiisoft\Yii\Gii\Command\ControllerCommand;
-use Yiisoft\Yii\Gii\Generator as Generators;
return [
'yiisoft/yii-debug' => [
@@ -24,16 +23,7 @@
'yiisoft/yii-gii' => [
'enabled' => true,
'allowedIPs' => ['127.0.0.1', '::1'],
- 'generators' => [
- [
- 'class' => Generators\Controller\Generator::class,
- 'parameters' => [],
- ],
- [
- 'class' => Generators\ActiveRecord\Generator::class,
- 'parameters' => [],
- ],
- ],
+ 'generators' => [],
'parameters' => [
'templates' => [],
],
From 31f915803e93a07cf3fc44adab4360907ec36819 Mon Sep 17 00:00:00 2001
From: Dmitriy Derepko
Date: Sun, 8 Oct 2023 14:05:03 +0300
Subject: [PATCH 19/29] Lazy generators (#116)
* Make generators lazy
* Apply fixes from StyleCI
* Revert generators
* Add AR generator
---------
Co-authored-by: StyleCI Bot
---
config/di.php | 6 +++---
config/params.php | 12 +++++++++++-
src/Gii.php | 17 ++++++++++-------
src/GiiInterface.php | 6 +++++-
4 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/config/di.php b/config/di.php
index 3f8dc62c..fe6fc121 100644
--- a/config/di.php
+++ b/config/di.php
@@ -20,10 +20,10 @@
foreach ($generators as $generator) {
$class = $generator['class'];
/**
- * @var $generator GeneratorInterface
+ * @var $loader Closure(): GeneratorInterface
*/
- $generator = $injector->make($class, $generator['parameters'] ?? []);
- $generatorsInstances[] = $generator;
+ $loader = fn() => $injector->make($class, $generator['parameters'] ?? []);
+ $generatorsInstances[$class] = $loader;
}
return new Gii($generatorsInstances);
},
diff --git a/config/params.php b/config/params.php
index 56e71694..818fb455 100644
--- a/config/params.php
+++ b/config/params.php
@@ -3,6 +3,7 @@
declare(strict_types=1);
use Yiisoft\Yii\Gii\Command\ControllerCommand;
+use Yiisoft\Yii\Gii\Generator as Generators;
return [
'yiisoft/yii-debug' => [
@@ -23,7 +24,16 @@
'yiisoft/yii-gii' => [
'enabled' => true,
'allowedIPs' => ['127.0.0.1', '::1'],
- 'generators' => [],
+ 'generators' => [
+ [
+ 'class' => Generators\Controller\Generator::class,
+ 'parameters' => [],
+ ],
+ [
+ 'class' => Generators\ActiveRecord\Generator::class,
+ 'parameters' => [],
+ ],
+ ],
'parameters' => [
'templates' => [],
],
diff --git a/src/Gii.php b/src/Gii.php
index 8c6d1cd0..002b8a98 100644
--- a/src/Gii.php
+++ b/src/Gii.php
@@ -4,19 +4,19 @@
namespace Yiisoft\Yii\Gii;
+use Closure;
use Yiisoft\Yii\Gii\Exception\GeneratorNotFoundException;
+/**
+ * @psalm-import-type LazyGenerator from GiiInterface
+ */
final class Gii implements GiiInterface
{
/**
- * @param array $generators
+ * @param array $generators
*/
public function __construct(private array $generators)
{
- $this->generators = array_combine(
- array_map(fn (GeneratorInterface $generator) => $generator::getId(), $generators),
- array_values($this->generators)
- );
}
public function addGenerator(GeneratorInterface $generator): void
@@ -30,11 +30,14 @@ public function getGenerator(string $id): GeneratorInterface
throw new GeneratorNotFoundException('Generator "' . $id . '" not found');
}
- return $this->generators[$id];
+ return $this->generators[$id] instanceof Closure ? $this->generators[$id]() : $this->generators[$id];
}
public function getGenerators(): array
{
- return $this->generators;
+ return array_map(
+ fn (Closure|GeneratorInterface $generator) => $generator instanceof Closure ? $generator() : $generator,
+ $this->generators
+ );
}
}
diff --git a/src/GiiInterface.php b/src/GiiInterface.php
index 2462000f..614435d3 100644
--- a/src/GiiInterface.php
+++ b/src/GiiInterface.php
@@ -4,12 +4,16 @@
namespace Yiisoft\Yii\Gii;
+use Closure;
use Yiisoft\Yii\Gii\Exception\GeneratorNotFoundException;
+/**
+ * @psalm-type LazyGenerator = Closure(): GeneratorInterface
+ */
interface GiiInterface
{
/**
- * @param GeneratorInterface $generator
+ * @psalm-param GeneratorInterface $generator
*/
public function addGenerator(GeneratorInterface $generator): void;
From 31d9506b4cab6d87b40abc98117ceb7d0e8698aa Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Tue, 10 Oct 2023 16:01:31 +0300
Subject: [PATCH 20/29] Replace Yii Request Model to Yii Input HTTP (#118)
---
composer.json | 3 ++-
src/Controller/DefaultController.php | 2 +-
src/Request/GeneratorRequest.php | 21 ++++++++++++++++-----
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/composer.json b/composer.json
index d462b375..f083adfc 100644
--- a/composer.json
+++ b/composer.json
@@ -26,9 +26,10 @@
"yiisoft/arrays": "^2.1|^3.0",
"yiisoft/data-response": "^2.0",
"yiisoft/http": "^1.2",
+ "yiisoft/hydrator": "dev-master",
"yiisoft/injector": "^1.1",
+ "yiisoft/input-http": "dev-master",
"yiisoft/json": "^1.0",
- "yiisoft/request-model": "dev-master",
"yiisoft/router": "^3.0",
"yiisoft/strings": "^2.1",
"yiisoft/validator": "^1.0",
diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php
index a49a99ef..24ff60d0 100644
--- a/src/Controller/DefaultController.php
+++ b/src/Controller/DefaultController.php
@@ -10,7 +10,7 @@
use Yiisoft\DataResponse\DataResponse;
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use Yiisoft\Http\Status;
-use Yiisoft\RequestModel\Attribute\Query;
+use Yiisoft\Input\Http\Attribute\Parameter\Query;
use Yiisoft\Validator\Helper\RulesDumper;
use Yiisoft\Validator\RulesProvider\AttributesRulesProvider;
use Yiisoft\Yii\Gii\Component\CodeFile\CodeFile;
diff --git a/src/Request/GeneratorRequest.php b/src/Request/GeneratorRequest.php
index 70c9fe25..e63568a0 100644
--- a/src/Request/GeneratorRequest.php
+++ b/src/Request/GeneratorRequest.php
@@ -4,28 +4,39 @@
namespace Yiisoft\Yii\Gii\Request;
-use Yiisoft\RequestModel\RequestModel;
+use Yiisoft\Hydrator\Temp\RouteArgument;
+use Yiisoft\Input\Http\Attribute\Parameter\Body;
+use Yiisoft\Input\Http\RequestInputInterface;
use Yiisoft\Yii\Gii\GeneratorInterface;
use Yiisoft\Yii\Gii\GiiInterface;
-final class GeneratorRequest extends RequestModel
+final class GeneratorRequest implements RequestInputInterface
{
+ #[RouteArgument('generator')]
+ private string $generatorId = '';
+
+ #[Body('answers')]
+ private array $answers = [];
+
+ #[Body('parameters')]
+ private array $parameters = [];
+
public function __construct(private readonly GiiInterface $gii)
{
}
public function getGenerator(): GeneratorInterface
{
- return $this->gii->getGenerator($this->getAttributeValue('router.generator'));
+ return $this->gii->getGenerator($this->generatorId);
}
public function getAnswers(): array
{
- return $this->getAttributeValue('body.answers', []);
+ return $this->answers;
}
public function getBody(): array
{
- return $this->getAttributeValue('body.parameters', []);
+ return $this->parameters;
}
}
From 747502a9b17e5a4c7bbf2c04f691faee28c7a2cb Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 9 Jan 2024 10:26:01 +0300
Subject: [PATCH 21/29] Update rector/rector requirement from ^0.18.4 to
^0.19.0 (#119)
Updates the requirements on [rector/rector](https://github.com/rectorphp/rector) to permit the latest version.
- [Release notes](https://github.com/rectorphp/rector/releases)
- [Commits](https://github.com/rectorphp/rector/compare/0.18.4...0.19.0)
---
updated-dependencies:
- dependency-name: rector/rector
dependency-type: direct:development
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index f083adfc..14fe4bc2 100644
--- a/composer.json
+++ b/composer.json
@@ -40,7 +40,7 @@
"jetbrains/phpstorm-attributes": "^1.0",
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^10.2",
- "rector/rector": "^0.18.4",
+ "rector/rector": "^0.19.0",
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.13",
From fcd87d32c59cec0d73378e4b58d9bbae5b373c85 Mon Sep 17 00:00:00 2001
From: Alexander Makarov
Date: Mon, 22 Jan 2024 20:26:53 +0300
Subject: [PATCH 22/29] Add "dev" to composer.json keywords
---
composer.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 14fe4bc2..7128c75d 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,8 @@
"keywords": [
"yii",
"gii",
- "code generator"
+ "code generator",
+ "dev"
],
"license": "BSD-3-Clause",
"support": {
From 18f91ca6e5d697058a823494ffe63daccd61afb6 Mon Sep 17 00:00:00 2001
From: Alexander Makarov
Date: Mon, 29 Jan 2024 13:50:31 +0300
Subject: [PATCH 23/29] Use stable yiisoft/hydrator
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 7128c75d..0e96c0c0 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,7 @@
"yiisoft/arrays": "^2.1|^3.0",
"yiisoft/data-response": "^2.0",
"yiisoft/http": "^1.2",
- "yiisoft/hydrator": "dev-master",
+ "yiisoft/hydrator": "^1.0",
"yiisoft/injector": "^1.1",
"yiisoft/input-http": "dev-master",
"yiisoft/json": "^1.0",
From 9ba020aabb812dc7e2949b7cea91a1acc17ef50e Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 7 Feb 2024 10:40:35 +0300
Subject: [PATCH 24/29] Update rector/rector requirement from ^0.19.0 to ^1.0.0
(#121)
Updates the requirements on [rector/rector](https://github.com/rectorphp/rector) to permit the latest version.
- [Release notes](https://github.com/rectorphp/rector/releases)
- [Commits](https://github.com/rectorphp/rector/compare/0.19.0...1.0.0)
---
updated-dependencies:
- dependency-name: rector/rector
dependency-type: direct:development
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 0e96c0c0..0cd25c18 100644
--- a/composer.json
+++ b/composer.json
@@ -41,7 +41,7 @@
"jetbrains/phpstorm-attributes": "^1.0",
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^10.2",
- "rector/rector": "^0.19.0",
+ "rector/rector": "^1.0.0",
"roave/infection-static-analysis-plugin": "^1.23",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.13",
From 06562e2b8baa92738320e3801618fe1ee554b465 Mon Sep 17 00:00:00 2001
From: Alexey Rogachev
Date: Tue, 26 Mar 2024 18:11:50 +0500
Subject: [PATCH 25/29] Use stable version of `input-http` (#122)
* Use stable version of input-http
* Update PR template [skip ci]
---
.github/PULL_REQUEST_TEMPLATE.md | 1 -
composer.json | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 4a3e8ace..6be5d587 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -3,4 +3,3 @@
| Is bugfix? | ✔️/❌
| New feature? | ✔️/❌
| Breaks BC? | ✔️/❌
-| Fixed issues | comma-separated list of tickets # fixed by the PR, if any
diff --git a/composer.json b/composer.json
index 0cd25c18..fc434ec8 100644
--- a/composer.json
+++ b/composer.json
@@ -29,7 +29,7 @@
"yiisoft/http": "^1.2",
"yiisoft/hydrator": "^1.0",
"yiisoft/injector": "^1.1",
- "yiisoft/input-http": "dev-master",
+ "yiisoft/input-http": "^1.0",
"yiisoft/json": "^1.0",
"yiisoft/router": "^3.0",
"yiisoft/strings": "^2.1",
From 38adb9eb9f3f7e1a4363f43c7eb8db71cc6f2f56 Mon Sep 17 00:00:00 2001
From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com>
Date: Mon, 22 Apr 2024 17:34:34 -0300
Subject: [PATCH 26/29] Docs folder standardization and other fixes (#126)
---
LICENSE.md | 8 +-
README.md | 34 +++++--
composer.json | 2 +-
docs/guide-pt-BR/images/gii-entry.png | Bin 45302 -> 0 bytes
docs/guide-pt-BR/images/gii-preview.png | Bin 41620 -> 0 bytes
docs/guide-ru/README.md | 20 -----
docs/guide-ru/basic-usage.md | 41 ---------
docs/guide-ru/images/gii-entry.png | Bin 45302 -> 0 bytes
docs/guide-ru/images/gii-preview.png | Bin 41620 -> 0 bytes
docs/guide-ru/installation.md | 85 ------------------
.../topics-creating-your-own-generators.md | 47 ----------
.../topics-creating-your-own-templates.md | 54 -----------
docs/guide-uk/README.md | 20 -----
docs/guide-uk/basic-usage.md | 46 ----------
docs/guide-uk/images/gii-entry.png | Bin 45302 -> 0 bytes
docs/guide-uk/images/gii-preview.png | Bin 41620 -> 0 bytes
docs/guide-uk/installation.md | 58 ------------
.../topics-creating-your-own-generators.md | 48 ----------
.../topics-creating-your-own-templates.md | 55 ------------
docs/guide-zh-CN/images/gii-entry.png | Bin 45302 -> 0 bytes
docs/guide-zh-CN/images/gii-preview.png | Bin 41620 -> 0 bytes
docs/guide/README.md | 28 ++----
docs/guide/{ => en}/basic-usage.md | 9 +-
docs/guide/{ => en}/installation.md | 0
docs/guide/en/readme.md | 20 +++++
.../topics-creating-your-own-generators.md | 0
.../topics-creating-your-own-templates.md | 0
docs/guide/images/gii-entry.png | Bin 45302 -> 0 bytes
docs/guide/images/gii-preview.png | Bin 41620 -> 0 bytes
docs/{guide-ja => guide/ja}/basic-usage.md | 7 +-
docs/{guide-ja => guide/ja}/installation.md | 0
.../README.md => guide/ja/readme.md} | 0
.../topics-creating-your-own-generators.md | 0
.../ja}/topics-creating-your-own-templates.md | 0
.../pt-BR}/basic-usage.md | 20 ++---
.../pt-BR}/installation.md | 0
.../README.md => guide/pt-BR/readme.md} | 0
.../topics-creating-your-own-generators.md | 0
.../topics-creating-your-own-templates.md | 0
.../zh-CN}/basic-usage.md | 8 +-
.../zh-CN}/installation.md | 0
.../README.md => guide/zh-CN/readme.md} | 0
.../topics-creating-your-own-generators.md | 0
.../topics-creating-your-own-templates.md | 0
docs/{guide-ja => }/images/gii-entry.png | Bin
docs/{guide-ja => }/images/gii-preview.png | Bin
docs/internals.md | 45 ++++++++++
47 files changed, 128 insertions(+), 527 deletions(-)
delete mode 100644 docs/guide-pt-BR/images/gii-entry.png
delete mode 100644 docs/guide-pt-BR/images/gii-preview.png
delete mode 100644 docs/guide-ru/README.md
delete mode 100644 docs/guide-ru/basic-usage.md
delete mode 100644 docs/guide-ru/images/gii-entry.png
delete mode 100644 docs/guide-ru/images/gii-preview.png
delete mode 100644 docs/guide-ru/installation.md
delete mode 100644 docs/guide-ru/topics-creating-your-own-generators.md
delete mode 100644 docs/guide-ru/topics-creating-your-own-templates.md
delete mode 100644 docs/guide-uk/README.md
delete mode 100644 docs/guide-uk/basic-usage.md
delete mode 100644 docs/guide-uk/images/gii-entry.png
delete mode 100644 docs/guide-uk/images/gii-preview.png
delete mode 100644 docs/guide-uk/installation.md
delete mode 100644 docs/guide-uk/topics-creating-your-own-generators.md
delete mode 100644 docs/guide-uk/topics-creating-your-own-templates.md
delete mode 100644 docs/guide-zh-CN/images/gii-entry.png
delete mode 100644 docs/guide-zh-CN/images/gii-preview.png
rename docs/guide/{ => en}/basic-usage.md (84%)
rename docs/guide/{ => en}/installation.md (100%)
create mode 100644 docs/guide/en/readme.md
rename docs/guide/{ => en}/topics-creating-your-own-generators.md (100%)
rename docs/guide/{ => en}/topics-creating-your-own-templates.md (100%)
delete mode 100644 docs/guide/images/gii-entry.png
delete mode 100644 docs/guide/images/gii-preview.png
rename docs/{guide-ja => guide/ja}/basic-usage.md (90%)
rename docs/{guide-ja => guide/ja}/installation.md (100%)
rename docs/{guide-ja/README.md => guide/ja/readme.md} (100%)
rename docs/{guide-ja => guide/ja}/topics-creating-your-own-generators.md (100%)
rename docs/{guide-ja => guide/ja}/topics-creating-your-own-templates.md (100%)
rename docs/{guide-pt-BR => guide/pt-BR}/basic-usage.md (78%)
rename docs/{guide-pt-BR => guide/pt-BR}/installation.md (100%)
rename docs/{guide-pt-BR/README.md => guide/pt-BR/readme.md} (100%)
rename docs/{guide-pt-BR => guide/pt-BR}/topics-creating-your-own-generators.md (100%)
rename docs/{guide-pt-BR => guide/pt-BR}/topics-creating-your-own-templates.md (100%)
rename docs/{guide-zh-CN => guide/zh-CN}/basic-usage.md (83%)
rename docs/{guide-zh-CN => guide/zh-CN}/installation.md (100%)
rename docs/{guide-zh-CN/README.md => guide/zh-CN/readme.md} (100%)
rename docs/{guide-zh-CN => guide/zh-CN}/topics-creating-your-own-generators.md (100%)
rename docs/{guide-zh-CN => guide/zh-CN}/topics-creating-your-own-templates.md (100%)
rename docs/{guide-ja => }/images/gii-entry.png (100%)
rename docs/{guide-ja => }/images/gii-preview.png (100%)
create mode 100644 docs/internals.md
diff --git a/LICENSE.md b/LICENSE.md
index bc5674fe..6a920d60 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,17 +1,17 @@
-Copyright © 2008 by Yii Software (https://www.yiiframework.com/)
+Copyright © 2008 by Yii Software ()
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- * Redistributions of source code must retain the above copyright
+* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
+* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- * Neither the name of Yii Software nor the names of its
+* Neither the name of Yii Software nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
diff --git a/README.md b/README.md
index d0b79e5d..3888c702 100644
--- a/README.md
+++ b/README.md
@@ -9,10 +9,6 @@
This extension provides a Web-based code generator, called Gii, for [Yii framework](https://www.yiiframework.com) applications.
You can use Gii to quickly generate models, forms, modules, CRUD, etc.
-For license information check the [LICENSE](LICENSE.md)-file.
-
-Documentation is at [docs/guide/README.md](docs/guide/README.md).
-
[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii-gii/v/stable.png)](https://packagist.org/packages/yiisoft/yii-gii)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii-gii/downloads.png)](https://packagist.org/packages/yiisoft/yii-gii)
[![Build Status](https://github.com/yiisoft/yii-gii/workflows/build/badge.svg)](https://github.com/yiisoft/yii-gii/actions?query=workflow%3Abuild)
@@ -21,7 +17,6 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fyii-gii%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/yii-gii/master)
[![static analysis](https://github.com/yiisoft/yii-gii/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/yii-gii/actions?query=workflow%3A%22static+analysis%22)
-
Installation
------------
@@ -77,3 +72,32 @@ yii help gii/model
# generate City model from city table
yii gii/model --tableName=city --modelClass=City
```
+
+## Documentation
+
+- [Guide](docs/guide/readme.md)
+- [Internals](docs/internals.md)
+
+## Support
+
+If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
+You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
+
+## Support the project
+
+[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)
+
+## Follow updates
+
+[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)
+[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework)
+[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
+[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
+[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)
+
+## License
+
+The Gii Extension for Yii is free software. It is released under the terms of the BSD License.
+Please see [`LICENSE`](./LICENSE.md) for more information.
+
+Maintained by [Yii Software](https://www.yiiframework.com/).
diff --git a/composer.json b/composer.json
index fc434ec8..487761ba 100644
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,7 @@
"issues": "https://github.com/yiisoft/yii-gii/issues",
"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",
"chat": "https://t.me/yii3en"
},
"minimum-stability": "dev",
diff --git a/docs/guide-pt-BR/images/gii-entry.png b/docs/guide-pt-BR/images/gii-entry.png
deleted file mode 100644
index 0a145f909f622664b5bd709a8d08d34ef5e5093a..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 45302
zcmeFZcUY768!s%*;wTkFR8)!}RAvz&vJxsFqC!wmM1)i!L_tW|BaqmNA~M28WCTTJ
z3X(8{KvF@7BmzZd7>N*uKp?Cvvd&}c@BI3{@AdwF&biJXCRYN_^L+31xj*;71ZOAv
zJv$HW+_Y)a9*1+bmp5(NTC{1?mc!p|2fjh@#w~$2xsc2DXEs%JAD#m~Y(@Oy_{*kE
zHP~I^o7;fT^1q#P581To`?jzDQ}vzKnnkQTAg
z3g*U*Ro|Za-QHtaNoFZ&hg8*h8sCR*o`3AIgliF7<-n1GFIVUbkZ3rsK&|B%s>}Xp
zZp*TjLYF}^yK>6(pEG}_Zu{S(B{^AphT>3gH(VHpT{b&zf$H3{l+iNz3%}D#T4ap(
zP>YNXX9*EL3TCsl?DamU3xO6|M;k(pi5O6?oR(>&As^=2ia#EN5zn(7)rdN%Hv8(2
zUVPOYgrPX$0-nH`Wkvqyxlhy1cO0giOHTelw6{&sxuhW5O2|g}LSo)o;jvazh4dpi
zOkEMR*r`Xl`ig+B21`kF7-VjY-Ce?j5ZCCl2#lb14L^!BGej+3ne}nA`kWLRWferb
zp!TFi(h&H8AICUE8cDhq+mFUuH+SRtg+=k
zCS)Bc^Z6K*^tSk-h0ak|S5CjgBdLl^YWwmytZ;HE={9h+I
zka@3(37inU_>TWkI=Pw}V{Rp)+2e9!xitvG!k7)i2Cq~}*RC_GbHCFuD4`9WEa4>*
zWYVYcz8L<-1%hm)gNB!FyoyI~(DQcm2UfECS$#x-y+5I(Tjk90cBYGsUFjSKe*pC!JVaKESGwcGgr};enihG6sEQy_CtiChAF^IqIGYAnshu5@Ud=3VV|?QJhy-xY8OsUyeg_H
zGYT4iT}}0p)yV1}X*cuY_tUDP=P&5c3WfEfx}!V4;n8s5i*zH3(PeLq_vrVZxAyBA
zTI!2vs%`e1rM&Tj;Ano52!RP%*aA4vb0xsN+|y#HkZ}IPpM>iv6?jYx--JGdUT7~L)@^4}?c_y9BVf=Q72Vum}S3650JPTqM?W?;;=us|R7SpqbUWRKq
zAu8cB@+EzX*iPxhEV8>Wwr$J)X&j1?OUEvbr^hZsacPtt()BsINH%qcZYb?^A@C(D
zE~~cvJ>m(aHSFwzl4t03{?R;$e4WSx7p|On?aq2wycZ0pX)2$S6TH#M`jdR}HsL;BbnL?qzLgT~;;a<#&zhMt}