Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Bootstrap;
4
 
5
use Dotenv\Dotenv;
6
use Dotenv\Exception\InvalidFileException;
7
use Illuminate\Contracts\Foundation\Application;
8
use Illuminate\Support\Env;
9
use Symfony\Component\Console\Input\ArgvInput;
10
use Symfony\Component\Console\Output\ConsoleOutput;
11
 
12
class LoadEnvironmentVariables
13
{
14
    /**
15
     * Bootstrap the given application.
16
     *
17
     * @param  \Illuminate\Contracts\Foundation\Application  $app
18
     * @return void
19
     */
20
    public function bootstrap(Application $app)
21
    {
22
        if ($app->configurationIsCached()) {
23
            return;
24
        }
25
 
26
        $this->checkForSpecificEnvironmentFile($app);
27
 
28
        try {
29
            $this->createDotenv($app)->safeLoad();
30
        } catch (InvalidFileException $e) {
31
            $this->writeErrorAndDie($e);
32
        }
33
    }
34
 
35
    /**
36
     * Detect if a custom environment file matching the APP_ENV exists.
37
     *
38
     * @param  \Illuminate\Contracts\Foundation\Application  $app
39
     * @return void
40
     */
41
    protected function checkForSpecificEnvironmentFile($app)
42
    {
43
        if ($app->runningInConsole() &&
44
            ($input = new ArgvInput)->hasParameterOption('--env') &&
45
            $this->setEnvironmentFilePath($app, $app->environmentFile().'.'.$input->getParameterOption('--env'))) {
46
            return;
47
        }
48
 
49
        $environment = Env::get('APP_ENV');
50
 
51
        if (! $environment) {
52
            return;
53
        }
54
 
55
        $this->setEnvironmentFilePath(
56
            $app, $app->environmentFile().'.'.$environment
57
        );
58
    }
59
 
60
    /**
61
     * Load a custom environment file.
62
     *
63
     * @param  \Illuminate\Contracts\Foundation\Application  $app
64
     * @param  string  $file
65
     * @return bool
66
     */
67
    protected function setEnvironmentFilePath($app, $file)
68
    {
69
        if (is_file($app->environmentPath().'/'.$file)) {
70
            $app->loadEnvironmentFrom($file);
71
 
72
            return true;
73
        }
74
 
75
        return false;
76
    }
77
 
78
    /**
79
     * Create a Dotenv instance.
80
     *
81
     * @param  \Illuminate\Contracts\Foundation\Application  $app
82
     * @return \Dotenv\Dotenv
83
     */
84
    protected function createDotenv($app)
85
    {
86
        return Dotenv::create(
87
            Env::getRepository(),
88
            $app->environmentPath(),
89
            $app->environmentFile()
90
        );
91
    }
92
 
93
    /**
94
     * Write the error information to the screen and exit.
95
     *
96
     * @param  \Dotenv\Exception\InvalidFileException  $e
97
     * @return void
98
     */
99
    protected function writeErrorAndDie(InvalidFileException $e)
100
    {
101
        $output = (new ConsoleOutput)->getErrorOutput();
102
 
103
        $output->writeln('The environment file is invalid!');
104
        $output->writeln($e->getMessage());
105
 
106
        http_response_code(500);
107
 
108
        exit(1);
109
    }
110
}