Файловый менеджер - Редактировать - /home/easybachat/hisabat365.com/4a7891/schema.zip
Ðазад
PK N*[.��<� � license.mdnu �[��� Licenses ======== Good news! You may use Nette Framework under the terms of either the New BSD License or the GNU General Public License (GPL) version 2 or 3. The BSD License is recommended for most projects. It is easy to understand and it places almost no restrictions on what you can do with the framework. If the GPL fits better to your project, you can use the framework under this license. You don't have to notify anyone which license you are using. You can freely use Nette Framework in commercial projects as long as the copyright header remains intact. Please be advised that the name "Nette Framework" is a protected trademark and its usage has some limitations. So please do not use word "Nette" in the name of your project or top-level domain, and choose a name that stands on its own merits. If your stuff is good, it will not take long to establish a reputation for yourselves. New BSD License --------------- Copyright (c) 2004, 2014 David Grudl (https://davidgrudl.com) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of "Nette Framework" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. GNU General Public License -------------------------- GPL licenses are very very long, so instead of including them here we offer you URLs with full text: - [GPL version 2](http://www.gnu.org/licenses/gpl-2.0.html) - [GPL version 3](http://www.gnu.org/licenses/gpl-3.0.html) PK N*[�m�� � src/Schema/DynamicParameter.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; interface DynamicParameter { } PK N*[ؤw� � src/Schema/Processor.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; use Nette; /** * Schema validator. */ final class Processor { public array $onNewContext = []; private Context $context; private bool $skipDefaults = false; public function skipDefaults(bool $value = true): void { $this->skipDefaults = $value; } /** * Normalizes and validates data. Result is a clean completed data. * @throws ValidationException */ public function process(Schema $schema, mixed $data): mixed { $this->createContext(); $data = $schema->normalize($data, $this->context); $this->throwsErrors(); $data = $schema->complete($data, $this->context); $this->throwsErrors(); return $data; } /** * Normalizes and validates and merges multiple data. Result is a clean completed data. * @throws ValidationException */ public function processMultiple(Schema $schema, array $dataset): mixed { $this->createContext(); $flatten = null; $first = true; foreach ($dataset as $data) { $data = $schema->normalize($data, $this->context); $this->throwsErrors(); $flatten = $first ? $data : $schema->merge($data, $flatten); $first = false; } $data = $schema->complete($flatten, $this->context); $this->throwsErrors(); return $data; } /** * @return string[] */ public function getWarnings(): array { $res = []; foreach ($this->context->warnings as $message) { $res[] = $message->toString(); } return $res; } private function throwsErrors(): void { if ($this->context->errors) { throw new ValidationException(null, $this->context->errors); } } private function createContext(): void { $this->context = new Context; $this->context->skipDefaults = $this->skipDefaults; Nette\Utils\Arrays::invoke($this->onNewContext, $this->context); } } PK N*[�V��% % src/Schema/Context.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; final class Context { public bool $skipDefaults = false; /** @var string[] */ public array $path = []; public bool $isKey = false; /** @var Message[] */ public array $errors = []; /** @var Message[] */ public array $warnings = []; /** @var array[] */ public array $dynamics = []; public function addError(string $message, string $code, array $variables = []): Message { $variables['isKey'] = $this->isKey; return $this->errors[] = new Message($message, $code, $this->path, $variables); } public function addWarning(string $message, string $code, array $variables = []): Message { return $this->warnings[] = new Message($message, $code, $this->path, $variables); } /** @return \Closure(): bool */ public function createChecker(): \Closure { $count = count($this->errors); return fn(): bool => $count === count($this->errors); } } PK N*[Γ0�� � src/Schema/Message.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; use Nette; final class Message { /** variables: {value: mixed, expected: string} */ public const TypeMismatch = 'schema.typeMismatch'; /** variables: {value: mixed, expected: string} */ public const ValueOutOfRange = 'schema.valueOutOfRange'; /** variables: {value: mixed, length: int, expected: string} */ public const LengthOutOfRange = 'schema.lengthOutOfRange'; /** variables: {value: string, pattern: string} */ public const PatternMismatch = 'schema.patternMismatch'; /** variables: {value: mixed, assertion: string} */ public const FailedAssertion = 'schema.failedAssertion'; /** no variables */ public const MissingItem = 'schema.missingItem'; /** variables: {hint: string} */ public const UnexpectedItem = 'schema.unexpectedItem'; /** no variables */ public const Deprecated = 'schema.deprecated'; /** @deprecated use Message::TypeMismatch */ public const TYPE_MISMATCH = self::TypeMismatch; /** @deprecated use Message::ValueOutOfRange */ public const VALUE_OUT_OF_RANGE = self::ValueOutOfRange; /** @deprecated use Message::LengthOutOfRange */ public const LENGTH_OUT_OF_RANGE = self::LengthOutOfRange; /** @deprecated use Message::PatternMismatch */ public const PATTERN_MISMATCH = self::PatternMismatch; /** @deprecated use Message::FailedAssertion */ public const FAILED_ASSERTION = self::FailedAssertion; /** @deprecated use Message::MissingItem */ public const MISSING_ITEM = self::MissingItem; /** @deprecated use Message::UnexpectedItem */ public const UNEXPECTED_ITEM = self::UnexpectedItem; /** @deprecated use Message::Deprecated */ public const DEPRECATED = self::Deprecated; public string $message; public string $code; /** @var string[] */ public array $path; /** @var string[] */ public array $variables; public function __construct(string $message, string $code, array $path, array $variables = []) { $this->message = $message; $this->code = $code; $this->path = $path; $this->variables = $variables; } public function toString(): string { $vars = $this->variables; $vars['label'] = empty($vars['isKey']) ? 'item' : 'key of item'; $vars['path'] = $this->path ? "'" . implode("\u{a0}›\u{a0}", $this->path) . "'" : null; $vars['value'] = Helpers::formatValue($vars['value'] ?? null); return preg_replace_callback('~( ?)%(\w+)%~', function ($m) use ($vars) { [, $space, $key] = $m; return $vars[$key] === null ? '' : $space . $vars[$key]; }, $this->message) ?? throw new Nette\InvalidStateException(preg_last_error_msg()); } } PK N*[�q�J J src/Schema/Schema.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; interface Schema { /** * Normalization. * @return mixed */ function normalize(mixed $value, Context $context); /** * Merging. * @return mixed */ function merge(mixed $value, mixed $base); /** * Validation and finalization. * @return mixed */ function complete(mixed $value, Context $context); /** * @return mixed */ function completeDefault(Context $context); } PK N*[�,"�o o src/Schema/Helpers.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; use Nette; use Nette\Utils\Reflection; /** * @internal */ final class Helpers { use Nette\StaticClass; public const PreventMerging = '_prevent_merging'; /** * Merges dataset. Left has higher priority than right one. */ public static function merge(mixed $value, mixed $base): mixed { if (is_array($value) && isset($value[self::PreventMerging])) { unset($value[self::PreventMerging]); return $value; } if (is_array($value) && is_array($base)) { $index = 0; foreach ($value as $key => $val) { if ($key === $index) { $base[] = $val; $index++; } else { $base[$key] = static::merge($val, $base[$key] ?? null); } } return $base; } elseif ($value === null && is_array($base)) { return $base; } else { return $value; } } public static function getPropertyType(\ReflectionProperty|\ReflectionParameter $prop): ?string { if ($type = Nette\Utils\Type::fromReflection($prop)) { return (string) $type; } elseif ( ($prop instanceof \ReflectionProperty) && ($type = preg_replace('#\s.*#', '', (string) self::parseAnnotation($prop, 'var'))) ) { $class = Reflection::getPropertyDeclaringClass($prop); return preg_replace_callback('#[\w\\\\]+#', fn($m) => Reflection::expandClassName($m[0], $class), $type); } return null; } /** * Returns an annotation value. * @param \ReflectionProperty $ref */ public static function parseAnnotation(\Reflector $ref, string $name): ?string { if (!Reflection::areCommentsAvailable()) { throw new Nette\InvalidStateException('You have to enable phpDoc comments in opcode cache.'); } $re = '#[\s*]@' . preg_quote($name, '#') . '(?=\s|$)(?:[ \t]+([^@\s]\S*))?#'; if ($ref->getDocComment() && preg_match($re, trim($ref->getDocComment(), '/*'), $m)) { return $m[1] ?? ''; } return null; } public static function formatValue(mixed $value): string { if ($value instanceof DynamicParameter) { return 'dynamic'; } elseif (is_object($value)) { return 'object ' . $value::class; } elseif (is_string($value)) { return "'" . Nette\Utils\Strings::truncate($value, 15, '...') . "'"; } elseif (is_scalar($value)) { return var_export($value, return: true); } else { return get_debug_type($value); } } public static function validateType(mixed $value, string $expected, Context $context): void { if (!Nette\Utils\Validators::is($value, $expected)) { $expected = str_replace(DynamicParameter::class . '|', '', $expected); $expected = str_replace(['|', ':'], [' or ', ' in range '], $expected); $context->addError( 'The %label% %path% expects to be %expected%, %value% given.', Message::TypeMismatch, ['value' => $value, 'expected' => $expected], ); } } public static function validateRange(mixed $value, array $range, Context $context, string $types = ''): void { if (is_array($value) || is_string($value)) { [$length, $label] = is_array($value) ? [count($value), 'items'] : (in_array('unicode', explode('|', $types), true) ? [Nette\Utils\Strings::length($value), 'characters'] : [strlen($value), 'bytes']); if (!self::isInRange($length, $range)) { $context->addError( "The length of %label% %path% expects to be in range %expected%, %length% $label given.", Message::LengthOutOfRange, ['value' => $value, 'length' => $length, 'expected' => implode('..', $range)], ); } } elseif ((is_int($value) || is_float($value)) && !self::isInRange($value, $range)) { $context->addError( 'The %label% %path% expects to be in range %expected%, %value% given.', Message::ValueOutOfRange, ['value' => $value, 'expected' => implode('..', $range)], ); } } public static function isInRange(mixed $value, array $range): bool { return ($range[0] === null || $value >= $range[0]) && ($range[1] === null || $value <= $range[1]); } public static function validatePattern(string $value, string $pattern, Context $context): void { if (!preg_match("\x01^(?:$pattern)$\x01Du", $value)) { $context->addError( "The %label% %path% expects to match pattern '%pattern%', %value% given.", Message::PatternMismatch, ['value' => $value, 'pattern' => $pattern], ); } } public static function getCastStrategy(string $type): \Closure { if (Nette\Utils\Reflection::isBuiltinType($type)) { return static function ($value) use ($type) { settype($value, $type); return $value; }; } elseif (method_exists($type, '__construct')) { return static fn($value) => is_array($value) || $value instanceof \stdClass ? new $type(...(array) $value) : new $type($value); } else { return static fn($value) => Nette\Utils\Arrays::toObject((array) $value, new $type); } } } PK N*[��<U� � src/Schema/Expect.phpnu �[��� <?php /** * This file is part of the Nette Framework (https://nette.org) * Copyright (c) 2004 David Grudl (https://davidgrudl.com) */ declare(strict_types=1); namespace Nette\Schema; use Nette; use Nette\Schema\Elements\AnyOf; use Nette\Schema\Elements\Structure; use Nette\Schema\Elements\Type; /** * Schema generator. * * @method static Type scalar($default = null) * @method static Type string($default = null) * @method static Type int($default = null) * @method static Type float($default = null) * @method static Type bool($default = null) * @method static Type null() * @method static Type array($default = []) * @method static Type list($default = []) * @method static Type mixed($default = null) * @method static Type email($default = null) * @method static Type unicode($default = null) */ final class Expect { public static function __callStatic(string $name, array $args): Type { $type = new Type($name); if ($args) { $type->default($args[0]); } return $type; } public static function type(string $type): Type { return new Type($type); } public static function anyOf(mixed ...$set): AnyOf { return new AnyOf(...$set); } /** * @param Schema[] $items */ public static function structure(array $items): Structure { return new Structure($items); } public static function from(object $object, array $items = []): Structure { $ro = new \ReflectionObject($object); $props = $ro->hasMethod('__construct') ? $ro->getMethod('__construct')->getParameters() : $ro->getProperties(); foreach ($props as $prop) { $item = &$items[$prop->getName()]; if (!$item) { $type = Helpers::getPropertyType($prop) ?? 'mixed'; $item = new Type($type); if ($prop instanceof \ReflectionProperty ? $prop->isInitialized($object) : $prop->isOptional()) { $def = ($prop instanceof \ReflectionProperty ? $prop->getValue($object) : $prop->getDefaultValue()); if (is_object($def)) { $item = static::from($def); } elseif ($def === null && !Nette\Utils\Validators::is(null, $type)) { $item->required(); } else { $item->default($def); } } else { $item->required(); } } } return (new Structure($items))->castTo($ro->getName()); } public static function arrayOf(string|Schema $valueType, string|Schema $keyType = null): Type { return (new Type('array'))->items($valueType, $keyType); } public static function listOf(string|Schema $type): Type { return (new Type('list'))->items($type); } } PK N*[Ж��W W "