2018-11-30 09:25:42 +01:00
|
|
|
--CREDITS--
|
|
|
|
Henrique Moody <henriquemoody@gmail.com>
|
2018-03-07 19:07:52 +01:00
|
|
|
--FILE--
|
2019-02-09 11:44:33 +01:00
|
|
|
--FILE--
|
2018-03-07 19:07:52 +01:00
|
|
|
<?php
|
|
|
|
|
2019-02-09 11:44:33 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-03-07 19:07:52 +01:00
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
|
|
use Respect\Validation\Exceptions\NestedValidationException;
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
|
|
|
|
try {
|
|
|
|
v::create()
|
|
|
|
->key(
|
|
|
|
'mysql',
|
|
|
|
v::create()
|
|
|
|
->key('host', v::stringType(), true)
|
|
|
|
->key('user', v::stringType(), true)
|
|
|
|
->key('password', v::stringType(), true)
|
|
|
|
->key('schema', v::stringType(), true),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
->key(
|
|
|
|
'postgresql',
|
|
|
|
v::create()
|
|
|
|
->key('host', v::stringType(), true)
|
|
|
|
->key('user', v::stringType(), true)
|
|
|
|
->key('password', v::stringType(), true)
|
|
|
|
->key('schema', v::stringType(), true),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
->assert([
|
|
|
|
'mysql' => [
|
|
|
|
'host' => 42,
|
|
|
|
'schema' => 42,
|
|
|
|
],
|
|
|
|
'postgresql' => [
|
|
|
|
'user' => 42,
|
|
|
|
'password' => 42,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
} catch (NestedValidationException $exception) {
|
|
|
|
print_r($exception->getMessages([
|
|
|
|
'mysql' => [
|
|
|
|
'user' => 'Value should be a MySQL username',
|
|
|
|
'host' => '{{input}} should be a MySQL host',
|
|
|
|
],
|
|
|
|
'postgresql' => [
|
|
|
|
'schema' => 'You must provide a valid PostgreSQL schema',
|
|
|
|
],
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
?>
|
2018-12-19 18:05:58 +01:00
|
|
|
--EXPECT--
|
2018-03-07 19:07:52 +01:00
|
|
|
Array
|
|
|
|
(
|
|
|
|
[mysql] => Array
|
|
|
|
(
|
|
|
|
[host] => 42 should be a MySQL host
|
|
|
|
[user] => Value should be a MySQL username
|
2019-07-05 03:02:08 +02:00
|
|
|
[password] => password must be present
|
2018-03-07 19:07:52 +01:00
|
|
|
[schema] => schema must be of type string
|
|
|
|
)
|
|
|
|
|
|
|
|
[postgresql] => Array
|
|
|
|
(
|
2019-07-05 03:02:08 +02:00
|
|
|
[host] => host must be present
|
2018-03-07 19:07:52 +01:00
|
|
|
[user] => user must be of type string
|
|
|
|
[password] => password must be of type string
|
|
|
|
[schema] => You must provide a valid PostgreSQL schema
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|