find and register Environment variables for application

@throws \Illuminate\Contracts\Filesystem\FileNotFoundException
435183
private function prepareEnvironment()
    {
        $filesystem = $this->make(Filesystem::class);


        if ($filesystem instanceof Filesystem) {
            if ($filesystem->exists($path = $this->getEnvironmentPath())) {
                $env = $filesystem->get($path);


                array_map(
                    function ($env) {

                        if ($env !== '' && $env !== null) {
                            putenv($env);
                        }
                    },
                    explode("\n", $env)
                );

                $this->environments = count($_ENV) ? $_ENV : isset($_SERVER['ENV']) ? $_SERVER['ENV'] : [];
            }
        }

    }
1081420
def environment_variables
      vars = @process.environment_variables.merge({
        'PROC_NAME' => self.description,
        'PID_FILE' => self.pid_file_path,
        'APP_ROOT' => @process.config.root
      })
      vars['PORT'] = @port.to_s if @port
      vars
    end
750681
public function checkEnvironmentVariables()
    {
        $settingsValues = array();
        $iniSettings = array(
            'memory_limit', 'max_execution_time', 'upload_max_filesize'
        );

        foreach($iniSettings as $setting) {
            $settingsValues[$setting] = ini_get($setting);
        }

        return $settingsValues;
    }
669398
protected function initEnvironment()
    {
        $path = getcwd();
        if (!is_file("$path/.env")) {
            return;
        }
        $dotenv = new \Dotenv\Dotenv($path);
        if ($this->dotEnvOverload) {
            $dotenv->overload();
        } else {
            $dotenv->load();
        }
    }
622429
private function registerFilesystem()
    {
        $this->singleton(Contracts\Utilities\Filesystem::class, function ($app) {
            /**
             * @var  \Illuminate\Config\Repository      $config
             * @var  \Illuminate\Filesystem\Filesystem  $files
             */
            $config     = $app['config'];
            $files      = $app['files'];
            $filesystem = new Utilities\Filesystem($files, $config->get('log-viewer.storage-path'));

            $pattern = $config->get('log-viewer.pattern', []);

            $filesystem->setPattern(
                Arr::get($pattern, 'prefix',    Utilities\Filesystem::PATTERN_PREFIX),
                Arr::get($pattern, 'date',      Utilities\Filesystem::PATTERN_DATE),
                Arr::get($pattern, 'extension', Utilities\Filesystem::PATTERN_EXTENSION)
            );

            return $filesystem;
        });
    }
959792
protected function _getEnvironment()
    {
        $environment = self::$forceEnvironment;

        // Check if the environment has been manually set (forced).
        if ($environment !== null) {
            if (!isset($this->_environments[$environment])) {
                throw new Exception('Environment configuration for "' . $environment . '" could not be found.');
            }
        }
        // If no manual setting is available, use "host:port" to decide which config to use.
        if ($environment === null && !empty($_SERVER['HTTP_HOST'])) {
            $host = (string)$_SERVER['HTTP_HOST'];
            foreach ($this->_environments as $env => $envConfig) {
                if (isset($envConfig['domain']) && in_array($host, $envConfig['domain'])) {
                    $environment = $env;
                    break;
                }
            }
        }
        // If there is no host:port match, try "host" only.
        if ($environment === null && !empty($_SERVER['SERVER_NAME'])) {
            $host = (string)$_SERVER['SERVER_NAME'];
            foreach ($this->_environments as $env => $envConfig) {
                if (isset($envConfig['domain']) && in_array($host, $envConfig['domain'])) {
                    $environment = $env;
                    break;
                }
            }
        }
        // If no host matched then try to use the APP path.
        if ($environment === null && ($serverPath = $this->_getRealAppPath())) {
            foreach ($this->_environments as $env => $envConfig) {
                if (isset($envConfig['path']) && in_array($serverPath, $envConfig['path'])) {
                    $environment = $env;
                    break;
                }
            }
        }
        // No environment could be identified -> we are on a dev machine.
        if (!$environment) {
            $environment = 'local';
        }

        return $environment;
    }
256445
protected function loadEnv()
    {
        try {
            $this->dotenv->load();
            $this->dotenv->required($this->required);
        } catch (\InvalidArgumentException $e) {
            // Assuming env data is set by server
        }
    }
1073639
protected function registerConfigFiles()
    {
        if (isset($this->dir) and isset($this->configFiles) and is_array($this->configFiles)) {
            foreach ($this->configFiles as $key) {
                $path = $this->getConfigFilePath($key);
                //$this->mergeConfigFrom($this->getConfigFilePath($filename), $filename);
                $config = $this->app->make('config')->get($key, [ ]);
                $this->app->make('config')->set($key, array_replace_recursive(require $path, $config));
            }
        }
    }
