Upgrade framework
This commit is contained in:
47
vendor/vlucas/phpdotenv/src/Loader/Loader.php
vendored
Normal file
47
vendor/vlucas/phpdotenv/src/Loader/Loader.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Loader;
|
||||
|
||||
use Dotenv\Parser\Entry;
|
||||
use Dotenv\Parser\Value;
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
|
||||
final class Loader implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Load the given entries into the repository.
|
||||
*
|
||||
* We'll substitute any nested variables, and send each variable to the
|
||||
* repository, with the effect of actually mutating the environment.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param \Dotenv\Parser\Entry[] $entries
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public function load(RepositoryInterface $repository, array $entries)
|
||||
{
|
||||
return \array_reduce($entries, static function (array $vars, Entry $entry) use ($repository) {
|
||||
$name = $entry->getName();
|
||||
|
||||
$value = $entry->getValue()->map(static function (Value $value) use ($repository) {
|
||||
return Resolver::resolve($repository, $value);
|
||||
});
|
||||
|
||||
if ($value->isDefined()) {
|
||||
$inner = $value->get();
|
||||
if ($repository->set($name, $inner)) {
|
||||
return \array_merge($vars, [$name => $inner]);
|
||||
}
|
||||
} else {
|
||||
if ($repository->clear($name)) {
|
||||
return \array_merge($vars, [$name => null]);
|
||||
}
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}, []);
|
||||
}
|
||||
}
|
||||
20
vendor/vlucas/phpdotenv/src/Loader/LoaderInterface.php
vendored
Normal file
20
vendor/vlucas/phpdotenv/src/Loader/LoaderInterface.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Loader;
|
||||
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
|
||||
interface LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Load the given entries into the repository.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param \Dotenv\Parser\Entry[] $entries
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public function load(RepositoryInterface $repository, array $entries);
|
||||
}
|
||||
65
vendor/vlucas/phpdotenv/src/Loader/Resolver.php
vendored
Normal file
65
vendor/vlucas/phpdotenv/src/Loader/Resolver.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Loader;
|
||||
|
||||
use Dotenv\Parser\Value;
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
use Dotenv\Util\Regex;
|
||||
use Dotenv\Util\Str;
|
||||
use PhpOption\Option;
|
||||
|
||||
final class Resolver
|
||||
{
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the nested variables in the given value.
|
||||
*
|
||||
* Replaces ${varname} patterns in the allowed positions in the variable
|
||||
* value by an existing environment variable.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param \Dotenv\Parser\Value $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function resolve(RepositoryInterface $repository, Value $value)
|
||||
{
|
||||
return \array_reduce($value->getVars(), static function (string $s, int $i) use ($repository) {
|
||||
return Str::substr($s, 0, $i).self::resolveVariable($repository, Str::substr($s, $i));
|
||||
}, $value->getChars());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a single nested variable.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function resolveVariable(RepositoryInterface $repository, string $str)
|
||||
{
|
||||
return Regex::replaceCallback(
|
||||
'/\A\${([a-zA-Z0-9_.]+)}/',
|
||||
static function (array $matches) use ($repository) {
|
||||
return Option::fromValue($repository->get($matches[1]))
|
||||
->getOrElse($matches[0]);
|
||||
},
|
||||
$str,
|
||||
1
|
||||
)->success()->getOrElse($str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user