Вход Регистрация
Файл: system/vendor/illuminate/support/Env.php
Строк: 86
<?php

namespace IlluminateSupport;

use 
DotenvRepositoryAdapterEnvConstAdapter;
use 
DotenvRepositoryAdapterPutenvAdapter;
use 
DotenvRepositoryAdapterServerConstAdapter;
use 
DotenvRepositoryRepositoryBuilder;
use 
PhpOptionOption;

class 
Env
{
    
/**
     * Indicates if the putenv adapter is enabled.
     *
     * @var bool
     */
    
protected static $putenv true;

    
/**
     * The environment repository instance.
     *
     * @var DotenvRepositoryRepositoryInterface|null
     */
    
protected static $repository;

    
/**
     * Enable the putenv adapter.
     *
     * @return void
     */
    
public static function enablePutenv()
    {
        static::
$putenv true;
        static::
$repository null;
    }

    
/**
     * Disable the putenv adapter.
     *
     * @return void
     */
    
public static function disablePutenv()
    {
        static::
$putenv false;
        static::
$repository null;
    }

    
/**
     * Get the environment repository instance.
     *
     * @return DotenvRepositoryRepositoryInterface
     */
    
public static function getRepository()
    {
        if (static::
$repository === null) {
            
$adapters array_merge(
                [new 
EnvConstAdapter, new ServerConstAdapter],
                static::
$putenv ? [new PutenvAdapter] : []
            );

            static::
$repository RepositoryBuilder::create()
                ->
withReaders($adapters)
                ->
withWriters($adapters)
                ->
immutable()
                ->
make();
        }

        return static::
$repository;
    }

    
/**
     * Gets the value of an environment variable.
     *
     * @param  string  $key
     * @param  mixed  $default
     * @return mixed
     */
    
public static function get($key$default null)
    {
        return 
Option::fromValue(static::getRepository()->get($key))
            ->
map(function ($value) {
                switch (
strtolower($value)) {
                    case 
'true':
                    case 
'(true)':
                        return 
true;
                    case 
'false':
                    case 
'(false)':
                        return 
false;
                    case 
'empty':
                    case 
'(empty)':
                        return 
'';
                    case 
'null':
                    case 
'(null)':
                        return;
                }

                if (
preg_match('/A(['"])(.*)1z/', $value$matches)) {
                    return 
$matches[2];
                }

                return 
$value;
            })
            ->getOrCall(function () use (
$default) {
                return value(
$default);
            });
    }
}
Онлайн: 0
Реклама