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
|
15 |
|
public function __construct($root) |
14
|
|
|
{ |
15
|
15 |
|
parent::__construct(); |
16
|
|
|
|
17
|
15 |
|
$fs = new Filesystem($this, $root); |
18
|
|
|
|
19
|
15 |
|
$this->share(Application::class, $this); |
20
|
15 |
|
$this->share(Container::class, $this); |
21
|
15 |
|
$this->share(Filesystem::class, $fs); |
22
|
|
|
|
23
|
15 |
|
$this->addServiceProvider(Provider\CoreProvider::class); |
24
|
15 |
|
$this->addServiceProvider(Provider\ServiceProvider::class); |
25
|
15 |
|
$this->addServiceProvider(Provider\TarantoolProvider::class); |
26
|
|
|
|
27
|
15 |
|
foreach ($fs->listClasses('Provider') as $provider) { |
28
|
15 |
|
$this->addServiceProvider($provider); |
29
|
|
|
} |
30
|
|
|
|
31
|
15 |
|
$this->delegate(new ReflectionContainer()); |
32
|
15 |
|
} |
33
|
|
|
|
34
|
8 |
|
public function dispatch($job, $params = [], $service = null) |
35
|
|
|
{ |
36
|
8 |
|
$runner = $this->get(Runner::class); |
37
|
8 |
|
if (!$service && $runner->hasJob($job)) { |
38
|
8 |
|
return $runner->dispatch($job, $params); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$dispatcher = $this->get(Dispatcher::class); |
42
|
|
|
return $dispatcher->dispatch($job, $params); |
43
|
|
|
} |
44
|
|
|
|
45
|
15 |
|
public function get($alias, array $args = []) |
46
|
|
|
{ |
47
|
15 |
|
if (!$this->hasShared($alias, true) && is_subclass_of($alias, Repository::class)) { |
|
|
|
|
48
|
1 |
|
$spaceName = $this->get(Mapper::class) |
49
|
1 |
|
->getPlugin(Annotation::class) |
50
|
1 |
|
->getRepositorySpaceName($alias); |
51
|
|
|
|
52
|
1 |
|
if ($spaceName) { |
53
|
1 |
|
$instance = $this->get(Mapper::class)->getRepository($spaceName); |
54
|
1 |
|
$this->share($alias, $instance); |
55
|
|
|
} |
56
|
|
|
} |
57
|
15 |
|
return parent::get($alias, $args); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|