Domain::getCachedServicesPath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Salah3id\Domains\Laravel;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Foundation\AliasLoader;
7
use Illuminate\Foundation\ProviderRepository;
8
use Illuminate\Support\Str;
9
use Salah3id\Domains\Domain as BaseDomain;
10
11
class Domain extends BaseDomain
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function getCachedServicesPath(): string
17
    {
18
        // This checks if we are running on a Laravel Vapor managed instance
19
        // and sets the path to a writable one (services path is not on a writable storage in Vapor).
20
        if (!is_null(env('VAPOR_MAINTENANCE_MODE', null))) {
21
            return Str::replaceLast('config.php', $this->getSnakeName() . '_domain.php', $this->app->getCachedConfigPath());
22
        }
23
24
        return Str::replaceLast('services.php', $this->getSnakeName() . '_domain.php', $this->app->getCachedServicesPath());
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function registerProviders(): void
31
    {
32
        (new ProviderRepository($this->app, new Filesystem(), $this->getCachedServicesPath()))
33
            ->load($this->get('providers', []));
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function registerAliases(): void
40
    {
41
        $loader = AliasLoader::getInstance();
42
        foreach ($this->get('aliases', []) as $aliasName => $aliasClass) {
43
            $loader->alias($aliasName, $aliasClass);
44
        }
45
    }
46
}
47