diff options
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/JsonSchema/Schema.php')
| -rwxr-xr-x | server/vendor/php-opencloud/common/src/Common/JsonSchema/Schema.php | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/server/vendor/php-opencloud/common/src/Common/JsonSchema/Schema.php b/server/vendor/php-opencloud/common/src/Common/JsonSchema/Schema.php deleted file mode 100755 index e1e3f65..0000000 --- a/server/vendor/php-opencloud/common/src/Common/JsonSchema/Schema.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php declare(strict_types=1); - -namespace OpenCloud\Common\JsonSchema; - -use JsonSchema\Validator; - -class Schema -{ - /** @var object */ - private $body; - - /** @var Validator */ - private $validator; - - public function __construct($body, Validator $validator = null) - { - $this->body = (object) $body; - $this->validator = $validator ?: new Validator(); - } - - public function getPropertyPaths(): array - { - $paths = []; - - foreach ($this->body->properties as $propertyName => $property) { - $paths[] = sprintf("/%s", $propertyName); - } - - return $paths; - } - - public function normalizeObject($subject, array $aliases): \stdClass - { - $out = new \stdClass; - - foreach ($this->body->properties as $propertyName => $property) { - $name = isset($aliases[$propertyName]) ? $aliases[$propertyName] : $propertyName; - if (isset($property->readOnly) && $property->readOnly === true) { - continue; - } elseif (property_exists($subject, $name)) { - $out->$propertyName = $subject->$name; - } elseif (property_exists($subject, $propertyName)) { - $out->$propertyName = $subject->$propertyName; - } - } - - return $out; - } - - public function validate($data) - { - $this->validator->check($data, $this->body); - } - - public function isValid(): bool - { - return $this->validator->isValid(); - } - - public function getErrors(): array - { - return $this->validator->getErrors(); - } - - public function getErrorString(): string - { - $msg = "Provided values do not validate. Errors:\n"; - - foreach ($this->getErrors() as $error) { - $msg .= sprintf("[%s] %s\n", $error['property'], $error['message']); - } - - return $msg; - } -} |
