diff --git a/Module/infoLayout.json b/Module/infoLayout.json new file mode 100644 index 000000000..438c82273 --- /dev/null +++ b/Module/infoLayout.json @@ -0,0 +1,35 @@ +{ + "name": { + "id": "^[1-9]\\d*", + "internal": "[a-zA-Z0-9]+", + "external": "[a-zA-Z0-9]+" + }, + "category": "[a-zA-Z0-9]+", + "version": "([0-9]+\\.){2}[0-9]+", + "requirements": { + ".*": ".*" + }, + "creator": { + "name": ".+", + "website": ".*" + }, + "description": ".+", + "directory": "[a-zA-Z0-9]+", + "dependencies": { + ".*": ".*" + }, + "providing": { + ".*": ".*" + }, + "load": [ + { + "pid": [ + ".*" + ], + "type": "^[1-9]\\d*", + "for": "^([1-9]\\d*)|([a-zA-Z0-9]+)", + "from": "[a-zA-Z0-9]+", + "file": "[a-zA-Z0-9]*" + } + ] +} diff --git a/Validation/Base/DateTime.php b/Validation/Base/DateTime.php index 4c75ef7e6..f068942b4 100644 --- a/Validation/Base/DateTime.php +++ b/Validation/Base/DateTime.php @@ -32,6 +32,6 @@ abstract class DateTime extends ValidatorAbstract */ public static function isValid($value, array $constraints = null) : bool { - return (bool) strtotime($value); + return (bool) \strtotime($value); } } diff --git a/Validation/Base/Json.php b/Validation/Base/Json.php new file mode 100644 index 000000000..2c5d1de84 --- /dev/null +++ b/Validation/Base/Json.php @@ -0,0 +1,225 @@ + $value) { + $tempPath = $path . '/' . $key; + + if (\is_array($value)) { + $paths += self::createAllViablePaths($value, $tempPath); + } else { + $paths[$tempPath] = $value; + } + } + + return $paths; + } + + /** + * Check if source array has additional elements. + * + * @param array $template Template structure + * @param array $source Source structure + * + * @return bool Returns false in case of undefined elements + * + * @since 1.0.0 + */ + private static function hasTemplateDefinition(array $template, array $source) : bool + { + $completePaths = []; + foreach ($template as $key => $value) { + $key = \str_replace('/0', '/.*', $key); + $completePaths[$key] = $value; + } + + foreach ($source as $sPath => $sValue) { + $hasDefinition = false; + + foreach ($completePaths as $tPath => $tValue) { + if ($tPath === $sPath + || \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1 + ) { + $hasDefinition = true; + break; + } + } + + if (!$hasDefinition) { + return false; + } + } + + return true; + } + + /** + * Check if source array is complete + * + * @param array $template Template structure + * @param array $source Source structure + * + * @return bool + * + * @since 1.0.0 + */ + private static function isCompleteSource(array $template, array $source) : bool + { + $completePaths = []; + foreach ($template as $key => $value) { + $key = \str_replace('/0', '/.*', $key); + + if (\stripos($key, '/.*') !== false) { + continue; + } + + $completePaths[$key] = $value; + } + + foreach ($completePaths as $tPath => $tValue) { + $sourceIsComplete = false; + + foreach ($source as $sPath => $sValue) { + if ($tPath === $sPath + || \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1 + ) { + unset($completePaths[$tPath]); + break; + } + } + } + + return count($completePaths) === 0; + } + + /** + * Check if source array is correct + * + * @param array $template Template structure + * @param array $source Source structure + * + * @return bool + * + * @since 1.0.0 + */ + private static function isValidSource(array $template, array $source) : bool + { + $validPaths = []; + foreach ($template as $key => $value) { + $key = \str_replace('/0', '/\d*', $key); + $validPaths[$key] = $value; + } + + foreach ($source as $sPath => $sValue) { + $sourceIsValid = false; + $foundPath = false; + + foreach ($validPaths as $tPath => $tValue) { + if (!$foundPath + && ($tPath === $sPath + || \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1) + ) { + $foundPath = true; + } + + if (($tPath === $sPath + || \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1) + && ($tValue === $sValue + || \preg_match('~' . ((string) $tValue) . '~', (string) $sValue) === 1) + ) { + $sourceIsValid = true; + break; + } + } + + if (!$sourceIsValid && $foundPath) { + return false; + } + } + + return true; + } +} diff --git a/tests/Validation/Base/JsonTest.php b/tests/Validation/Base/JsonTest.php new file mode 100644 index 000000000..6aa0ce8cc --- /dev/null +++ b/tests/Validation/Base/JsonTest.php @@ -0,0 +1,38 @@ +