Primo Committ
This commit is contained in:
27
vendor/vlucas/phpdotenv/src/Store/File/Paths.php
vendored
Normal file
27
vendor/vlucas/phpdotenv/src/Store/File/Paths.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Store\File;
|
||||
|
||||
class Paths
|
||||
{
|
||||
/**
|
||||
* Returns the full paths to the files.
|
||||
*
|
||||
* @param string[] $paths
|
||||
* @param string[] $names
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function filePaths(array $paths, array $names)
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
foreach ($names as $name) {
|
||||
$files[] = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$name;
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
52
vendor/vlucas/phpdotenv/src/Store/File/Reader.php
vendored
Normal file
52
vendor/vlucas/phpdotenv/src/Store/File/Reader.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Store\File;
|
||||
|
||||
use PhpOption\Option;
|
||||
|
||||
class Reader
|
||||
{
|
||||
/**
|
||||
* Read the file(s), and return their raw content.
|
||||
*
|
||||
* We provide the file path as the key, and its content as the value. If
|
||||
* short circuit mode is enabled, then the returned array with have length
|
||||
* at most one. File paths that couldn't be read are omitted entirely.
|
||||
*
|
||||
* @param string[] $filePaths
|
||||
* @param bool $shortCircuit
|
||||
*
|
||||
* @return array<string,string>
|
||||
*/
|
||||
public static function read(array $filePaths, $shortCircuit = true)
|
||||
{
|
||||
$output = [];
|
||||
|
||||
foreach ($filePaths as $filePath) {
|
||||
$content = self::readFromFile($filePath);
|
||||
if ($content->isDefined()) {
|
||||
$output[$filePath] = $content->get();
|
||||
if ($shortCircuit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the given file.
|
||||
*
|
||||
* @param string $filePath
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
private static function readFromFile($filePath)
|
||||
{
|
||||
$content = @file_get_contents($filePath);
|
||||
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromValue($content, false);
|
||||
}
|
||||
}
|
||||
61
vendor/vlucas/phpdotenv/src/Store/FileStore.php
vendored
Normal file
61
vendor/vlucas/phpdotenv/src/Store/FileStore.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Store;
|
||||
|
||||
use Dotenv\Exception\InvalidPathException;
|
||||
use Dotenv\Store\File\Reader;
|
||||
|
||||
class FileStore implements StoreInterface
|
||||
{
|
||||
/**
|
||||
* The file paths.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $filePaths;
|
||||
|
||||
/**
|
||||
* Should file loading short circuit?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shortCircuit;
|
||||
|
||||
/**
|
||||
* Create a new file store instance.
|
||||
*
|
||||
* @param string[] $filePaths
|
||||
* @param bool $shortCircuit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $filePaths, $shortCircuit)
|
||||
{
|
||||
$this->filePaths = $filePaths;
|
||||
$this->shortCircuit = $shortCircuit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the content of the environment file(s).
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidPathException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
if ($this->filePaths === []) {
|
||||
throw new InvalidPathException('At least one environment file path must be provided.');
|
||||
}
|
||||
|
||||
$contents = Reader::read($this->filePaths, $this->shortCircuit);
|
||||
|
||||
if (count($contents) > 0) {
|
||||
return implode("\n", $contents);
|
||||
}
|
||||
|
||||
throw new InvalidPathException(
|
||||
sprintf('Unable to read any of the environment file(s) at [%s].', implode(', ', $this->filePaths))
|
||||
);
|
||||
}
|
||||
}
|
||||
102
vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php
vendored
Normal file
102
vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Store;
|
||||
|
||||
use Dotenv\Store\File\Paths;
|
||||
|
||||
class StoreBuilder
|
||||
{
|
||||
/**
|
||||
* The paths to search within.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $paths;
|
||||
|
||||
/**
|
||||
* The file names to search for.
|
||||
*
|
||||
* @var string[]|null
|
||||
*/
|
||||
private $names;
|
||||
|
||||
/**
|
||||
* Should file loading short circuit?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shortCircuit;
|
||||
|
||||
/**
|
||||
* Create a new store builder instance.
|
||||
*
|
||||
* @param string[] $paths
|
||||
* @param string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct(array $paths = [], array $names = null, $shortCircuit = false)
|
||||
{
|
||||
$this->paths = $paths;
|
||||
$this->names = $names;
|
||||
$this->shortCircuit = $shortCircuit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new store builder instance.
|
||||
*
|
||||
* @return \Dotenv\Store\StoreBuilder
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a store builder with the given paths.
|
||||
*
|
||||
* @param string|string[] $paths
|
||||
*
|
||||
* @return \Dotenv\Store\StoreBuilder
|
||||
*/
|
||||
public function withPaths($paths)
|
||||
{
|
||||
return new self((array) $paths, $this->names, $this->shortCircuit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a store builder with the given names.
|
||||
*
|
||||
* @param string|string[]|null $names
|
||||
*
|
||||
* @return \Dotenv\Store\StoreBuilder
|
||||
*/
|
||||
public function withNames($names = null)
|
||||
{
|
||||
return new self($this->paths, $names === null ? null : (array) $names, $this->shortCircuit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a store builder with short circuit mode enabled.
|
||||
*
|
||||
* @return \Dotenv\Store\StoreBuilder
|
||||
*/
|
||||
public function shortCircuit()
|
||||
{
|
||||
return new self($this->paths, $this->names, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new store instance.
|
||||
*
|
||||
* @return \Dotenv\Store\StoreInterface
|
||||
*/
|
||||
public function make()
|
||||
{
|
||||
return new FileStore(
|
||||
Paths::filePaths($this->paths, $this->names === null ? ['.env'] : $this->names),
|
||||
$this->shortCircuit
|
||||
);
|
||||
}
|
||||
}
|
||||
15
vendor/vlucas/phpdotenv/src/Store/StoreInterface.php
vendored
Normal file
15
vendor/vlucas/phpdotenv/src/Store/StoreInterface.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Store;
|
||||
|
||||
interface StoreInterface
|
||||
{
|
||||
/**
|
||||
* Read the content of the environment file(s).
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidPathException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read();
|
||||
}
|
||||
35
vendor/vlucas/phpdotenv/src/Store/StringStore.php
vendored
Normal file
35
vendor/vlucas/phpdotenv/src/Store/StringStore.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Store;
|
||||
|
||||
final class StringStore implements StoreInterface
|
||||
{
|
||||
/**
|
||||
* The file content.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* Create a new string store instance.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the content of the environment file(s).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user