Completed
Push — master ( fb06ff...f5244f )
by Vladimir
02:51
created

AppServiceProvider::resourcesPath()

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
use League\Container\ServiceProvider\BootableServiceProviderInterface;
10
11
abstract class AppServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface
12
{
13
    protected $provides = [
14
        Config::class,
15
        'environment',
16
        'base_path',
17
        'resources_path',
18
    ];
19
20
    /**
21
     * Determine environment where application is currently is running on.
22
     *
23
     * @return string
24
     */
25
    abstract public function environment(): string;
26
27
    /**
28
     * Base path of the application.
29
     *
30
     * @return string
31
     */
32
    abstract public function basePath(): string;
33
34
    /**
35
     * Path to the "resources folder".
36
     *
37
     * @return string
38
     */
39
    abstract public function resourcesPath(): string;
40
41
    /**
42
     * Method will be invoked on registration of a service provider implementing
43
     * this interface. Provides ability for eager loading of Service Providers.
44
     *
45
     * @return void
46
     */
47 1
    public function boot(): void
48
    {
49 1
        $dotenv = new Dotenv($this->basePath());
50 1
        $dotenv->load();
51
52 1
        $this->getContainer()->share(Config::class, function () {
53 1
            return new Config($_ENV);
54 1
        });
55 1
    }
56
57
    /**
58
     * Use the register method to register items with the container via the
59
     * protected $this->container property or the `getContainer` method
60
     * from the ContainerAwareTrait.
61
     *
62
     * @return void
63
     */
64 1
    public function register(): void
65
    {
66 1
        $this->getContainer()->share('environment', $this->environment());
67 1
        $this->getContainer()->share('base_path', $this->basePath());
68 1
        $this->getContainer()->share('resources_path', $this->resourcesPath());
69 1
    }
70
}
71