|
1
|
|
|
<?php |
|
2
|
|
|
namespace Wandu\Event |
|
3
|
|
|
{ |
|
4
|
|
|
use function Wandu\DI\container; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* @param string|object $event |
|
8
|
|
|
*/ |
|
9
|
|
|
function trigger($event) |
|
10
|
|
|
{ |
|
11
|
|
|
container()->get(EventEmitter::class)->trigger($event); |
|
12
|
|
|
} |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
namespace Wandu\Foundation |
|
16
|
|
|
{ |
|
17
|
|
|
use function Wandu\DI\container; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @deprecated use function Wandu\DI\container |
|
21
|
|
|
* @return \Wandu\DI\ContainerInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
function app() |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
return container(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $name |
|
30
|
|
|
* @param mixed $default |
|
31
|
|
|
* @return mixed |
|
32
|
|
|
*/ |
|
33
|
|
|
function config($name, $default = null) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
return container()->get('config')->get($name, $default); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
namespace Wandu\View |
|
40
|
|
|
{ |
|
41
|
|
|
use Wandu\View\Contracts\RenderInterface; |
|
|
|
|
|
|
42
|
|
|
use function Wandu\DI\container; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $template |
|
46
|
|
|
* @param array $attributes |
|
47
|
|
|
* @param string $basePath |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
function render($template, array $attributes = [], $basePath = null) |
|
51
|
|
|
{ |
|
52
|
|
|
return container()->get(RenderInterface::class)->render($template, $attributes, $basePath); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
namespace Wandu\Validator |
|
57
|
|
|
{ |
|
58
|
|
|
use Wandu\Validator\Contracts\Tester; |
|
|
|
|
|
|
59
|
|
|
use function Wandu\DI\container; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $tester |
|
63
|
|
|
* @param array $arguments |
|
64
|
|
|
* @return \Wandu\Validator\Contracts\Tester |
|
65
|
|
|
*/ |
|
66
|
|
|
function tester(string $tester, array $arguments = []): Tester |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$factory = container()->get(TesterFactory::class); |
|
69
|
|
|
if (count($arguments)) { |
|
70
|
|
|
return $factory->create($tester, $arguments); |
|
71
|
|
|
} |
|
72
|
|
|
return $factory->parse($tester); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string|\Wandu\Validator\Contracts\Rule $rule |
|
77
|
|
|
* @return \Wandu\Validator\Validator |
|
78
|
|
|
*/ |
|
79
|
|
|
function validator($rule): Validator |
|
80
|
|
|
{ |
|
81
|
|
|
return container()->get(ValidatorFactory::class)->create($rule); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.