Skip to content

Commit

Permalink
Merge pull request #20 from koriym/meta
Browse files Browse the repository at this point in the history
Add Meta
  • Loading branch information
koriym authored May 11, 2018
2 parents be14df6 + 2e94f14 commit 4f78477
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.AppMeta package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace BEAR\AppMeta;

use BEAR\AppMeta\Exception\AppNameException;
use BEAR\AppMeta\Exception\NotWritableException;

class Meta extends AbstractAppMeta
{
/**
* @param string $name application name (Vendor\Project)
* @param string $context application context (prod-hal-app)
* @param string $appDir application directory
*/
public function __construct(string $name, string $context = 'app', string $appDir = '')
{
$this->name = $name;
try {
$this->appDir = $appDir ?: dirname((new \ReflectionClass($name . '\Module\AppModule'))->getFileName(), 3);
} catch (\ReflectionException $e) {
throw new AppNameException($name);
}
$this->tmpDir = $this->appDir . '/var/tmp/' . $context;
if (! file_exists($this->tmpDir) && ! @mkdir($this->tmpDir, 0777, true) && ! is_dir($this->tmpDir)) {
throw new NotWritableException($this->tmpDir);
}
$this->logDir = $this->appDir . '/var/log/' . $context;
if (! file_exists($this->logDir) && ! @mkdir($this->logDir, 0777, true) && ! is_dir($this->logDir)) {
throw new NotWritableException($this->logDir);
}
}
}

0 comments on commit 4f78477

Please sign in to comment.