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