default = $value; return $this; } public function required(bool $state = true): self { $this->required = $state; return $this; } public function before(callable $handler): self { $this->before = $handler; return $this; } public function castTo(string $type): self { $this->castTo = $type; return $this; } public function assert(callable $handler, ?string $description = null): self { $this->asserts[] = [$handler, $description]; return $this; } /** * Marks as deprecated */ public function deprecated(string $message = 'The item %path% is deprecated.'): self { $this->deprecated = $message; return $this; } public function completeDefault(Context $context) { if ($this->required) { $context->addError( 'The mandatory item %path% is missing.', Nette\Schema\Message::MissingItem ); return null; } return $this->default; } public function doNormalize($value, Context $context) { if ($this->before) { $value = ($this->before)($value); } return $value; } private function doDeprecation(Context $context): void { if ($this->deprecated !== null) { $context->addWarning( $this->deprecated, Nette\Schema\Message::Deprecated ); } } private function doValidate($value, string $expected, Context $context): bool { if (!Nette\Utils\Validators::is($value, $expected)) { $expected = str_replace(['|', ':'], [' or ', ' in range '], $expected); $context->addError( 'The %label% %path% expects to be %expected%, %value% given.', Nette\Schema\Message::TypeMismatch, ['value' => $value, 'expected' => $expected] ); return false; } return true; } private function doValidateRange($value, array $range, Context $context, string $types = ''): bool { 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.", Nette\Schema\Message::LengthOutOfRange, ['value' => $value, 'length' => $length, 'expected' => implode('..', $range)] ); return false; } } elseif ((is_int($value) || is_float($value)) && !self::isInRange($value, $range)) { $context->addError( 'The %label% %path% expects to be in range %expected%, %value% given.', Nette\Schema\Message::ValueOutOfRange, ['value' => $value, 'expected' => implode('..', $range)] ); return false; } return true; } private function isInRange($value, array $range): bool { return ($range[0] === null || $value >= $range[0]) && ($range[1] === null || $value <= $range[1]); } private function doFinalize($value, Context $context) { if ($this->castTo) { if (Nette\Utils\Reflection::isBuiltinType($this->castTo)) { settype($value, $this->castTo); } else { $object = new $this->castTo; foreach ($value as $k => $v) { $object->$k = $v; } $value = $object; } } foreach ($this->asserts as $i => [$handler, $description]) { if (!$handler($value)) { $expected = $description ?: (is_string($handler) ? "$handler()" : "#$i"); $context->addError( 'Failed assertion ' . ($description ? "'%assertion%'" : '%assertion%') . ' for %label% %path% with value %value%.', Nette\Schema\Message::FailedAssertion, ['value' => $value, 'assertion' => $expected] ); return; } } return $value; } } __halt_compiler();----SIGNATURE:----R/t5JMUFw9PRyvrjbwdJwZwqxVmNZA2/embqy8RBEUEyN6lOcqVG9QxFT/t7et4vkcgpmA5Ta3B/s6dASG/cD6qGnCBJpJZYMMvRb56d8BrsvLnipMGw1z1w5uPlZqEnkMG+detA8UMlS4ts0ZY6DTGWM2w2HTMy0BAhRHGoPH9IcWAh4rcvS7IDQcGViFo4TB0Zwk3rrsl1OGne13LosPdAx674W6Nom3jszRfHJ8GDXXBy36ZvbaHRjC/S7EQgcUbfrQHDh/Omid1eA3NdZ80q26vT6rAoB1YwRE9iw1TF0myLZQDgcnFM2mHGQWBShjKU5pAKWHJ+cNaWydl6rJIRgGo91H9tMkfFw4QBRCodQhV/+DLLH0KzhzxE4utbLe5IctviJaJxhtlfGqZU3L80sVsUvcI07eOsDU7mwAuD6KLlo7gNAA0WPPrCwPVRew7T5EdOme423VQKEb3z7nagOmt4LWp2k4o1EWBqeDWcLlrOIJPlnXQWQD+jb5mFWNOg0vXU56FjzuRwuuy7EORHG2QRJ4EJ8SZg8l/MQdMpqWwrUWKNdFXGhWGux6QdwIV3hTk886IpNtDf6VvWQBOk13fshJ1aNAE52llb/Ct0PcbgaOSfrst8EUL2JBkru5LzopHVx6jcX1AovMlFPy8pK/FpEhhAUcmTQU0HG74=----ATTACHMENT:----OTE5MjUzODk1NzUwODkxOSAyMTk1NDkyMjc2Mjc5ODM5IDU5MzY1NDg1OTA5Njc5OTU=