-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/third-release' into develop
- Loading branch information
Showing
24 changed files
with
322 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
github: cerbero90 | ||
ko_fi: cerbero90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ composer.lock | |
vendor | ||
phpcs.xml | ||
phpunit.xml | ||
.phpunit.result.cache | ||
.phpunit.cache | ||
.phpunit.result.cache | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
build: | ||
environment: | ||
php: 8.2 | ||
nodes: | ||
analysis: | ||
project_setup: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Andrea Marco Sartori <[email protected]> | ||
Copyright (c) 2024 Andrea Marco Sartori <[email protected]> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,117 @@ | ||
# Command Validator | ||
# ✅ Command Validator | ||
|
||
[![Author][ico-author]][link-author] | ||
[![PHP Version][ico-php]][link-php] | ||
[![Laravel Version][ico-laravel]][link-laravel] | ||
[![Build Status][ico-actions]][link-actions] | ||
[![Coverage Status][ico-scrutinizer]][link-scrutinizer] | ||
[![Quality Score][ico-code-quality]][link-code-quality] | ||
[![PHPStan Level][ico-phpstan]][link-phpstan] | ||
[![Latest Version][ico-version]][link-packagist] | ||
[![Software License][ico-license]](LICENSE.md) | ||
[![PSR-12][ico-psr12]][link-psr12] | ||
[![PER][ico-per]][link-per] | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
|
||
[![SensioLabsInsight][ico-sensiolabs]][link-sensiolabs] | ||
Laravel package to validate the input of console commands. | ||
|
||
Laravel package to validate input in Artisan console commands. | ||
|
||
## Install | ||
## 📦 Install | ||
|
||
Via Composer | ||
Via Composer: | ||
|
||
``` bash | ||
$ composer require cerbero/command-validator | ||
composer require cerbero/command-validator | ||
``` | ||
|
||
## Usage | ||
## 🔮 Usage | ||
|
||
This package merely consists in the `ValidatesInput` trait that Artisan commands can use to define their own validation rules for arguments and options in the `rules()` method: | ||
To validate the input of our console commands, we can use the `ValidatesInput` trait and define the validation rules for our arguments and options in the `rules()` method: | ||
|
||
``` php | ||
```php | ||
use Illuminate\Console\Command; | ||
use Cerbero\CommandValidator\ValidatesInput; | ||
|
||
class SampleCommand extends Command | ||
{ | ||
use ValidatesInput; | ||
|
||
protected function rules() | ||
protected function rules(): array | ||
{ | ||
return [ | ||
'year' => 'integer|digits:4|min:2000', | ||
'some_argument' => 'integer|digits:4|min:2000', | ||
'some_option' => 'string|max:2', | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
The available rules are the same [validation rules][link-rules] provided by Laravel. If you need custom validation, please have a look at [how to define custom rules][link-custom-rules]. | ||
The available rules are the same [validation rules provided by Laravel](https://laravel.com/docs/validation#available-validation-rules). If we need custom validation, here is how we can [define custom rules in Laravel](https://laravel.com/docs/validation#custom-validation-rules). | ||
|
||
Sometimes you may need to show custom messages or attributes for some validation errors. You can achieve that by overriding the methods `messages()` and `attributes()`: | ||
Sometimes we may need to show custom messages or attributes for some validation errors. We can achieve that by overriding the methods `messages()` and `attributes()`: | ||
|
||
``` php | ||
protected function messages() | ||
```php | ||
protected function messages(): array | ||
{ | ||
return [ | ||
'min' => 'The minimum allowed :attribute is :min' | ||
'min' => 'The minimum allowed :attribute is :min', | ||
]; | ||
} | ||
|
||
protected function attributes() | ||
protected function attributes(): array | ||
{ | ||
return [ | ||
'year' => 'year of birth' | ||
'year' => 'year of birth', | ||
]; | ||
} | ||
``` | ||
|
||
## Change log | ||
## 📆 Change log | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
## Testing | ||
## 🧪 Testing | ||
|
||
``` bash | ||
$ composer test | ||
composer test | ||
``` | ||
|
||
## Contributing | ||
## 💞 Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details. | ||
|
||
## Security | ||
## 🧯 Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
## 🏅 Credits | ||
|
||
- [Andrea Marco Sartori][link-author] | ||
- [All Contributors][link-contributors] | ||
|
||
## License | ||
## ⚖️ License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. | ||
|
||
[ico-author]: https://img.shields.io/static/v1?label=author&message=cerbero90&color=50ABF1&logo=twitter&style=flat-square | ||
[ico-php]: https://img.shields.io/packagist/php-v/cerbero/command-validator?color=%234F5B93&logo=php&style=flat-square | ||
[ico-laravel]: https://img.shields.io/static/v1?label=laravel&message=%E2%89%A55.5&color=ff2d20&logo=laravel&style=flat-square | ||
[ico-laravel]: https://img.shields.io/static/v1?label=laravel&message=%E2%89%A511&color=ff2d20&logo=laravel&style=flat-square | ||
[ico-version]: https://img.shields.io/packagist/v/cerbero/command-validator.svg?label=version&style=flat-square | ||
[ico-actions]: https://img.shields.io/github/workflow/status/cerbero90/command-validator/build?style=flat-square&logo=github | ||
[ico-actions]: https://img.shields.io/github/actions/workflow/status/cerbero90/command-validator/build.yml?branch=master&style=flat-square&logo=github | ||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square | ||
[ico-psr12]: https://img.shields.io/static/v1?label=compliance&message=PSR-12&color=blue&style=flat-square | ||
[ico-per]: https://img.shields.io/static/v1?label=compliance&message=PER&color=blue&style=flat-square | ||
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/cerbero90/command-validator.svg?style=flat-square&logo=scrutinizer | ||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/cerbero90/command-validator.svg?style=flat-square&logo=scrutinizer | ||
[ico-phpstan]: https://img.shields.io/badge/level-max-success?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGb0lEQVR42u1Xe1BUZRS/y4Kg8oiR3FCCBUySESZBRCiaBnmEsOzeSzsg+KxYYO9dEEftNRqZjx40FRZkTpqmOz5S2LsXlEZBciatkQnHDGYaGdFy1EpGMHl/p/PdFlt2rk5O+J9n5nA/vtf5ned3lnlISpRhafBlLRLHCtJGVrB/ZBDsaw2lUqzReGAC46DstTYfnSCGUjaaDvgxACo6j3vUenNdImeRXqdnWV5az5rrnzeZznj8J+E5Ftsclhf3s4J4CS/oRx5Bvon8ZU65FGYQxAwcf85a7CeRz+C41THejueydCZ7AAK34nwv3kHP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a87mv4lcjLwLlStlLTKYYUUAlvrlDGcW45wKxXX6aqHZNutM+1oQBHFTewAKkoH4+vqCj48PYAGS5yb5amjNoO+CU2SL53NKpDD0vxHHmOJir7L5xUvZgm0us2R142ScOIyVqYvlpWU4XoHIP8DXL2b+wjdWeXh6U2FjmIIKmbWAYPFRMus62h/geIvjOQYlpuDysQrLL6Ger49HgW8jqvXUhI7UvDb9iaSTDqHtyItiF5Suw5ewF/Nd8VJ6zlhsn06bEhwX4NyfCvuGEeRpTmh4mkG68yDpyuzB9EUcjU5awbAgncPlAeSdAQER0zCndzqVbeXC4qDsMpvGEYBXRnsDx4N3Auf1FCTjTIaVtY/QTmd0I8bBVm1kejEubUfO01vqImn3c49X7qpeqI9inIgtbpxK3YrKfIJCt+OeV2nfUVFR4ca4EkVENyA7gkYcMfB1R5MMmxZ7ez/2KF5SSN1yV+158UPsJT0ZBcI2bRLtIXGoYu5FerOUiJe1OfsL3XEWH43l2KS+iJF9+S4FpcNgsc+j8cT8H4o1bfPg/qkLt50uJ1RzdMsGg0UqwfEN114Pwb1CtWTGg+Y9U5ClK9x7xUWI7BI5VQVp0AVcQ3bZkQhmnEgdHhKyNSZe16crtBIlc7sIb6cRLft2PCgoKGjijBDtjrAQ7a3EdMsxzIRflAFIhPb6mHYmYwX+WBlPQgskhgVryyJCQyNyBLsBQdQ6fgsQhyt6MSOOsWZ7gbH8wETmgRKAijatNL8Ngm0xx4tLcsps0Wzx4al0jXlI40B/A3pa144MDtSgAAAAAElFTkSuQmCC | ||
[ico-downloads]: https://img.shields.io/packagist/dt/cerbero/command-validator.svg?style=flat-square | ||
[ico-sensiolabs]: https://insight.sensiolabs.com/projects/756ebffa-7aa3-464c-a7a4-3f09e37f897a/big.png | ||
|
||
[link-author]: https://twitter.com/cerbero90 | ||
[link-php]: https://www.php.net | ||
[link-laravel]: https://laravel.com | ||
[link-packagist]: https://packagist.org/packages/cerbero/command-validator | ||
[link-actions]: https://github.com/cerbero90/command-validator/actions?query=workflow%3Abuild | ||
[link-psr12]: https://www.php-fig.org/psr/psr-12/ | ||
[link-per]: https://www.php-fig.org/per/coding-style/ | ||
[link-scrutinizer]: https://scrutinizer-ci.com/g/cerbero90/command-validator/code-structure | ||
[link-code-quality]: https://scrutinizer-ci.com/g/cerbero90/command-validator | ||
[link-downloads]: https://packagist.org/packages/cerbero/command-validator | ||
[link-author]: https://github.com/cerbero90 | ||
[link-phpstan]: https://phpstan.org/ | ||
[link-contributors]: ../../contributors | ||
[link-sensiolabs]: https://insight.sensiolabs.com/projects/756ebffa-7aa3-464c-a7a4-3f09e37f897a | ||
[link-rules]: https://laravel.com/docs/validation#available-validation-rules | ||
[link-custom-rules]: https://laravel.com/docs/validation#custom-validation-rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.