Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Batch] Add composer-require-checker CI #57

Merged
merged 10 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'

name: Composer require checker

jobs:
composer-require-checker:
uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1']
xepozz marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## 1.0.0 under development

- Initial release.
- Enh: Add composer require checker into CI
xepozz marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"yiisoft/yii-middleware": "dev-master"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"jetbrains/phpstorm-attributes": "^1.0",
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^9.5",
Expand Down
47 changes: 47 additions & 0 deletions src/Generator/AbstractGeneratorDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
xepozz marked this conversation as resolved.
Show resolved Hide resolved

declare(strict_types=1);

namespace Yiisoft\Yii\Gii\Generator;

use Yiisoft\Validator\Result;
use Yiisoft\Validator\Rule\Callback;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\ValidationContext;

abstract class AbstractGeneratorDTO
{
#[Required(message: 'A code template must be selected.')]
#[Callback(['validateTemplate'])]
private $template = [];

/**
* Validates the template selection.
* This method validates whether the user selects an existing template
* and the template contains all required template files as specified in {@see requiredTemplates()}.
*
* @param string $value
*/
public function validateTemplate(mixed $value, Callback $rule, ValidationContext $validationContext): Result
{
/** @var self $dataSet */
$dataSet = $validationContext->getDataSet();
$result = new Result();
$templates = $dataSet->getTemplates();
if ($templates === []) {
return $result;
}
if (!isset($templates[$value])) {
$result->addError('Invalid template selection.');
} else {
$templatePath = $templates[$value];
foreach ($dataSet->requiredTemplates() as $template) {
if (!is_file($dataSet->aliases->get($templatePath . '/' . $template))) {
$result->addError("Unable to find the required code template file '$template'.");
}
}
}

return $result;
}
}
34 changes: 34 additions & 0 deletions src/Generator/Controller/ControllerDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
xepozz marked this conversation as resolved.
Show resolved Hide resolved

declare(strict_types=1);

namespace Yiisoft\Yii\Gii\Generator\Controller;

use Yiisoft\Validator\Rule\Callback;
use Yiisoft\Validator\Rule\Regex;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Yii\Gii\Generator\AbstractGeneratorDTO;

class ControllerDTO extends AbstractGeneratorDTO
{
#[Required()]
#[Regex(
pattern: '/^[A-Z][\w]*Controller$/',
message: 'Only word characters are allowed, and the class name must start with a capital letter and end with "Controller".'
)]
#[Callback(['validateNewClass'])]
private $controllerClass = [];

#[Regex(
pattern: '/^[\w\\\\]*$/',
message: 'Only word characters and backslashes are allowed.',
skipOnEmpty: true,
)]
private $baseClass = [];

#[Regex(
pattern: '/^[a-z][a-z0-9\\-,\\s]*$/',
message: 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'
)]
private $actions = [];
}