609178
public function registerEnvironment()
	{
		$this->app->bindShared('view', function($app)
		{
			// Next we need to grab the engine resolver instance that will be used by the
			// environment. The resolver will be used by an environment to get each of
			// the various engine implementations such as plain PHP or Sword engine.
			$resolver = $app['view.engine.resolver'];

			$finder = $app['view.finder'];

			$env = new Environment($resolver, $finder, $app['events']);

			// We will also set the container instance on this view environment since the
			// view composers may be classes registered in the container, which allows
			// for great testable, flexible composers for the application developer.
			$env->setContainer($app);

			$env->share('app', $app);

			return $env;
		});
	}
222918
private function findPaths()
    {
        $configFilename = $this->projectPath . DIRECTORY_SEPARATOR . $this->configFile;
        $handle         = fopen($configFilename, 'r');
        if (false === $handle) {
            throw new \FileNotFoundException($configFilename . ' could not be found');
        }
        $contents = fread($handle, filesize($configFilename));
        foreach (explode(PHP_EOL, $contents) as $line) {
            if (preg_match('/sass_dir ?= ?"(.*)"/', $line, $matches) !== 0) {
                $this->sassPath = $this->projectPath . DIRECTORY_SEPARATOR . $matches[1];
            }
            if (preg_match('/css_dir ?= ?"(.*)"/', $line, $matches) !== 0) {
                $this->cssPath = $this->projectPath . DIRECTORY_SEPARATOR . $matches[1];
            }
        }
    }
663338
public function init()
    {
        if (!defined('APPLICATION_PATH')) {
            throw new ArchException('Please define the APPLICATION_PATH constant');
        }
        if (!defined('APPLICATION_ENV')) {
            $env = getenv('APPLICATION_ENV');
            if ($env && !in_array($env, [self::ENV_DEV, self::ENV_STG, self::ENV_DEM, self::ENV_PRD])) {
                throw new ArchException('Execution environment "' . $env . '" is not correct. '
                            . 'Please choose one of theses : ' . self::ENV_DEV . ', ' . self::ENV_STG . ', ' 
                            . self::ENV_DEM . ' or ' . self::ENV_PRD);
            }
            define('APPLICATION_ENV', $env ?: self::ENV_PRD);
        }
        
        return $this;
    }
1339201
protected function checkEnvironmentPath() {
		// Create folder if it doesn't exist
		$configDir = dirname($this->getConfigFilename());
		if(!file_exists($configDir) && $configDir) {
			mkdir($configDir, 0777, true);
		}
	}
131279
protected function envFileToUseForDefaults()
    {
        $file = config('setup.dot_env.default_file');

        if ($this->envFileExist() &&
            $this->command->confirm('Existing .env file was found. Use it for defaults?', true)
        )
        {
            $file = '.env';
        }

        return $file;
    }
1118005
protected function checkForSpecificEnvironmentFile($app)
    {
//        if (php_sapi_name() == 'cli' && with($input = new ArgvInput)->hasParameterOption('--env')) {
//            $this->setEnvironmentFilePath(
//                $app, $app->environmentFile() . '.' . $input->getParameterOption('--env')
//            );
//        }
        if (!env('APP_ENV') || empty($file)) {
            return;
        }
        $this->setEnvironmentFilePath(
            $app,
            $app->environmentFile() . '.' . env('APP_ENV')
        );
    }
1054254
private static function environment() {
	$environment = getenv('APP_ENV') ?: 'production';
	
	define('alsvanzelf\fem\ENVIRONMENT',  $environment);
	define('alsvanzelf\fem\ROOT_DIR',     realpath(__DIR__.'/../../../../').'/');
	define('alsvanzelf\fem\ROOT_DIR_APP', \alsvanzelf\fem\ROOT_DIR.'application/');
	define('alsvanzelf\fem\CLI',          (strpos(php_sapi_name(), 'cli') !== false || defined('STDIN')));
	
	if (constant('\alsvanzelf\fem\ENVIRONMENT') == false) {
		echo 'no environment set';
		exit;
	}
}
1300639
private function registerAppBindings($environment)
    {
        static::setInstance($this);

        // Set application environment
        $this->setEnvironment($environment);

        // Set container
        $this->set('app', $this);
        $this->set(self::class, $this);
        $this->set(Container::class, $this);

        return $this;
    }
1352237
protected function loadEnvironments()
    {
        $this->purge();
        if (false == file_exists($this->getFileName())) {
            touch($this->getFileName());
        }
        $tempEnvironments = file($this->getFileName());
        foreach ($tempEnvironments as $key => $value) {
            $value = trim($value);
            if (null != $value && '' != $value && false == is_array($value)) {
                if (true == $this->vagrentExists($value)) {
                    $this->_environments[] = $value;
                }
            }
        }
        return $this->_environments;
    }