diff --git a/.github/labeler.yml b/.github/labeler.yml index e0ece348..a7cc87fa 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -78,6 +78,10 @@ Pager: - docs/components/pager/* - src/SonsOfPHP/**/Pager/* +Validator: + - docs/components/validator/* + - src/SonsOfPHP/**/Validator/* + Version: - docs/components/version/* - src/SonsOfPHP/**/Version/* diff --git a/docs/contracts/validator/index.md b/docs/contracts/validator/index.md new file mode 100644 index 00000000..2dafcfaa --- /dev/null +++ b/docs/contracts/validator/index.md @@ -0,0 +1,9 @@ +--- +title: Validator Contract +--- + +## Installation + +```shell +composer require sonsofphp/validator-contract +``` diff --git a/mkdocs.yml b/mkdocs.yml index 74519622..08aa2f87 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -126,3 +126,4 @@ nav: - Cqrs: contracts/cqrs/index.md - Mailer: contracts/mailer/index.md - Pager: contracts/pager/index.md + - Validator: contracts/validator/index.md diff --git a/src/SonsOfPHP/Contract/Validator/.gitattributes b/src/SonsOfPHP/Contract/Validator/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/Validator/.gitignore b/src/SonsOfPHP/Contract/Validator/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/Validator/ConstraintDescriptorInterface.php b/src/SonsOfPHP/Contract/Validator/ConstraintDescriptorInterface.php new file mode 100644 index 00000000..f01b3a48 --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/ConstraintDescriptorInterface.php @@ -0,0 +1,13 @@ + + */ +interface ConstraintDescriptorInterface +{ + public function getMessageTemplate(): string; +} diff --git a/src/SonsOfPHP/Contract/Validator/ConstraintViolationInterface.php b/src/SonsOfPHP/Contract/Validator/ConstraintViolationInterface.php new file mode 100644 index 00000000..e3198ba5 --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/ConstraintViolationInterface.php @@ -0,0 +1,14 @@ + + */ +interface ConstraintViolationInterface +{ + public function getMessage(): string; + public function getMessageTemplate(): string; +} diff --git a/src/SonsOfPHP/Contract/Validator/LICENSE b/src/SonsOfPHP/Contract/Validator/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/LICENSE @@ -0,0 +1,19 @@ +Copyright 2022 to Present Joshua Estes + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/SonsOfPHP/Contract/Validator/README.md b/src/SonsOfPHP/Contract/Validator/README.md new file mode 100644 index 00000000..266f30c8 --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/README.md @@ -0,0 +1,16 @@ +Sons of PHP - Validator Contract +================================ + +## Learn More + +* [Documentation][docs] +* [Contributing][contributing] +* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo] +* Get Help & Support using [Discussions][discussions] + +[discussions]: https://github.com/orgs/SonsOfPHP/discussions +[mother-repo]: https://github.com/SonsOfPHP/sonsofphp +[contributing]: https://docs.sonsofphp.com/contributing/ +[docs]: https://docs.sonsofphp.com/contracts/validator/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AValidator +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AValidator diff --git a/src/SonsOfPHP/Contract/Validator/ValidatorInterface.php b/src/SonsOfPHP/Contract/Validator/ValidatorInterface.php new file mode 100644 index 00000000..d16166da --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/ValidatorInterface.php @@ -0,0 +1,17 @@ + + */ +interface ValidatorInterface +{ + public function validate(mixed $object, array $groups = []): iterable; + public function validateProperty(mixed $object, string $propertyName, array $groups = []): iterable; + public function validateValue(mixed $object, string $propertyName, object $value, array $groups = []): iterable; + + public function getConstrainsForClass(string $class); +} diff --git a/src/SonsOfPHP/Contract/Validator/composer.json b/src/SonsOfPHP/Contract/Validator/composer.json new file mode 100644 index 00000000..f1989fec --- /dev/null +++ b/src/SonsOfPHP/Contract/Validator/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/validator-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/validator-contract", + "license": "MIT", + "authors": [ + { + "name": "Joshua Estes", + "email": "joshua@sonsofphp.com" + } + ], + "support": { + "issues": "https://github.com/SonsOfPHP/sonsofphp/issues", + "forum": "https://github.com/orgs/SonsOfPHP/discussions", + "docs": "https://docs.sonsofphp.com" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\Validator\\": "" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": ">=8.1" + }, + "extra": { + "sort-packages": true, + "branch-alias": { + "dev-main": "0.3.x-dev" + } + }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/JoshuaEstes" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" + } + ] +}