dependencies-upgrade
This commit is contained in:
@@ -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, '');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user