1 | <?php |
||
13 | class AppMeta extends AbstractAppMeta |
||
14 | { |
||
15 | /** |
||
16 | * @param string $name application name (Vendor\Project) |
||
17 | * @param string $context application context (prod-hal-app) |
||
18 | * @param string $appDir application directory |
||
19 | */ |
||
20 | 4 | public function __construct($name, $context = 'app', $appDir = null) |
|
21 | { |
||
22 | 4 | $appModule = $name . '\Module\AppModule'; |
|
23 | 4 | if (! class_exists($appModule)) { |
|
24 | 1 | throw new AppNameException($name); |
|
25 | } |
||
26 | 4 | $this->name = $name; |
|
27 | 4 | $this->appDir = $appDir ? $appDir : dirname(dirname(dirname((new \ReflectionClass($appModule))->getFileName()))); |
|
28 | 4 | $this->tmpDir = $this->appDir . '/var/tmp/' . $context; |
|
29 | 4 | if (! file_exists($this->tmpDir) && mkdir($this->tmpDir) && ! is_writable($this->tmpDir)) { |
|
30 | throw new NotWritableException($this->tmpDir); |
||
31 | } |
||
32 | 4 | $this->logDir = $this->appDir . '/var/log/' . $context; |
|
33 | 4 | if (! file_exists($this->logDir) && mkdir($this->logDir) && ! is_writable($this->logDir)) { |
|
34 | throw new NotWritableException($this->logDir); |
||
35 | } |
||
36 | 4 | $isDevelop = strpos($context, 'prod') === false; |
|
37 | 4 | if ($isDevelop) { |
|
38 | 2 | $this->clearTmpDirectory($this->tmpDir); |
|
39 | } |
||
40 | 4 | } |
|
41 | |||
42 | /** |
||
43 | * @return \Generator |
||
44 | */ |
||
45 | 1 | public function getResourceListGenerator() |
|
52 | |||
53 | /** |
||
54 | * @param string $dir |
||
55 | */ |
||
56 | 2 | private function clearTmpDirectory($dir) |
|
75 | } |
||
76 |