updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -2,48 +2,78 @@
namespace Dotenv;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Environment\FactoryInterface;
use Dotenv\Exception\InvalidPathException;
/**
* This is the dotenv class.
*
* It's responsible for loading a `.env` file in the given directory and
* setting the environment vars.
* setting the environment variables.
*/
class Dotenv
{
/**
* The file path.
*
* @var string
*/
protected $filePath;
/**
* The loader instance.
*
* @var \Dotenv\Loader|null
* @var \Dotenv\Loader
*/
protected $loader;
/**
* Create a new dotenv instance.
*
* @param string $path
* @param string $file
* @param \Dotenv\Loader $loader
*
* @return void
*/
public function __construct($path, $file = '.env')
public function __construct(Loader $loader)
{
$this->filePath = $this->getFilePath($path, $file);
$this->loader = new Loader($this->filePath, true);
$this->loader = $loader;
}
/**
* Create a new dotenv instance.
*
* @param string|string[] $paths
* @param string|null $file
* @param \Dotenv\Environment\FactoryInterface|null $envFactory
*
* @return \Dotenv\Dotenv
*/
public static function create($paths, $file = null, FactoryInterface $envFactory = null)
{
$loader = new Loader(
self::getFilePaths((array) $paths, $file ?: '.env'),
$envFactory ?: new DotenvFactory(),
true
);
return new self($loader);
}
/**
* Returns the full paths to the files.
*
* @param string[] $paths
* @param string $file
*
* @return string[]
*/
private static function getFilePaths(array $paths, $file)
{
return array_map(function ($path) use ($file) {
return rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file;
}, $paths);
}
/**
* Load environment file in given directory.
*
* @return array
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
*
* @return array<string|null>
*/
public function load()
{
@@ -51,9 +81,11 @@ class Dotenv
}
/**
* Load environment file in given directory, suppress InvalidPathException.
* Load environment file in given directory, silently failing if it doesn't exist.
*
* @return array
* @throws \Dotenv\Exception\InvalidFileException
*
* @return array<string|null>
*/
public function safeLoad()
{
@@ -61,45 +93,30 @@ class Dotenv
return $this->loadData();
} catch (InvalidPathException $e) {
// suppressing exception
return array();
return [];
}
}
/**
* Load environment file in given directory.
*
* @return array
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
*
* @return array<string|null>
*/
public function overload()
{
return $this->loadData(true);
}
/**
* Returns the full path to the file.
*
* @param string $path
* @param string $file
*
* @return string
*/
protected function getFilePath($path, $file)
{
if (!is_string($file)) {
$file = '.env';
}
$filePath = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file;
return $filePath;
}
/**
* Actually load the data.
*
* @param bool $overload
*
* @return array
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
*
* @return array<string|null>
*/
protected function loadData($overload = false)
{
@@ -109,22 +126,34 @@ class Dotenv
/**
* Required ensures that the specified variables exist, and returns a new validator object.
*
* @param string|string[] $variable
* @param string|string[] $variables
*
* @return \Dotenv\Validator
*/
public function required($variable)
public function required($variables)
{
return new Validator((array) $variable, $this->loader);
return new Validator((array) $variables, $this->loader);
}
/**
* Returns a new validator object that won't check if the specified variables exist.
*
* @param string|string[] $variables
*
* @return \Dotenv\Validator
*/
public function ifPresent($variables)
{
return new Validator((array) $variables, $this->loader, false);
}
/**
* Get the list of environment variables declared inside the 'env' file.
*
* @return array
* @return string[]
*/
public function getEnvironmentVariableNames()
{
return $this->loader->variableNames;
return $this->loader->getEnvironmentVariableNames();
}
}