Added app path to container

This commit is contained in:
Igor Scheller 2017-09-21 20:52:19 +02:00
parent 212760d4c9
commit 783c58611a
2 changed files with 36 additions and 2 deletions

View File

@ -23,7 +23,7 @@ require_once __DIR__ . '/autoload.php';
/** /**
* Initialize the application * Initialize the application
*/ */
$app = Application::getInstance(); $app = new Application(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'));
/** /**

View File

@ -7,8 +7,20 @@ use Psr\Container\ContainerInterface;
class Application extends Container class Application extends Container
{ {
public function __construct() /** @var string|null */
protected $appPath = null;
/**
* Application constructor.
*
* @param string $appPath
*/
public function __construct($appPath = null)
{ {
if (!is_null($appPath)) {
$this->setAppPath($appPath);
}
$this->registerBaseBindings(); $this->registerBaseBindings();
} }
@ -22,4 +34,26 @@ class Application extends Container
$this->instance(Application::class, $this); $this->instance(Application::class, $this);
$this->bind(ContainerInterface::class, Application::class); $this->bind(ContainerInterface::class, Application::class);
} }
/**
* @param string $appPath
* @return static
*/
public function setAppPath($appPath)
{
$appPath = rtrim($appPath, DIRECTORY_SEPARATOR);
$this->appPath = $appPath;
$this->instance('path', $appPath);
return $this;
}
/**
* @return string|null
*/
public function path()
{
return $this->appPath;
}
} }