1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basis; |
4
|
|
|
|
5
|
|
|
use League\Container\Container; |
6
|
|
|
use League\Container\ReflectionContainer; |
7
|
|
|
use Tarantool\Mapper\Mapper; |
8
|
|
|
use Tarantool\Mapper\Plugin\Annotation; |
9
|
|
|
use Tarantool\Mapper\Repository; |
10
|
|
|
|
11
|
|
|
class Application extends Container |
12
|
|
|
{ |
13
|
11 |
|
public function __construct(string $root) |
14
|
|
|
{ |
15
|
11 |
|
parent::__construct(); |
16
|
|
|
|
17
|
11 |
|
$fs = new Filesystem($this, $root); |
18
|
|
|
|
19
|
11 |
|
$this->share(Application::class, $this); |
20
|
11 |
|
$this->share(Container::class, $this); |
21
|
11 |
|
$this->share(Filesystem::class, $fs); |
22
|
|
|
|
23
|
11 |
|
$this->addServiceProvider(Provider\CoreProvider::class); |
24
|
11 |
|
$this->addServiceProvider(Provider\ServiceProvider::class); |
25
|
11 |
|
$this->addServiceProvider(Provider\TarantoolProvider::class); |
26
|
|
|
|
27
|
11 |
|
foreach ($fs->listClasses('Provider') as $provider) { |
28
|
11 |
|
$this->addServiceProvider($provider); |
29
|
|
|
} |
30
|
|
|
|
31
|
11 |
|
$this->delegate(new ReflectionContainer()); |
32
|
11 |
|
} |
33
|
|
|
|
34
|
6 |
|
public function dispatch(string $job, array $params = [], string $service = null) |
35
|
|
|
{ |
36
|
6 |
|
if ($service) { |
|
|
|
|
37
|
|
|
if ($this->get(Service::class)->getName() == $service) { |
38
|
|
|
$service = null; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
6 |
|
$runner = $this->get(Runner::class); |
43
|
6 |
|
if (!$service && $runner->hasJob($job)) { |
|
|
|
|
44
|
6 |
|
return $runner->dispatch($job, $params); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$dispatcher = $this->get(Dispatcher::class); |
48
|
|
|
return $dispatcher->dispatch($job, $params, $service); |
49
|
|
|
} |
50
|
|
|
|
51
|
11 |
|
public function get($alias, array $args = []) |
52
|
|
|
{ |
53
|
11 |
|
if (!$this->hasShared($alias, true) && is_subclass_of($alias, Repository::class)) { |
|
|
|
|
54
|
|
|
$spaceName = $this->get(Mapper::class) |
55
|
|
|
->getPlugin(Annotation::class) |
56
|
|
|
->getRepositorySpaceName($alias); |
57
|
|
|
|
58
|
|
|
if ($spaceName) { |
59
|
|
|
$instance = $this->get(Mapper::class)->getRepository($spaceName); |
60
|
|
|
$this->share($alias, $instance); |
61
|
|
|
} |
62
|
|
|
} |
63
|
11 |
|
return parent::get($alias, $args); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: