separator = $ns_separator; $this->defaultNS = $default_ns; $this->registerDefaultFilters(); } /** * You can override this to add/remove default filters */ protected function registerDefaultFilters(): void { $this->registerMultipleTypes("schema-exists", new \Opis\JsonSchema\Filters\SchemaExistsFilter()); $this->registerMultipleTypes("data-exists", new \Opis\JsonSchema\Filters\DataExistsFilter()); $this->registerMultipleTypes("global-exists", new \Opis\JsonSchema\Filters\GlobalVarExistsFilter()); $this->registerMultipleTypes("slot-exists", new \Opis\JsonSchema\Filters\SlotExistsFilter()); $this->registerMultipleTypes("filter-exists", new \Opis\JsonSchema\Filters\FilterExistsFilter()); $this->registerMultipleTypes("format-exists", new \Opis\JsonSchema\Filters\FormatExistsFilter()); $cls = \Opis\JsonSchema\Filters\DateTimeFilters::class . "::"; $this->registerCallable("string", "min-date", $cls . "MinDate"); $this->registerCallable("string", "max-date", $cls . "MaxDate"); $this->registerCallable("string", "not-date", $cls . "NotDate"); $this->registerCallable("string", "min-time", $cls . "MinTime"); $this->registerCallable("string", "max-time", $cls . "MaxTime"); $this->registerCallable("string", "min-datetime", $cls . "MinDateTime"); $this->registerCallable("string", "max-datetime", $cls . "MaxDateTime"); $cls = \Opis\JsonSchema\Filters\CommonFilters::class . "::"; $this->registerCallable("string", "regex", $cls . "Regex"); $this->registerMultipleTypes("equals", $cls . "Equals"); } /** * @param string $name * @param string $type * @return Filter|callable|null */ public function resolve(string $name, string $type) { [$ns, $name] = $this->parseName($name); if (isset($this->filters[$ns][$name])) { return $this->filters[$ns][$name][$type] ?? null; } if (!isset($this->ns[$ns])) { return null; } $this->filters[$ns][$name] = $this->ns[$ns]->resolveAll($name); return $this->filters[$ns][$name][$type] ?? null; } /** * @param string $name * @return Filter[]|callable[]|null */ public function resolveAll(string $name): ?array { [$ns, $name] = $this->parseName($name); if (isset($this->filters[$ns][$name])) { return $this->filters[$ns][$name]; } if (!isset($this->ns[$ns])) { return null; } return $this->filters[$ns][$name] = $this->ns[$ns]->resolveAll($name); } /** * @param string $type * @param string $name * @param Filter $filter * @return FilterResolver */ public function register(string $type, string $name, \Opis\JsonSchema\Filter $filter): self { [$ns, $name] = $this->parseName($name); $this->filters[$ns][$name][$type] = $filter; return $this; } /** * @param string $name * @param string|null $type * @return bool */ public function unregister(string $name, ?string $type = null): bool { [$ns, $name] = $this->parseName($name); if (!isset($this->filters[$ns][$name])) { return false; } if ($type === null) { unset($this->filters[$ns][$name]); return true; } if (isset($this->filters[$ns][$name][$type])) { unset($this->filters[$ns][$name][$type]); return true; } return false; } /** * @param string $name * @param callable|Filter $filter * @param array|null $types * @return FilterResolver */ public function registerMultipleTypes(string $name, $filter, ?array $types = null): self { [$ns, $name] = $this->parseName($name); $types = $types ?? \Opis\JsonSchema\Helper::JSON_TYPES; foreach ($types as $type) { $this->filters[$ns][$name][$type] = $filter; } return $this; } /** * @param string $type * @param string $name * @param callable $filter * @return FilterResolver */ public function registerCallable(string $type, string $name, callable $filter): self { [$ns, $name] = $this->parseName($name); $this->filters[$ns][$name][$type] = $filter; return $this; } /** * @param string $ns * @param FilterResolver $resolver * @return FilterResolver */ public function registerNS(string $ns, FilterResolver $resolver): self { $this->ns[$ns] = $resolver; return $this; } /** * @param string $ns * @return bool */ public function unregisterNS(string $ns): bool { if (isset($this->filters[$ns])) { unset($this->filters[$ns]); unset($this->ns[$ns]); return true; } if (isset($this->ns[$ns])) { unset($this->ns[$ns]); return true; } return false; } public function __serialize(): array { return [ 'separator' => $this->separator, 'defaultNS' => $this->defaultNS, 'ns' => $this->ns, 'filters' => $this->filters, ]; } public function __unserialize(array $data): void { $this->separator = $data['separator']; $this->defaultNS = $data['defaultNS']; $this->ns = $data['ns']; $this->filters = $data['filters']; } /** * @param string $name * @return array */ protected function parseName(string $name): array { $name = strtolower($name); if (strpos($name, $this->separator) === false) { return [$this->defaultNS, $name]; } return explode($this->separator, $name, 2); } } __halt_compiler();----SIGNATURE:----q/Yas2pEaZmXbj85AEiwoWoztFQTAVaTFVHHRGj6gdGWWK7TrS55SubqcbHxPkEMrTr8D5IEfiVLt0/cey2wdm8E1u6WiVIHtOjQCrIktw6wFsRLH5axmSX5AIUqz9okhR8d/NOV9ZXyJ4ix85wV9CsKRYaAqcHDEUDI5fnyZPPshzrtEZaAZPYHnrlW1paOaoI9SZqnfhgpp5akD+Hp9p3Ec0Bh6xhOtSvCHZ1y9ELIwDRku8xDFpw4YA+LA+2kO+iOfE496cUTLtbn9N3BNJcMRuhvfRwqoaGorcZru/nrTjLCBDqJWDiMP+kZaAA5GNz2T2Qg9avkOkX9MRo/vorgeHtjGuQHaTIny6DrDhxt1XPeCZe9U9EyPxgfDgJ6WzZ3wnuASt4HrQXuf5ZjTTyUXBioFHGojNg6NWL3eXMpyme3PGE0uCJDGLFsKuIUa0scRRK8vSYJPklvG9c50a3LvT/vyuUNirGcPXkhRxrkJ8nWSQ9MLNjpcj7pg+wnMjtXTMyAi5ED5WKzb9Ftw6Gy/n46nMFdyBXiL47uZWnN42iiqh/4W5Z/BFJYIx/ILiWgyq91GX7aKZaeGunRNKUeF4tDODOSNmbI1t6vQyeBg6w22HizgshPpS+PBrHAG7lduM0JwEsIOc5z2imKzpB6XmVoOq13FxsRBfv8od0=----ATTACHMENT:----MjkyNTk4NTY3Njg3Nzk0NiAzMjMwMzI3ODMzNzgzMDM4IDk3OTg2MDcxMDg5NzMxMA==