Skip to content

Commit

Permalink
added support for warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 25, 2020
1 parent 06a5b26 commit fe3d161
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Schema/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ final class Context
/** @var Message[] */
public $errors = [];

/** @var Message[] */
public $warnings = [];

/** @var array[] */
public $dynamics = [];

Expand All @@ -36,4 +39,10 @@ public function addError(string $message, string $code, array $variables = []):
{
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);
}
}
1 change: 1 addition & 0 deletions src/Schema/Elements/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function complete($value, Nette\Schema\Context $context)
$dolly->path = $context->path;
$res = $item->complete($value, $dolly);
if (!$dolly->errors) {
$context->warnings = array_merge($context->warnings, $dolly->warnings);
return $this->doFinalize($res, $context);
}
foreach ($dolly->errors as $error) {
Expand Down
13 changes: 13 additions & 0 deletions src/Schema/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ public function processMultiple(Schema $schema, array $dataset)
}


/**
* @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) {
Expand Down

0 comments on commit fe3d161

Please sign in to comment.