Completed
Push — master ( 08a237...4891cb )
by Shagiakhmetov
05:00
created

LiveProfilerUI::getAggregatingJobsLockFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * @maintainer Timur Shagiakhmetov <[email protected]>
5
 */
6
7
namespace Badoo\LiveProfilerUI;
8
9
use Badoo\LiveProfilerUI\DataProviders\Interfaces\JobInterface;
10
use Badoo\LiveProfilerUI\DataProviders\Interfaces\SnapshotInterface;
11
use Badoo\LiveProfilerUI\Interfaces\StorageInterface;
12
use Psr\Log\LoggerInterface;
13
use Symfony\Component\DependencyInjection\Container;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
17
18
class LiveProfilerUI
19
{
20
    /** @var Container|null */
21
    protected $Container;
22
23
    /**
24
     * @return Container
25
     * @throws \Exception
26
     */
27 2
    public function getContainer() : Container
28
    {
29 2
        if (null === $this->Container) {
30 2
            $this->Container = new ContainerBuilder();
31 2
            $env_config_path = getenv('AGGREGATOR_CONFIG_PATH');
32 2
            $config_path = !empty($env_config_path) && file_exists($env_config_path)
33 1
                ? $env_config_path
34 2
                : __DIR__ . '/../../config/services.yaml';
35 2
            $DILoader = new YamlFileLoader($this->Container, new FileLocator(\dirname($config_path)));
36 2
            $DILoader->load(basename($config_path));
37
        }
38
39 2
        return $this->Container;
40
    }
41
42
    /**
43
     * @param string $page_name
44
     * @return object
45
     * @throws \Exception
46
     */
47
    public function getPage(string $page_name)
48
    {
49
        try {
50
            if (!$this->getContainer()->has($page_name)) {
51
                throw new \InvalidArgumentException('Page not found');
52
            }
53
54
            return $this->getContainer()->get($page_name);
55
        } catch (\Throwable $Ex) {
56
            echo $this->getContainer()
57
                ->get('view')
58
                ->fetchFile('error', ['error' => $Ex->getMessage()]);
59
            exit;
60
        }
61
    }
62
63
    /**
64
     * @return Aggregator
65
     * @throws \Exception
66
     */
67
    public function getAggregator() : Aggregator
68
    {
69
        /** @var Aggregator $Aggregator */
70
        $Aggregator = $this->getContainer()->get('aggregator');
71
72
        return $Aggregator;
73
    }
74
75
    /**
76
     * @return StorageInterface
77
     * @throws \Exception
78
     */
79
    public function getSourceStorage() : StorageInterface
80
    {
81
        /** @var StorageInterface $Storage */
82
        $Storage = $this->getContainer()->get('source_storage');
83
84
        return $Storage;
85
    }
86
87
    /**
88
     * @return StorageInterface
89
     * @throws \Exception
90
     */
91
    public function getAggregatorStorage() : StorageInterface
92
    {
93
        /** @var StorageInterface $Storage */
94
        $Storage = $this->getContainer()->get('aggregator_storage');
95
96
        return $Storage;
97
    }
98
99
    /**
100
     * @return SnapshotInterface
101
     * @throws \Exception
102
     */
103
    public function getSnapshotDataProvider() : SnapshotInterface
104
    {
105
        /** @var SnapshotInterface $SnapshotDataProvider */
106
        $SnapshotDataProvider = $this->getContainer()->get('snapshot');
107
108
        return $SnapshotDataProvider;
109
    }
110
111
    /**
112
     * @return JobInterface
113
     * @throws \Exception
114
     */
115
    public function getJobDataProvider() : JobInterface
116
    {
117
        /** @var JobInterface $JobDataProvider */
118
        $JobDataProvider = $this->getContainer()->get('job');
119
120
        return $JobDataProvider;
121
    }
122
123
    /**
124
     * @return LoggerInterface
125
     * @throws \Exception
126
     */
127
    public function getLogger() : LoggerInterface
128
    {
129
        /** @var LoggerInterface $Logger */
130
        $Logger = $this->getContainer()->get('logger');
131
132
        return $Logger;
133
    }
134
135
    /**
136
     * @return FieldList
137
     * @throws \Exception
138
     */
139
    public function getFieldService() : FieldList
140
    {
141
        /** @var FieldList $FieldList */
142
        $FieldList = $this->getContainer()->get('fields');
143
144
        return$FieldList;
145
    }
146
147
    /**
148
     * @return string
149
     * @throws \Exception
150
     */
151
    public function getCallsCountField() : string
152
    {
153
        return $this->getContainer()->getParameter('aggregator.calls_count_field');
154
    }
155
156
    /**
157
     * @return string
158
     * @throws \Exception
159
     */
160
    public function getDefaultApp() : string
161
    {
162
        return $this->getContainer()->getParameter('aggregator.default_app');
163
    }
164
165
    /**
166
     * @return bool
167
     * @throws \Exception
168
     */
169
    public function isUseJobsInAggregation() : bool
170
    {
171
        return (bool)$this->getContainer()->getParameter('aggregator.use_jobs_in_aggregation');
172
    }
173
174
    /**
175
     * @return string
176
     * @throws \Exception
177
     */
178
    public function getAggregatingJobsLockFile() : string
179
    {
180
        return (string)$this->getContainer()->getParameter('aggregator.aggregating_jobs_lock_file');
181
    }
182
}
183