dependencies-upgrade
This commit is contained in:
15
vendor/vlucas/phpdotenv/src/Repository/Adapter/AdapterInterface.php
vendored
Normal file
15
vendor/vlucas/phpdotenv/src/Repository/Adapter/AdapterInterface.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface AdapterInterface extends ReaderInterface, WriterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create();
|
||||
}
|
||||
@@ -1,11 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
class ApacheAdapter implements AvailabilityInterface, ReaderInterface, WriterInterface
|
||||
final class ApacheAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new apache adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
if (self::isSupported()) {
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
*
|
||||
@@ -13,54 +42,48 @@ class ApacheAdapter implements AvailabilityInterface, ReaderInterface, WriterInt
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported()
|
||||
private static function isSupported()
|
||||
{
|
||||
return function_exists('apache_getenv') && function_exists('apache_setenv');
|
||||
return \function_exists('apache_getenv') && \function_exists('apache_setenv');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment variable, if it exists.
|
||||
*
|
||||
* This is intentionally not implemented, since this adapter exists only as
|
||||
* a means to overwrite existing apache environment variables.
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string|null>
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function get($name)
|
||||
public function read(string $name)
|
||||
{
|
||||
return None::create();
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromValue(apache_getenv($name))->filter(static function ($value) {
|
||||
return \is_string($value) && $value !== '';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* Only if an existing apache variable exists do we overwrite it.
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string|null $value
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function set($name, $value = null)
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
if (apache_getenv($name) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
apache_setenv($name, (string) $value);
|
||||
return apache_setenv($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function clear($name)
|
||||
public function delete(string $name)
|
||||
{
|
||||
// Nothing to do here.
|
||||
return apache_setenv($name, '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
class ArrayAdapter implements AvailabilityInterface, ReaderInterface, WriterInterface
|
||||
final class ArrayAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* The variables and their values.
|
||||
*
|
||||
* @var array<non-empty-string,string|null>
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $variables = [];
|
||||
private $variables;
|
||||
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
* Create a new array adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
$this->variables = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
return Option::fromArraysValue($this->variables, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported()
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
$this->variables[$name] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment variable, if it exists.
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string|null>
|
||||
* @return bool
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!array_key_exists($name, $this->variables)) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
return Some::create($this->variables[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($name, $value = null)
|
||||
{
|
||||
$this->variables[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear($name)
|
||||
public function delete(string $name)
|
||||
{
|
||||
unset($this->variables[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface AvailabilityInterface
|
||||
{
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported();
|
||||
}
|
||||
@@ -1,72 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
class EnvConstAdapter implements AvailabilityInterface, ReaderInterface, WriterInterface
|
||||
final class EnvConstAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
* Create a new env const adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromArraysValue($_ENV, $name)
|
||||
->filter(static function ($value) {
|
||||
return \is_scalar($value);
|
||||
})
|
||||
->map(static function ($value) {
|
||||
if ($value === false) {
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if ($value === true) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidCast */
|
||||
return (string) $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported()
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
$_ENV[$name] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment variable, if it exists.
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string|null>
|
||||
* @return bool
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!array_key_exists($name, $_ENV)) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
$value = $_ENV[$name];
|
||||
|
||||
if (is_scalar($value)) {
|
||||
/** @var \PhpOption\Option<string|null> */
|
||||
return Some::create((string) $value);
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
/** @var \PhpOption\Option<string|null> */
|
||||
return Some::create(null);
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($name, $value = null)
|
||||
{
|
||||
$_ENV[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear($name)
|
||||
public function delete(string $name)
|
||||
{
|
||||
unset($_ENV[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
85
vendor/vlucas/phpdotenv/src/Repository/Adapter/GuardedWriter.php
vendored
Normal file
85
vendor/vlucas/phpdotenv/src/Repository/Adapter/GuardedWriter.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class GuardedWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The inner writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* The variable name allow list.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $allowList;
|
||||
|
||||
/**
|
||||
* Create a new guarded writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
* @param string[] $allowList
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(WriterInterface $writer, array $allowList)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->allowList = $allowList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
// Don't set non-allowed variables
|
||||
if (!$this->isAllowed($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the value on the inner writer
|
||||
return $this->writer->write($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
// Don't clear non-allowed variables
|
||||
if (!$this->isAllowed($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the value on the inner writer
|
||||
return $this->writer->delete($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given variable is allowed.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isAllowed(string $name)
|
||||
{
|
||||
return \in_array($name, $this->allowList, true);
|
||||
}
|
||||
}
|
||||
110
vendor/vlucas/phpdotenv/src/Repository/Adapter/ImmutableWriter.php
vendored
Normal file
110
vendor/vlucas/phpdotenv/src/Repository/Adapter/ImmutableWriter.php
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class ImmutableWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The inner writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* The inner reader to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* The record of loaded variables.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $loaded;
|
||||
|
||||
/**
|
||||
* Create a new immutable writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface $reader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(WriterInterface $writer, ReaderInterface $reader)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->reader = $reader;
|
||||
$this->loaded = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
// Don't overwrite existing environment variables
|
||||
// Ruby's dotenv does this with `ENV[key] ||= value`
|
||||
if ($this->isExternallyDefined($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the value on the inner writer
|
||||
if (!$this->writer->write($name, $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Record that we have loaded the variable
|
||||
$this->loaded[$name] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
// Don't clear existing environment variables
|
||||
if ($this->isExternallyDefined($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear the value on the inner writer
|
||||
if (!$this->writer->delete($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Leave the variable as fair game
|
||||
unset($this->loaded[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given variable is externally defined.
|
||||
*
|
||||
* That is, is it an "existing" variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isExternallyDefined(string $name)
|
||||
{
|
||||
return $this->reader->read($name)->isDefined() && !isset($this->loaded[$name]);
|
||||
}
|
||||
}
|
||||
48
vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiReader.php
vendored
Normal file
48
vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiReader.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
|
||||
final class MultiReader implements ReaderInterface
|
||||
{
|
||||
/**
|
||||
* The set of readers to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface[]
|
||||
*/
|
||||
private $readers;
|
||||
|
||||
/**
|
||||
* Create a new multi-reader instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface[] $readers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $readers)
|
||||
{
|
||||
$this->readers = $readers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
foreach ($this->readers as $reader) {
|
||||
$result = $reader->read($name);
|
||||
if ($result->isDefined()) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
}
|
||||
64
vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiWriter.php
vendored
Normal file
64
vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiWriter.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class MultiWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The set of writers to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface[]
|
||||
*/
|
||||
private $writers;
|
||||
|
||||
/**
|
||||
* Create a new multi-writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface[] $writers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $writers)
|
||||
{
|
||||
$this->writers = $writers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
foreach ($this->writers as $writers) {
|
||||
if (!$writers->write($name, $value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
foreach ($this->writers as $writers) {
|
||||
if (!$writers->delete($name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
class PutenvAdapter implements AvailabilityInterface, ReaderInterface, WriterInterface
|
||||
final class PutenvAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new putenv adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
if (self::isSupported()) {
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported()
|
||||
private static function isSupported()
|
||||
{
|
||||
return function_exists('getenv') && function_exists('putenv');
|
||||
return \function_exists('getenv') && \function_exists('putenv');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment variable, if it exists.
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string|null>
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function get($name)
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string|null> */
|
||||
return Option::fromValue(getenv($name), false);
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromValue(\getenv($name), false)->filter(static function ($value) {
|
||||
return \is_string($value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string|null $value
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function set($name, $value = null)
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
putenv("$name=$value");
|
||||
\putenv("$name=$value");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function clear($name)
|
||||
public function delete(string $name)
|
||||
{
|
||||
putenv($name);
|
||||
\putenv($name);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface ReaderInterface extends AvailabilityInterface
|
||||
interface ReaderInterface
|
||||
{
|
||||
/**
|
||||
* Get an environment variable, if it exists.
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string|null>
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function get($name);
|
||||
public function read(string $name);
|
||||
}
|
||||
|
||||
104
vendor/vlucas/phpdotenv/src/Repository/Adapter/ReplacingWriter.php
vendored
Normal file
104
vendor/vlucas/phpdotenv/src/Repository/Adapter/ReplacingWriter.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class ReplacingWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The inner writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* The inner reader to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* The record of seen variables.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $seen;
|
||||
|
||||
/**
|
||||
* Create a new replacement writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface $reader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(WriterInterface $writer, ReaderInterface $reader)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->reader = $reader;
|
||||
$this->seen = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
if ($this->exists($name)) {
|
||||
return $this->writer->write($name, $value);
|
||||
}
|
||||
|
||||
// succeed if nothing to do
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
if ($this->exists($name)) {
|
||||
return $this->writer->delete($name);
|
||||
}
|
||||
|
||||
// succeed if nothing to do
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given environment variable exist.
|
||||
*
|
||||
* Returns true if it currently exists, or existed at any point in the past
|
||||
* that we are aware of.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function exists(string $name)
|
||||
{
|
||||
if (isset($this->seen[$name])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->reader->read($name)->isDefined()) {
|
||||
$this->seen[$name] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
class ServerConstAdapter implements AvailabilityInterface, ReaderInterface, WriterInterface
|
||||
final class ServerConstAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
* Create a new server const adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromArraysValue($_SERVER, $name)
|
||||
->filter(static function ($value) {
|
||||
return \is_scalar($value);
|
||||
})
|
||||
->map(static function ($value) {
|
||||
if ($value === false) {
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if ($value === true) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidCast */
|
||||
return (string) $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported()
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
$_SERVER[$name] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment variable, if it exists.
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string|null>
|
||||
* @return bool
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!array_key_exists($name, $_SERVER)) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
$value = $_SERVER[$name];
|
||||
|
||||
if (is_scalar($value)) {
|
||||
/** @var \PhpOption\Option<string|null> */
|
||||
return Some::create((string) $value);
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
/** @var \PhpOption\Option<string|null> */
|
||||
return Some::create(null);
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($name, $value = null)
|
||||
{
|
||||
$_SERVER[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear($name)
|
||||
public function delete(string $name)
|
||||
{
|
||||
unset($_SERVER[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface WriterInterface extends AvailabilityInterface
|
||||
interface WriterInterface
|
||||
{
|
||||
/**
|
||||
* Set an environment variable.
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string|null $value
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function set($name, $value = null);
|
||||
public function write(string $name, string $value);
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function clear($name);
|
||||
public function delete(string $name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user