3
vendor/vlucas/phpdotenv/.gitignore
vendored
3
vendor/vlucas/phpdotenv/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
composer.phar
|
||||
composer.lock
|
||||
vendor
|
14
vendor/vlucas/phpdotenv/.travis.yml
vendored
14
vendor/vlucas/phpdotenv/.travis.yml
vendored
@@ -1,14 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit
|
32
vendor/vlucas/phpdotenv/LICENSE.txt
vendored
32
vendor/vlucas/phpdotenv/LICENSE.txt
vendored
@@ -1,32 +0,0 @@
|
||||
The BSD 3-Clause License
|
||||
http://opensource.org/licenses/BSD-3-Clause
|
||||
|
||||
Copyright (c) 2013, Vance Lucas
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Vance Lucas nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
199
vendor/vlucas/phpdotenv/README.md
vendored
199
vendor/vlucas/phpdotenv/README.md
vendored
@@ -1,199 +0,0 @@
|
||||
PHP dotenv
|
||||
==========
|
||||
|
||||
Loads environment variables from `.env` to `getenv()`, `$_ENV` and
|
||||
`$_SERVER` automagically.
|
||||
|
||||
This is a PHP version of the original [Ruby
|
||||
dotenv](https://github.com/bkeepers/dotenv).
|
||||
|
||||
[](http://travis-ci.org/vlucas/phpdotenv)
|
||||
|
||||
Why .env?
|
||||
---------
|
||||
**You should never store sensitive credentials in your code**. Storing
|
||||
[configuration in the environment](http://www.12factor.net/config) is one of
|
||||
the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is
|
||||
likely to change between deployment environments – such as database credentials
|
||||
or credentials for 3rd party services – should be extracted from the
|
||||
code into environment variables.
|
||||
|
||||
Basically, a `.env` file is an easy way to load custom configuration
|
||||
variables that your application needs without having to modify .htaccess
|
||||
files or Apache/nginx virtual hosts. This means you won't have to edit
|
||||
any files outside the project, and all the environment variables are
|
||||
always set no matter how you run your project - Apache, Nginx, CLI, and
|
||||
even PHP 5.4's built-in webserver. It's WAY easier than all the other
|
||||
ways you know of to set environment variables, and you're going to love
|
||||
it.
|
||||
|
||||
* NO editing virtual hosts in Apache or Nginx
|
||||
* NO adding `php_value` flags to .htaccess files
|
||||
* EASY portability and sharing of required ENV values
|
||||
* COMPATIBLE with PHP's built-in web server and CLI runner
|
||||
|
||||
|
||||
Installation with Composer
|
||||
--------------------------
|
||||
|
||||
```shell
|
||||
curl -s http://getcomposer.org/installer | php
|
||||
php composer.phar require vlucas/phpdotenv
|
||||
```
|
||||
|
||||
Usage
|
||||
-----
|
||||
The `.env` file is generally kept out of version control since it can contain
|
||||
sensitive API keys and passwords. A separate `.env.example` file is created
|
||||
with all the required environment variables defined except for the sensitive
|
||||
ones, which are either user-supplied for their own development environments or
|
||||
are communicated elsewhere to project collaborators. The project collaborators
|
||||
then independently copy the `.env.example` file to a local `.env` and ensure
|
||||
all the settings are correct for their local environment, filling in the secret
|
||||
keys or providing their own values when necessary. In this usage, the `.env`
|
||||
file should be added to the project's `.gitignore` file so that it will never
|
||||
be committed by collaborators. This usage ensures that no sensitive passwords
|
||||
or API keys will ever be in the version control history so there is less risk
|
||||
of a security breach, and production values will never have to be shared with
|
||||
all project collaborators.
|
||||
|
||||
Add your application configuration to a `.env` file in the root of your
|
||||
project. **Make sure the `.env` file is added to your `.gitignore` so it is not
|
||||
checked-in the code**
|
||||
|
||||
```shell
|
||||
S3_BUCKET=dotenv
|
||||
SECRET_KEY=souper_seekret_key
|
||||
```
|
||||
|
||||
Now create a file named `.env.example` and check this into the project. This
|
||||
should have the ENV variables you need to have set, but the values should
|
||||
either be blank or filled with dummy data. The idea is to let people know what
|
||||
variables are required, but not give them the sensitive production values.
|
||||
|
||||
```shell
|
||||
S3_BUCKET=devbucket
|
||||
SECRET_KEY=abc123
|
||||
```
|
||||
|
||||
You can then load `.env` in your application with a single line:
|
||||
```php
|
||||
Dotenv::load(__DIR__);
|
||||
```
|
||||
|
||||
All of the defined variables are now accessible with the `getenv`
|
||||
method, and are available in the `$_ENV` and `$_SERVER` super-globals.
|
||||
```php
|
||||
$s3_bucket = getenv('S3_BUCKET');
|
||||
$s3_bucket = $_ENV['S3_BUCKET'];
|
||||
$s3_bucket = $_SERVER['S3_BUCKET'];
|
||||
```
|
||||
|
||||
You should also be able to access them using your framework's Request
|
||||
class (if you are using a framework).
|
||||
```php
|
||||
$s3_bucket = $request->env('S3_BUCKET');
|
||||
$s3_bucket = $request->getEnv('S3_BUCKET');
|
||||
$s3_bucket = $request->server->get('S3_BUCKET');
|
||||
```
|
||||
|
||||
### Nesting Variables
|
||||
|
||||
It's possible to nest an environment variable within another, useful to cut down on repetition.
|
||||
|
||||
This is done by wrapping an existing environment variable in `{$…}` e.g.
|
||||
|
||||
```shell
|
||||
BASE_DIR=/var/webroot/project-root
|
||||
CACHE_DIR={$BASE_DIR}/cache
|
||||
TMP_DIR={$BASE_DIR}/tmp
|
||||
```
|
||||
|
||||
### Immutability
|
||||
|
||||
By default, Dotenv treats environment variables as immutable, that is… once set they cannot be changed.
|
||||
|
||||
You can make Dotenv mutable using
|
||||
|
||||
```php
|
||||
Dotenv::makeMutable();
|
||||
```
|
||||
|
||||
… and you can make Dotenv immutable again using
|
||||
|
||||
```php
|
||||
Dotenv::makeImmutable();
|
||||
```
|
||||
|
||||
Requiring Variables to be Set
|
||||
-----------------------------
|
||||
|
||||
Using Dotenv, you can require specific ENV vars to be defined, and throw
|
||||
an Exception if they are not. This is particularly useful to let people know
|
||||
any explicit required variables that your app will not work without.
|
||||
|
||||
You can use a single string:
|
||||
```php
|
||||
Dotenv::required('DATABASE_DSN');
|
||||
```
|
||||
|
||||
Or an array of strings:
|
||||
```php
|
||||
Dotenv::required(array('DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS'));
|
||||
```
|
||||
|
||||
If any ENV vars are missing, Dotenv will throw a `RuntimeException` like this:
|
||||
```
|
||||
Required environment variable missing or value not allowed: 'DB_USER', 'DB_PASS'
|
||||
```
|
||||
|
||||
### Allowed values
|
||||
|
||||
As you may have noticed from the Exception message above, it's also possible to define a set of values that your
|
||||
environment variable should adhere to.
|
||||
|
||||
```php
|
||||
Dotenv::required('SESSION_STORE', array('Filesystem', 'Memcached'));
|
||||
```
|
||||
|
||||
Again, if the environment variable wasn't in this list, you'd get a similar Exception:
|
||||
```
|
||||
Required environment variable missing or value not allowed: 'SESSION_STORE'
|
||||
```
|
||||
|
||||
### Comments
|
||||
|
||||
You can comment your `.env` file using the `#` character. E.g.
|
||||
|
||||
```shell
|
||||
# this is a comment
|
||||
VAR="value" # comment
|
||||
VAR=value # comment
|
||||
```
|
||||
|
||||
Usage Notes
|
||||
-----------
|
||||
|
||||
When a new developer clones your codebase, they will have an additional
|
||||
**one-time step** to manually copy the `.env.example` file to `.env` and fill-in
|
||||
their own values (or get any sensitive values from a project co-worker).
|
||||
|
||||
phpdotenv is made for development environments, and generally should not be
|
||||
used in production. In production, the actual environment variables should be
|
||||
set so that there is no overhead of loading the `.env` file on each request.
|
||||
This can be achieved via an automated deployment process with tools like
|
||||
Vagrant, chef, or Puppet, or can be set manually with cloud hosts like
|
||||
Pagodabox and Heroku.
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
1. Fork it
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Make your changes
|
||||
4. Run the tests, adding new ones for your own code if necessary (`phpunit`)
|
||||
5. Commit your changes (`git commit -am 'Added some feature'`)
|
||||
6. Push to the branch (`git push origin my-new-feature`)
|
||||
7. Create new Pull Request
|
||||
|
31
vendor/vlucas/phpdotenv/composer.json
vendored
31
vendor/vlucas/phpdotenv/composer.json
vendored
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"type": "library",
|
||||
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
|
||||
"keywords": ["env", "dotenv", "environment"],
|
||||
"homepage": "http://github.com/vlucas/phpdotenv",
|
||||
"license" : "BSD",
|
||||
"authors" : [
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "http://www.vancelucas.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Dotenv": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
18
vendor/vlucas/phpdotenv/phpunit.xml
vendored
18
vendor/vlucas/phpdotenv/phpunit.xml
vendored
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="./tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Dotenv Test Suite">
|
||||
<directory suffix=".php">tests/Dotenv</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
261
vendor/vlucas/phpdotenv/src/Dotenv.php
vendored
261
vendor/vlucas/phpdotenv/src/Dotenv.php
vendored
@@ -1,261 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Dotenv
|
||||
*
|
||||
* Loads a `.env` file in the given directory and sets the environment vars
|
||||
*/
|
||||
class Dotenv
|
||||
{
|
||||
/**
|
||||
* If true, then environment variables will not be overwritten
|
||||
* @var bool
|
||||
*/
|
||||
protected static $immutable = true;
|
||||
|
||||
/**
|
||||
* Load `.env` file in given directory
|
||||
*/
|
||||
public static function load($path, $file = '.env')
|
||||
{
|
||||
if (!is_string($file)) {
|
||||
$file = '.env';
|
||||
}
|
||||
|
||||
$filePath = rtrim($path, '/') . '/' . $file;
|
||||
if (!is_readable($filePath) || !is_file($filePath)) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
"Dotenv: Environment file %s not found or not readable. " .
|
||||
"Create file with your environment settings at %s",
|
||||
$file,
|
||||
$filePath
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Read file into an array of lines with auto-detected line endings
|
||||
$autodetect = ini_get('auto_detect_line_endings');
|
||||
ini_set('auto_detect_line_endings', '1');
|
||||
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
ini_set('auto_detect_line_endings', $autodetect);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
// Disregard comments
|
||||
if (strpos(trim($line), '#') === 0) {
|
||||
continue;
|
||||
}
|
||||
// Only use non-empty lines that look like setters
|
||||
if (strpos($line, '=') !== false) {
|
||||
static::setEnvironmentVariable($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a variable using:
|
||||
* - putenv
|
||||
* - $_ENV
|
||||
* - $_SERVER
|
||||
*
|
||||
* The environment variable value is stripped of single and double quotes.
|
||||
*
|
||||
* @param $name
|
||||
* @param null $value
|
||||
*/
|
||||
public static function setEnvironmentVariable($name, $value = null)
|
||||
{
|
||||
list($name, $value) = static::normaliseEnvironmentVariable($name, $value);
|
||||
|
||||
// Don't overwrite existing environment variables if we're immutable
|
||||
// Ruby's dotenv does this with `ENV[key] ||= value`.
|
||||
if (static::$immutable === true && !is_null(static::findEnvironmentVariable($name))) {
|
||||
return;
|
||||
}
|
||||
|
||||
putenv("$name=$value");
|
||||
$_ENV[$name] = $value;
|
||||
$_SERVER[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require specified ENV vars to be present, or throw Exception.
|
||||
* You can also pass through an set of allowed values for the environment variable.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @param mixed $environmentVariables the name of the environment variable or an array of names
|
||||
* @param string[] $allowedValues
|
||||
* @return true (or throws exception on error)
|
||||
*/
|
||||
public static function required($environmentVariables, array $allowedValues = array())
|
||||
{
|
||||
$environmentVariables = (array) $environmentVariables;
|
||||
$missingEnvironmentVariables = array();
|
||||
|
||||
foreach ($environmentVariables as $environmentVariable) {
|
||||
$value = static::findEnvironmentVariable($environmentVariable);
|
||||
if (is_null($value)) {
|
||||
$missingEnvironmentVariables[] = $environmentVariable;
|
||||
} elseif ($allowedValues) {
|
||||
if (!in_array($value, $allowedValues)) {
|
||||
// may differentiate in the future, but for now this does the job
|
||||
$missingEnvironmentVariables[] = $environmentVariable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($missingEnvironmentVariables) {
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
"Required environment variable missing, or value not allowed: '%s'",
|
||||
implode("', '", $missingEnvironmentVariables)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes value as passed in by developer and:
|
||||
* - ensures we're dealing with a separate name and value, breaking apart the name string if needed
|
||||
* - cleaning the value of quotes
|
||||
* - cleaning the name of quotes
|
||||
* - resolving nested variables
|
||||
*
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
protected static function normaliseEnvironmentVariable($name, $value)
|
||||
{
|
||||
list($name, $value) = static::splitCompoundStringIntoParts($name, $value);
|
||||
$name = static::sanitiseVariableName($name);
|
||||
$value = static::sanitiseVariableValue($value);
|
||||
$value = static::resolveNestedVariables($value);
|
||||
|
||||
return array($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the $name contains an = sign, then we split it into 2 parts, a name & value
|
||||
*
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
protected static function splitCompoundStringIntoParts($name, $value)
|
||||
{
|
||||
if (strpos($name, '=') !== false) {
|
||||
list($name, $value) = array_map('trim', explode('=', $name, 2));
|
||||
}
|
||||
|
||||
return array($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips quotes from the environment variable value.
|
||||
*
|
||||
* @param $value
|
||||
* @return string
|
||||
*/
|
||||
protected static function sanitiseVariableValue($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (!$value) return '';
|
||||
if (strpbrk($value[0], '"\'') !== false) { // value starts with a quote
|
||||
$quote = $value[0];
|
||||
$regexPattern = sprintf('/^
|
||||
%1$s # match a quote at the start of the value
|
||||
( # capturing sub-pattern used
|
||||
(?: # we do not need to capture this
|
||||
[^%1$s\\\\] # any character other than a quote or backslash
|
||||
|\\\\\\\\ # or two backslashes together
|
||||
|\\\\%1$s # or an escaped quote e.g \"
|
||||
)* # as many characters that match the previous rules
|
||||
) # end of the capturing sub-pattern
|
||||
%1$s # and the closing quote
|
||||
.*$ # and discard any string after the closing quote
|
||||
/mx', $quote);
|
||||
$value = preg_replace($regexPattern, '$1', $value);
|
||||
$value = str_replace("\\$quote", $quote, $value);
|
||||
$value = str_replace('\\\\', '\\', $value);
|
||||
} else {
|
||||
$parts = explode(' #', $value, 2);
|
||||
$value = $parts[0];
|
||||
}
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips quotes and the optional leading "export " from the environment variable name.
|
||||
*
|
||||
* @param $name
|
||||
* @return string
|
||||
*/
|
||||
protected static function sanitiseVariableName($name)
|
||||
{
|
||||
return trim(str_replace(array('export ', '\'', '"'), '', $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for {$varname} patterns in the variable value and replace with an existing
|
||||
* environment variable.
|
||||
*
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function resolveNestedVariables($value)
|
||||
{
|
||||
if (strpos($value, '$') !== false) {
|
||||
$value = preg_replace_callback(
|
||||
'/{\$([a-zA-Z0-9_]+)}/',
|
||||
function ($matchedPatterns) {
|
||||
$nestedVariable = Dotenv::findEnvironmentVariable($matchedPatterns[1]);
|
||||
if (is_null($nestedVariable)) {
|
||||
return $matchedPatterns[0];
|
||||
} else {
|
||||
return $nestedVariable;
|
||||
}
|
||||
},
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the different places for environment variables and return first value found.
|
||||
* @param $name
|
||||
* @return string
|
||||
*/
|
||||
public static function findEnvironmentVariable($name)
|
||||
{
|
||||
switch (true) {
|
||||
case array_key_exists($name, $_ENV):
|
||||
return $_ENV[$name];
|
||||
case array_key_exists($name, $_SERVER):
|
||||
return $_SERVER[$name];
|
||||
default:
|
||||
$value = getenv($name);
|
||||
|
||||
return $value === false ? null : $value; // switch getenv default to null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make Dotenv immutable. This means that once set, an environment variable cannot be overridden.
|
||||
*/
|
||||
public static function makeImmutable()
|
||||
{
|
||||
static::$immutable = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make Dotenv mutable. Environment variables will act as, well, variables.
|
||||
*/
|
||||
public static function makeMutable()
|
||||
{
|
||||
static::$immutable = false;
|
||||
}
|
||||
}
|
156
vendor/vlucas/phpdotenv/tests/Dotenv/Dotenv.php
vendored
156
vendor/vlucas/phpdotenv/tests/Dotenv/Dotenv.php
vendored
@@ -1,156 +0,0 @@
|
||||
<?php
|
||||
class DotenvTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testDotenvLoadsEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$this->assertEquals('bar', getenv('FOO'));
|
||||
$this->assertEquals('baz', getenv('BAR'));
|
||||
$this->assertEquals('with spaces', getenv('SPACED'));
|
||||
$this->assertEquals('', getenv('NULL'));
|
||||
}
|
||||
|
||||
public function testCommentedDotenvLoadsEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'commented.env');
|
||||
$this->assertEquals('bar', getenv('CFOO'));
|
||||
$this->assertEquals(false, getenv('CBAR'));
|
||||
$this->assertEquals(false, getenv('CZOO'));
|
||||
$this->assertEquals('with spaces', getenv('CSPACED'));
|
||||
$this->assertEquals('a value with a # character', getenv('CQUOTES'));
|
||||
$this->assertEquals('a value with a # character & a quote " character inside quotes', getenv('CQUOTESWITHQUOTE'));
|
||||
$this->assertEquals('', getenv('CNULL'));
|
||||
}
|
||||
|
||||
public function testQuotedDotenvLoadsEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
|
||||
$this->assertEquals('bar', getenv('QFOO'));
|
||||
$this->assertEquals('baz', getenv('QBAR'));
|
||||
$this->assertEquals('with spaces', getenv('QSPACED'));
|
||||
$this->assertEquals('', getenv('QNULL'));
|
||||
$this->assertEquals('pgsql:host=localhost;dbname=test', getenv('QEQUALS'));
|
||||
$this->assertEquals("test some escaped characters like a quote (') or maybe a backslash (\\)", getenv('QESCAPED'));
|
||||
}
|
||||
|
||||
public function testExportedDotenvLoadsEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'exported.env');
|
||||
$this->assertEquals('bar', getenv('EFOO'));
|
||||
$this->assertEquals('baz', getenv('EBAR'));
|
||||
$this->assertEquals('with spaces', getenv('ESPACED'));
|
||||
$this->assertEquals('', getenv('ENULL'));
|
||||
}
|
||||
|
||||
public function testDotenvLoadsEnvGlobals()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$this->assertEquals('bar', $_SERVER['FOO']);
|
||||
$this->assertEquals('baz', $_SERVER['BAR']);
|
||||
$this->assertEquals('with spaces', $_SERVER['SPACED']);
|
||||
$this->assertEquals('', $_SERVER['NULL']);
|
||||
}
|
||||
|
||||
public function testDotenvLoadsServerGlobals()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$this->assertEquals('bar', $_ENV['FOO']);
|
||||
$this->assertEquals('baz', $_ENV['BAR']);
|
||||
$this->assertEquals('with spaces', $_ENV['SPACED']);
|
||||
$this->assertEquals('', $_ENV['NULL']);
|
||||
}
|
||||
|
||||
public function testDotenvRequiredStringEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$res = Dotenv::required('FOO');
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
|
||||
public function testDotenvRequiredArrayEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$res = Dotenv::required(array('FOO', 'BAR'));
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
|
||||
public function testDotenvNestedEnvironmentVars()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'nested.env');
|
||||
$this->assertEquals('Hello World!', $_ENV['NVAR3']);
|
||||
$this->assertEquals('${NVAR1} ${NVAR2}', $_ENV['NVAR4']); // not resolved
|
||||
$this->assertEquals('$NVAR1 {NVAR2}', $_ENV['NVAR5']); // not resolved
|
||||
}
|
||||
|
||||
public function testDotenvAllowedValues()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$res = Dotenv::required('FOO', array('bar', 'baz'));
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
* @expectedExceptionMessage Required environment variable missing, or value not allowed: 'FOO'
|
||||
*/
|
||||
public function testDotenvProhibitedValues()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$res = Dotenv::required('FOO', array('buzz'));
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
* @expectedExceptionMessage Required environment variable missing, or value not allowed: 'FOOX', 'NOPE'
|
||||
*/
|
||||
public function testDotenvRequiredThrowsRuntimeException()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures');
|
||||
$res = Dotenv::required(array('FOOX', 'NOPE'));
|
||||
}
|
||||
|
||||
public function testDotenvNullFileArgumentUsesDefault()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', null);
|
||||
|
||||
$this->assertEquals('bar', getenv('FOO'));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fixture data has whitespace between the key and in the value string
|
||||
* Test that these keys are trimmed down
|
||||
*/
|
||||
public function testDotenvTrimmedKeys()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
|
||||
$this->assertTrue(isset($_ENV['QWHITESPACE']));
|
||||
}
|
||||
|
||||
public function testDotenvDoesNotOverwriteEnvWhenImmutable()
|
||||
{
|
||||
Dotenv::makeMutable(); // only need this because we've previously set the variable
|
||||
Dotenv::setEnvironmentVariable('QFOO=external');
|
||||
Dotenv::makeImmutable();
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
|
||||
$this->assertEquals('external', getenv('QFOO'));
|
||||
}
|
||||
|
||||
public function testDotenvDoesNotOverwriteEnvWhenMutable()
|
||||
{
|
||||
Dotenv::makeMutable();
|
||||
Dotenv::setEnvironmentVariable('QFOO=external');
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
|
||||
$this->assertEquals('bar', getenv('QFOO'));
|
||||
}
|
||||
|
||||
public function testDotenvAllowsSpecialCharacters()
|
||||
{
|
||||
Dotenv::load(dirname(__DIR__) . '/fixtures', 'specialchars.env');
|
||||
$this->assertEquals('$a6^C7k%zs+e^.jvjXk', getenv('SPVAR1'));
|
||||
$this->assertEquals('?BUty3koaV3%GA*hMAwH}B', getenv('SPVAR2'));
|
||||
$this->assertEquals('jdgEB4{QgEC]HL))&GcXxokB+wqoN+j>xkV7K?m$r', getenv('SPVAR3'));
|
||||
$this->assertEquals('22222:22#2^{', getenv('SPVAR4'));
|
||||
$this->assertEquals("test some escaped characters like a quote \\' or maybe a backslash \\\\", getenv('SPVAR5'));
|
||||
}
|
||||
}
|
18
vendor/vlucas/phpdotenv/tests/bootstrap.php
vendored
18
vendor/vlucas/phpdotenv/tests/bootstrap.php
vendored
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
error_reporting(-1);
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
/**
|
||||
* Path trickery ensures test suite will always run, standalone or within
|
||||
* another composer package. Designed to find composer autoloader and require
|
||||
*/
|
||||
$vendorPos = strpos(__DIR__, 'vendor/vlucas/phpdotenv');
|
||||
if($vendorPos !== false) {
|
||||
// Package has been cloned within another composer package, resolve path to autoloader
|
||||
$vendorDir = substr(__DIR__, 0, $vendorPos) . 'vendor/';
|
||||
$loader = require $vendorDir . 'autoload.php';
|
||||
} else {
|
||||
// Package itself (cloned standalone)
|
||||
$loader = require __DIR__.'/../vendor/autoload.php';
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
# This is a comment
|
||||
CFOO=bar
|
||||
#CBAR=baz
|
||||
#CZOO=goo # a comment on a commented row
|
||||
CSPACED=with spaces # this is a comment
|
||||
CQUOTES="a value with a # character" # this is a comment
|
||||
CQUOTESWITHQUOTE="a value with a # character & a quote \" character inside quotes" # " this is a comment
|
||||
|
||||
CNULL=
|
||||
|
||||
## this is a comment ##
|
@@ -1,5 +0,0 @@
|
||||
export EFOO='bar'
|
||||
export EBAR='baz'
|
||||
export ESPACED='with spaces'
|
||||
|
||||
export ENULL=''
|
@@ -1,5 +0,0 @@
|
||||
NVAR1='Hello'
|
||||
NVAR2='World!'
|
||||
NVAR3='{$NVAR1} {$NVAR2}'
|
||||
NVAR4='${NVAR1} ${NVAR2}'
|
||||
NVAR5='$NVAR1 {NVAR2}'
|
@@ -1,9 +0,0 @@
|
||||
QFOO='bar'
|
||||
QBAR='baz'
|
||||
QSPACED='with spaces'
|
||||
QEQUALS='pgsql:host=localhost;dbname=test'
|
||||
|
||||
QNULL=''
|
||||
QWHITESPACE = 'no space'
|
||||
|
||||
QESCAPED='test some escaped characters like a quote (\') or maybe a backslash (\\)'
|
@@ -1,5 +0,0 @@
|
||||
SPVAR1='$a6^C7k%zs+e^.jvjXk'
|
||||
SPVAR2='?BUty3koaV3%GA*hMAwH}B'
|
||||
SPVAR3='jdgEB4{QgEC]HL))&GcXxokB+wqoN+j>xkV7K?m$r'
|
||||
SPVAR4='22222:22#2^{'
|
||||
SPVAR5=test some escaped characters like a quote \' or maybe a backslash \\ # not escaped
|
Reference in New Issue
Block a user