Skip to content

Commit 58cd31f

Browse files
committed
added support for warnings
1 parent ec41161 commit 58cd31f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/Schema/Context.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ final class Context
2828
/** @var Message[] */
2929
public $errors = [];
3030

31+
/** @var Message[] */
32+
public $warnings = [];
33+
3134
/** @var array[] */
3235
public $dynamics = [];
3336

@@ -36,4 +39,10 @@ public function addError(string $message, string $code, array $variables = []):
3639
{
3740
return $this->errors[] = new Message($message, $code, $this->path, $variables);
3841
}
42+
43+
44+
public function addWarning(string $message, string $code, array $variables = []): Message
45+
{
46+
return $this->warnings[] = new Message($message, $code, $this->path, $variables);
47+
}
3948
}

src/Schema/Elements/AnyOf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function complete($value, Nette\Schema\Context $context)
7575
$dolly->path = $context->path;
7676
$res = $item->complete($value, $dolly);
7777
if (!$dolly->errors) {
78+
$context->warnings = array_merge($context->warnings, $dolly->warnings);
7879
return $this->doFinalize($res, $context);
7980
}
8081
foreach ($dolly->errors as $error) {

src/Schema/Processor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ public function processMultiple(Schema $schema, array $dataset)
7373
}
7474

7575

76+
/**
77+
* @return string[]
78+
*/
79+
public function getWarnings(): array
80+
{
81+
$res = [];
82+
foreach ($this->context->warnings as $message) {
83+
$res[] = $message->toString();
84+
}
85+
return $res;
86+
}
87+
88+
7689
private function throwsErrors(): void
7790
{
7891
if ($this->context->errors) {

0 commit comments

Comments
 (0)