Completed
Push — master ( b69e83...ad913f )
by Vladimir
02:54
created

AppServiceProvider::basePath()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Application;
6
7
use Dotenv\Dotenv;
8
use League\Container\ServiceProvider\AbstractServiceProvider;
9
10
abstract class AppServiceProvider extends AbstractServiceProvider
11
{
12
    protected $provides = [
13
        Config::class,
14
        'env',
15
        'base_path',
16
        'resources_path',
17
    ];
18
19
    /**
20
     * Determine environment where application is currently is running on.
21
     *
22
     * @return string
23
     */
24
    abstract public function environment(): string;
25
26
    /**
27
     * Base path of the application.
28
     *
29
     * @return string
30
     */
31
    abstract public function basePath(): string;
32
33
    /**
34
     * Path to the "resources folder".
35
     *
36
     * @return string
37
     */
38
    abstract public function resourcesPath(): string;
39
40
    /**
41
     * Use the register method to register items with the container via the
42
     * protected $this->container property or the `getContainer` method
43
     * from the ContainerAwareTrait.
44
     *
45
     * @return void
46
     */
47
    public function register(): void
48
    {
49
        $this->getContainer()->share(Config::class, function () {
50
            $dotenv = new Dotenv($this->basePath());
51
52
            return new Config($dotenv->load());
53
        });
54
55
        $this->getContainer()->share('env', $this->environment());
56
        $this->getContainer()->share('base_path', $this->basePath());
57
        $this->getContainer()->share('resources_path', $this->resourcesPath());
58
    }
59
}
60