phramework / validate-filler
Fill forms generated by validate (JSON schema) specification
Installs: 10 110
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 7
Forks: 2
Open Issues: 7
Requires
- php: ^7.2.0 | ^8.0.0
- ext-json: *
- fzaninotto/faker: ^1.5
- phramework/validate: ^v0.12.0
Requires (Dev)
- codacy/coverage: ^1.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.3.0
- squizlabs/php_codesniffer: ^3.5.2
This package is auto-updated.
Last update: 2024-10-25 12:28:38 UTC
README
Fill forms generated by validate (JSON schema) specification
Usage
Require package using composer
composer require phramework/validate-filler
Example parsing schema from json
<?php $validator = \Phramework\Validate\ObjectValidator::createFromJSON('{ "type": "object", "properties": { "a": { "type": "string", "enum": [ "1", "2", "3" ] }, "b": { "type": "string", "enum": [ "i", "ii", "iii" ] } }, "required": ["a"] }'); $value = (new \Phramework\ValidateFiller\Filler()) ->fill($validator); var_dump($value);
Sample outputs:
class stdClass#1381 (1) { public $a => string(1) "2" }
class stdClass#1381 (2) { public $a => string(1) "3" public $b => string(2) "ii" }
- will always include property
"a"
since it's required - some times will include property
"b"
(probabilistic)
Example using ObjectValidator constructor
<?php $validator = new \Phramework\Validate\ObjectValidator( (object) [ 'a' => new \Phramework\Validate\EnumValidator([ '1', '2', '3' ]), 'b' => new \Phramework\Validate\EnumValidator([ 'i', 'ii', 'iii' ]) ], ['a'], false ); $value = (new \Phramework\ValidateFiller\Filler()) ->fill($validator);
Development
Install dependencies
composer update
Test and lint code
composer test
composer lint
Generate documentation
composer doc
License
Copyright 2015-2017 Xenofon Spafaridis
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.