Repository navigation
Expand file tree
/
Copy pathValidationServiceProvider.php
More file actions
47 lines (44 loc) · 1.81 KB
/
Copy pathValidationServiceProvider.php
File metadata and controls
47 lines (44 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Krak\Validation;
use ArrayObject;
use Krak\Cargo;
use Krak\Invoke;
class ValidationServiceProvider implements Cargo\ServiceProvider
{
public function register(Cargo\Container $c) {
$c[ValidationContext\FluentValidationBuilder::class] = function($c) {
return new ValidationContext\FluentValidationBuilder(
$c['krak.validation.validators'],
$c['krak.validation.aliases']
);
};
$c[ValidationContext::class] = function($c) {
$invoke = new ValidatorInvoke(new Invoke\CallableInvoke());
$ctx = new ValidationContext\FluentValidationContext(
new Invoke\ContainerInvoke($invoke, $c->toInterop()),
$c[ValidationContext\FluentValidationBuilder::class]
);
$ctx = new ValidationContext\HttpRequestValidationContext($ctx);
return $ctx;
};
$c[MessageStore::class] = function($c) {
return new MessageStore\CompositeMessageStore([
$c['krak.validation.messages'],
new MessageStore\DefaultMessageStore($c['krak.validation.default_message'])
]);
};
$c[FormatMessage::class] = function() {
return new FormatMessage\StrTrFormatMessage();
};
$c[FormatViolations::class] = function() {
return new FormatViolations\MappedMessageFormatViolations();
};
$c['krak.validation.messages'] = new MessageStore\StackedMessageStore();
$c['krak.validation.default_message'] = "The {{attribute}} is invalid.";
$c['krak.validation.validators'] = new ArrayObject();
$c['krak.validation.aliases'] = [];
$c['krak.validation.context'] = new ArrayObject([
'container' => Cargo\toInterop($c),
]);
}
}