cast = $cast; $this->func = $this->getCastFunction($cast); } /** * @inheritDoc */ public function enter(\Opis\JsonSchema\ValidationContext $context) { $currentType = $context->currentDataType(); if ($currentType !== null && \Opis\JsonSchema\Helper::jsonTypeMatches($currentType, $this->cast)) { // Cast not needed return $this; } unset($currentType); $currentData = $context->currentData(); $context->setCurrentData(($this->func)($currentData)); return $currentData; } /** * @inheritDoc */ public function leave(\Opis\JsonSchema\ValidationContext $context, $data): void { if ($data !== $this) { $context->setCurrentData($data); } } /** * @param string $type * @return callable */ protected function getCastFunction(string $type): callable { $f = 'toNull'; switch ($type) { case 'integer': $f = 'toInteger'; break; case 'number': $f = 'toNumber'; break; case 'string': $f = 'toString'; break; case 'array': $f = 'toArray'; break; case 'object': $f = 'toObject'; break; case 'boolean': $f = 'toBoolean'; break; } return [$this, $f]; } /** * @param $value * @return int|null */ public function toInteger($value): ?int { if ($value === null) { return 0; } return is_scalar($value) ? intval($value) : null; } /** * @param $value * @return float|null */ public function toNumber($value): ?float { if ($value === null) { return 0.0; } return is_scalar($value) ? floatval($value) : null; } /** * @param $value * @return string|null */ public function toString($value): ?string { if ($value === null) { return ''; } if (is_scalar($value)) { return (string) $value; } return null; } /** * @param $value * @return array|null */ public function toArray($value): ?array { if ($value === null) { return []; } if (is_scalar($value)) { return [$value]; } if (is_array($value)) { return array_values($value); } if (is_object($value)) { return array_values(get_object_vars($value)); } return null; } /** * @param $value * @return object|null */ public function toObject($value): ?object { if (is_object($value) || is_array($value)) { return (object) $value; } return null; } /** * @param $value * @return bool */ public function toBoolean($value): bool { if ($value === null) { return false; } if (is_string($value)) { return !($value === ''); } if (is_object($value)) { return count(get_object_vars($value)) > 0; } return boolval($value); } } __halt_compiler();----SIGNATURE:----LWu8tVu84H8Lo0o9oLGby/kiqnflatlZSjH2ERcWpd0tAspHJnVAdeuhsgh9oQNK4HypbDVtanT6ZzEfIK4Y4YDpgbJvNotu0aHokCys0YBR0k8X8sfKuKdSLAsaeIX+sdqpTUk0a73Z+eYT2RRjJW4VY98LcSe/O2WrrZiXCyo8ddnanCF3USQOuEeHQbkI9asFAaX6Evma1rogl2xjpdqIaLipoUpxwjr6zncovdwedEPITSEFUMzo59wlsnYj2p8Tncx4zhvZs5RDICBSildZo7AC1f5OBis9X2qj3RssvS6LcVipQL1FoNNwV7eHH3HUgC1LxIn0V/UtHzYtFvZuFYO9iU4wpoIc50A5rttl9h1ZrE9EUjCnsoEZZypA1gSklv/7ZKrOSlXxsaYNAMsRGkgFFQE3cA1C4s/RL7LTaJ76xH8rEstrGywUiM9TVpyI9UWhweJeYmobXxYjOyOBCnfxAvTPYhgfQOdhmHL8UaCBBEas+faDL+1+oAeFQ7LPnyeu28/NDS7BetpP3CbuVcd+aQLab0wB6kz3JIkX4Vy+rFhoIvX92cOd8AJnnFHhoLaVWXpxQ9TBz+hrbPwZv4njYEahmuvCGyhITZrTGWELbgTJ5rIpzXByeLboYsUjqud2Bg9LWOnGPkJEyASiM9uLb5hh/dwaSIjbi14=----ATTACHMENT:----NjE2ODcxMjExNzYyNTk4MSA3MjQ4MjgxNzIzMTE0NTUgMTA2MjAzMTgyMjU1NzIxMw==