summaryrefslogtreecommitdiff
path: root/src/Application.php
blob: 80538396c06f037ed969467ad9a5b2dc217eee85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

namespace Engelsystem;

use Engelsystem\Container\Container;
use Psr\Container\ContainerInterface;

class Application extends Container
{
    /** @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();
    }

    protected function registerBaseBindings()
    {
        static::setInstance($this);
        Container::setInstance($this);
        $this->instance('app', $this);
        $this->instance('container', $this);
        $this->instance(Container::class, $this);
        $this->instance(Application::class, $this);
        $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;
    }
}