Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php
Строк: 175
<?php

namespace IlluminateFoundationBootstrap;

use 
DotenvDotenv;
use 
DotenvExceptionInvalidFileException;
use 
IlluminateContractsFoundationApplication;
use 
IlluminateSupportEnv;
use 
SymfonyComponentConsoleInputArgvInput;
use 
SymfonyComponentConsoleOutputConsoleOutput;

class 
LoadEnvironmentVariables
{
    
/**
     * Bootstrap the given application.
     *
     * @param  IlluminateContractsFoundationApplication  $app
     * @return void
     */
    
public function bootstrap(Application $app)
    {
        if (
$app->configurationIsCached()) {
            return;
        }

        
$this->checkForSpecificEnvironmentFile($app);

        try {
            
$this->createDotenv($app)->safeLoad();
        } catch (
InvalidFileException $e) {
            
$this->writeErrorAndDie($e);
        }
    }

    
/**
     * Detect if a custom environment file matching the APP_ENV exists.
     *
     * @param  IlluminateContractsFoundationApplication  $app
     * @return void
     */
    
protected function checkForSpecificEnvironmentFile($app)
    {
        if (
$app->runningInConsole() &&
            (
$input = new ArgvInput)->hasParameterOption('--env') &&
            
$this->setEnvironmentFilePath($app$app->environmentFile().'.'.$input->getParameterOption('--env'))) {
            return;
        }

        
$environment Env::get('APP_ENV');

        if (! 
$environment) {
            return;
        }

        
$this->setEnvironmentFilePath(
            
$app$app->environmentFile().'.'.$environment
        
);
    }

    
/**
     * Load a custom environment file.
     *
     * @param  IlluminateContractsFoundationApplication  $app
     * @param  string  $file
     * @return bool
     */
    
protected function setEnvironmentFilePath($app$file)
    {
        if (
is_file($app->environmentPath().'/'.$file)) {
            
$app->loadEnvironmentFrom($file);

            return 
true;
        }

        return 
false;
    }

    
/**
     * Create a Dotenv instance.
     *
     * @param  IlluminateContractsFoundationApplication  $app
     * @return DotenvDotenv
     */
    
protected function createDotenv($app)
    {
        return 
Dotenv::create(
            
Env::getRepository(),
            
$app->environmentPath(),
            
$app->environmentFile()
        );
    }

    
/**
     * Write the error information to the screen and exit.
     *
     * @param  DotenvExceptionInvalidFileException  $e
     * @return never
     */
    
protected function writeErrorAndDie(InvalidFileException $e)
    {
        
$output = (new ConsoleOutput)->getErrorOutput();

        
$output->writeln('The environment file is invalid!');
        
$output->writeln($e->getMessage());

        
http_response_code(500);

        exit(
1);
    }
}
Онлайн: 1
Реклама