diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 59c77e6..fd40fa3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,13 +4,10 @@
-
+
-
-
-
@@ -25,59 +22,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Dusan\\DotEnv\\
@@ -93,26 +37,6 @@
-
-
-
@@ -159,56 +83,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -235,11 +110,15 @@
-
+
+
+
+
+
@@ -248,20 +127,17 @@
-
-
-
-
-
+
+
+
+
-
-
@@ -278,76 +154,24 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -367,118 +191,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.phpunit.result.cache b/.phpunit.result.cache
index 194ed6d..7a62be0 100644
--- a/.phpunit.result.cache
+++ b/.phpunit.result.cache
@@ -1 +1 @@
-C:37:"PHPUnit\Runner\DefaultTestResultCache":616:{a:2:{s:7:"defects";a:4:{s:49:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_parser";i:3;s:53:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_with_error";i:4;s:76:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_with_space_error_in_variable_name";i:4;s:52:"BrosSquad\DotEnv\Tests\EnvParserTest::test_interpolation";i:3;}s:5:"times";a:4:{s:49:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_parser";d:0.026;s:53:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_with_error";d:0.003;s:76:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_with_space_error_in_variable_name";d:0.002;s:52:"BrosSquad\DotEnv\Tests\EnvParserTest::test_interpolation";d:0.003;}}}
+C:37:"PHPUnit\Runner\DefaultTestResultCache":414:{a:2:{s:7:"defects";a:1:{s:56:"BrosSquad\DotEnv\Tests\EnvParserTest::test_interpolation";i:3;}s:5:"times";a:4:{s:53:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_parser";d:0.003;s:57:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_with_error";d:0.001;s:80:"BrosSquad\DotEnv\Tests\EnvParserTest::test_env_with_space_error_in_variable_name";d:0;s:56:"BrosSquad\DotEnv\Tests\EnvParserTest::test_interpolation";d:0;}}}
\ No newline at end of file
diff --git a/composer.lock b/composer.lock
index b225010..e37b6ae 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "662b3420a4e09ca28e1af5cb1d910496",
+ "content-hash": "f290d9afcfa09ead4fbd10fc589aadc7",
"packages": [
{
"name": "dusan/php-mvc-file",
@@ -291,16 +291,16 @@
},
{
"name": "myclabs/deep-copy",
- "version": "1.9.1",
+ "version": "1.9.3",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72"
+ "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72",
- "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea",
+ "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea",
"shasum": ""
},
"require": {
@@ -335,7 +335,7 @@
"object",
"object graph"
],
- "time": "2019-04-07T13:18:21+00:00"
+ "time": "2019-08-09T12:45:53+00:00"
},
{
"name": "phar-io/manifest",
@@ -441,35 +441,33 @@
},
{
"name": "phpdocumentor/reflection-common",
- "version": "1.0.1",
+ "version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
- "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6"
+ "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6",
- "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a",
+ "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a",
"shasum": ""
},
"require": {
- "php": ">=5.5"
+ "php": ">=7.1"
},
"require-dev": {
- "phpunit/phpunit": "^4.6"
+ "phpunit/phpunit": "~6"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "2.x-dev"
}
},
"autoload": {
"psr-4": {
- "phpDocumentor\\Reflection\\": [
- "src"
- ]
+ "phpDocumentor\\Reflection\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -491,30 +489,30 @@
"reflection",
"static analysis"
],
- "time": "2017-09-11T18:02:19+00:00"
+ "time": "2018-08-07T13:53:10+00:00"
},
{
"name": "phpdocumentor/reflection-docblock",
- "version": "4.3.1",
+ "version": "4.3.2",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
- "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c"
+ "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c",
- "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e",
+ "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e",
"shasum": ""
},
"require": {
"php": "^7.0",
- "phpdocumentor/reflection-common": "^1.0.0",
- "phpdocumentor/type-resolver": "^0.4.0",
+ "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0",
+ "phpdocumentor/type-resolver": "~0.4 || ^1.0.0",
"webmozart/assert": "^1.0"
},
"require-dev": {
- "doctrine/instantiator": "~1.0.5",
+ "doctrine/instantiator": "^1.0.5",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.4"
},
@@ -542,41 +540,40 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
- "time": "2019-04-30T17:48:53+00:00"
+ "time": "2019-09-12T14:27:41+00:00"
},
{
"name": "phpdocumentor/type-resolver",
- "version": "0.4.0",
+ "version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
- "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7"
+ "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7",
- "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7",
+ "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9",
+ "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9",
"shasum": ""
},
"require": {
- "php": "^5.5 || ^7.0",
- "phpdocumentor/reflection-common": "^1.0"
+ "php": "^7.1",
+ "phpdocumentor/reflection-common": "^2.0"
},
"require-dev": {
- "mockery/mockery": "^0.9.4",
- "phpunit/phpunit": "^5.2||^4.8.24"
+ "ext-tokenizer": "^7.1",
+ "mockery/mockery": "~1",
+ "phpunit/phpunit": "^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
- "phpDocumentor\\Reflection\\": [
- "src/"
- ]
+ "phpDocumentor\\Reflection\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -589,26 +586,27 @@
"email": "me@mikevanriel.com"
}
],
- "time": "2017-07-14T14:27:02+00:00"
+ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
+ "time": "2019-08-22T18:11:29+00:00"
},
{
"name": "phpspec/prophecy",
- "version": "1.8.1",
+ "version": "1.9.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
- "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76"
+ "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76",
- "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76",
+ "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203",
+ "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0",
- "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0",
+ "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0",
"sebastian/comparator": "^1.1|^2.0|^3.0",
"sebastian/recursion-context": "^1.0|^2.0|^3.0"
},
@@ -652,20 +650,20 @@
"spy",
"stub"
],
- "time": "2019-06-13T12:50:23+00:00"
+ "time": "2019-10-03T11:07:50+00:00"
},
{
"name": "phpunit/php-code-coverage",
- "version": "7.0.6",
+ "version": "7.0.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315"
+ "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d471d0d2b529a67c6a722dd446c4ec90881ac315",
- "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f",
+ "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f",
"shasum": ""
},
"require": {
@@ -674,7 +672,7 @@
"php": "^7.2",
"phpunit/php-file-iterator": "^2.0.2",
"phpunit/php-text-template": "^1.2.1",
- "phpunit/php-token-stream": "^3.0.2",
+ "phpunit/php-token-stream": "^3.1.1",
"sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^4.2.2",
"sebastian/version": "^2.0.1",
@@ -715,7 +713,7 @@
"testing",
"xunit"
],
- "time": "2019-07-08T05:29:42+00:00"
+ "time": "2019-09-17T06:24:36+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -859,16 +857,16 @@
},
{
"name": "phpunit/php-token-stream",
- "version": "3.0.2",
+ "version": "3.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
- "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c"
+ "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c",
- "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff",
+ "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff",
"shasum": ""
},
"require": {
@@ -881,7 +879,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-master": "3.1-dev"
}
},
"autoload": {
@@ -904,20 +902,20 @@
"keywords": [
"tokenizer"
],
- "time": "2019-07-08T05:24:54+00:00"
+ "time": "2019-09-17T06:23:10+00:00"
},
{
"name": "phpunit/phpunit",
- "version": "8.2.4",
+ "version": "8.4.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "25fe0b5031b24722f66a75ad479a074cccc1bb37"
+ "reference": "366a4a0f2b971fd43b7c351d621e8dd7d7131869"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/25fe0b5031b24722f66a75ad479a074cccc1bb37",
- "reference": "25fe0b5031b24722f66a75ad479a074cccc1bb37",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/366a4a0f2b971fd43b7c351d621e8dd7d7131869",
+ "reference": "366a4a0f2b971fd43b7c351d621e8dd7d7131869",
"shasum": ""
},
"require": {
@@ -933,14 +931,14 @@
"phar-io/version": "^2.0.1",
"php": "^7.2",
"phpspec/prophecy": "^1.8.1",
- "phpunit/php-code-coverage": "^7.0.5",
+ "phpunit/php-code-coverage": "^7.0.7",
"phpunit/php-file-iterator": "^2.0.2",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-timer": "^2.1.2",
"sebastian/comparator": "^3.0.2",
"sebastian/diff": "^3.0.2",
"sebastian/environment": "^4.2.2",
- "sebastian/exporter": "^3.1.0",
+ "sebastian/exporter": "^3.1.1",
"sebastian/global-state": "^3.0.0",
"sebastian/object-enumerator": "^3.0.3",
"sebastian/resource-operations": "^2.0.1",
@@ -961,7 +959,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "8.2-dev"
+ "dev-master": "8.4-dev"
}
},
"autoload": {
@@ -987,7 +985,7 @@
"testing",
"xunit"
],
- "time": "2019-07-03T08:30:33+00:00"
+ "time": "2019-10-07T12:57:41+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
@@ -1209,16 +1207,16 @@
},
{
"name": "sebastian/exporter",
- "version": "3.1.0",
+ "version": "3.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "234199f4528de6d12aaa58b612e98f7d36adb937"
+ "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937",
- "reference": "234199f4528de6d12aaa58b612e98f7d36adb937",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e",
+ "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e",
"shasum": ""
},
"require": {
@@ -1245,6 +1243,10 @@
"BSD-3-Clause"
],
"authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ },
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
@@ -1253,17 +1255,13 @@
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
- {
- "name": "Bernhard Schussek",
- "email": "bschussek@2bepublished.at"
- },
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- },
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
+ },
+ {
+ "name": "Bernhard Schussek",
+ "email": "bschussek@gmail.com"
}
],
"description": "Provides the functionality to export PHP variables for visualization",
@@ -1272,7 +1270,7 @@
"export",
"exporter"
],
- "time": "2017-04-03T13:19:02+00:00"
+ "time": "2019-09-14T09:02:43+00:00"
},
{
"name": "sebastian/global-state",
@@ -1606,16 +1604,16 @@
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.11.0",
+ "version": "v1.12.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
- "reference": "82ebae02209c21113908c229e9883c419720738a"
+ "reference": "550ebaac289296ce228a706d0867afc34687e3f4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a",
- "reference": "82ebae02209c21113908c229e9883c419720738a",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4",
+ "reference": "550ebaac289296ce228a706d0867afc34687e3f4",
"shasum": ""
},
"require": {
@@ -1627,7 +1625,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.11-dev"
+ "dev-master": "1.12-dev"
}
},
"autoload": {
@@ -1643,13 +1641,13 @@
"MIT"
],
"authors": [
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- },
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for ctype functions",
@@ -1660,20 +1658,20 @@
"polyfill",
"portable"
],
- "time": "2019-02-06T07:57:58+00:00"
+ "time": "2019-08-06T08:03:45+00:00"
},
{
"name": "symfony/yaml",
- "version": "v4.3.2",
+ "version": "v4.3.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
- "reference": "c60ecf5ba842324433b46f58dc7afc4487dbab99"
+ "reference": "41e16350a2a1c7383c4735aa2f9fce74cf3d1178"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/c60ecf5ba842324433b46f58dc7afc4487dbab99",
- "reference": "c60ecf5ba842324433b46f58dc7afc4487dbab99",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/41e16350a2a1c7383c4735aa2f9fce74cf3d1178",
+ "reference": "41e16350a2a1c7383c4735aa2f9fce74cf3d1178",
"shasum": ""
},
"require": {
@@ -1719,7 +1717,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
- "time": "2019-04-06T14:04:46+00:00"
+ "time": "2019-09-11T15:41:19+00:00"
},
{
"name": "theseer/tokenizer",
@@ -1763,16 +1761,16 @@
},
{
"name": "webmozart/assert",
- "version": "1.4.0",
+ "version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/assert.git",
- "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9"
+ "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9",
- "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9",
+ "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4",
+ "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4",
"shasum": ""
},
"require": {
@@ -1780,8 +1778,7 @@
"symfony/polyfill-ctype": "^1.8"
},
"require-dev": {
- "phpunit/phpunit": "^4.6",
- "sebastian/version": "^1.0.1"
+ "phpunit/phpunit": "^4.8.36 || ^7.5.13"
},
"type": "library",
"extra": {
@@ -1810,7 +1807,7 @@
"check",
"validate"
],
- "time": "2018-12-25T11:19:39+00:00"
+ "time": "2019-08-24T08:43:50+00:00"
}
],
"aliases": [],
@@ -1818,6 +1815,8 @@
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
- "platform": [],
+ "platform": {
+ "ext-mbstring": "*"
+ },
"platform-dev": []
}
diff --git a/src/EnvParser.php b/src/EnvParser.php
index 6a63922..fcb8337 100644
--- a/src/EnvParser.php
+++ b/src/EnvParser.php
@@ -9,6 +9,7 @@
use BrosSquad\DotEnv\Exceptions\EnvVariableNotFound;
use Dusan\PhpMvc\File\File;
use Exception;
+use RuntimeException;
class EnvParser implements Tokens, EnvParserInterface
{
@@ -40,19 +41,19 @@ class EnvParser implements Tokens, EnvParserInterface
*
* @param string $file
*
- * @throws \Exception
+ * @throws Exception
*/
public function __construct(string $file)
{
$this->handler = new File($file);
if ($this->handler === NULL) {
- throw new Exception('File could not be opened');
+ throw new RuntimeException('File could not be opened');
}
if (!$this->handler->isFile()) {
- throw new Exception($file . ' is not a file');
+ throw new RuntimeException($file . ' is not a file');
}
if (!$this->handler->isReadable()) {
- throw new Exception($file . ' is not readable');
+ throw new RuntimeException($file . ' is not readable');
}
}
@@ -65,7 +66,7 @@ public function __construct(string $file)
* @return void
* @throws DotEnvSyntaxError
* @throws EnvVariableNotFound
- * @throws \Exception
+ * @throws Exception
*/
public function parse(bool $raw = false): void
{
@@ -76,8 +77,14 @@ public function parse(bool $raw = false): void
while (($c = $this->handler->fgetc()) !== false) {
$column = 0;
// Handling Comments, Empty lines and leading spaces
- if ($c === self::COMMENT) while (($c = $this->handler->fgetc()) !== self::NEW_LINE) continue;
- if ($c === self::NEW_LINE || $c === self::CARRIAGE_RETURN || $c === self::SPACE) continue;
+ if ($c === self::COMMENT) {
+ while (($c = $this->handler->fgetc()) !== self::NEW_LINE) {
+ continue;
+ }
+ }
+ if ($c === self::NEW_LINE || $c === self::CARRIAGE_RETURN || $c === self::SPACE) {
+ continue;
+ }
$envs[$this->extractName($c, $column)] = $this->extractValue($envs, $raw, $column);
}
@@ -88,10 +95,10 @@ public function parse(bool $raw = false): void
/**
* @param string $startingChar
- * @param int $column
+ * @param int $column
*
* @return string
- * @throws \BrosSquad\DotEnv\Exceptions\DotEnvSyntaxError
+ * @throws DotEnvSyntaxError
*/
private function extractName(string $startingChar, int & $column): string
{
@@ -126,11 +133,11 @@ private function extractName(string $startingChar, int & $column): string
* Parses the individual value from the .env file
*
* @param array $envs
- * @param bool $raw
- * @param int $column
+ * @param bool $raw
+ * @param int $column
*
* @return string
- * @throws \BrosSquad\DotEnv\Exceptions\EnvVariableNotFound
+ * @throws EnvVariableNotFound
*/
private function extractValue(array $envs, bool $raw, int & $column): string
{
@@ -147,7 +154,7 @@ private function extractValue(array $envs, bool $raw, int & $column): string
$this->handler->fseek($this->handler->ftell() + 1);
while (($c = $this->handler->fgetc()) !== false && $c !== self::MULTI_LINE_STOP) {
// Handle the interpolation
- if ($c === self::INTERPOLATION_INDICATOR && ($c = $this->handler->fgetc()) === self::INTERPOLATION_START && !$raw) {
+ if (!$raw && $c === self::INTERPOLATION_INDICATOR && ($c = $this->handler->fgetc()) === self::INTERPOLATION_START) {
$value .= $this->interpolation($envs);
} else {
$value .= $c;
@@ -158,19 +165,26 @@ private function extractValue(array $envs, bool $raw, int & $column): string
}
// Handling Single line values
while (($c = $this->handler->fgetc()) !== false) {
- if ($c === self::CARRIAGE_RETURN) break;
- if ($c === self::NEW_LINE) break;
+ if ($c === self::CARRIAGE_RETURN) {
+ break;
+ }
+ if ($c === self::NEW_LINE) {
+ break;
+ }
// Every space character will be ignored
- if ($c === self::SPACE) break;
+ if ($c === self::SPACE) {
+ break;
+ }
// If comment is found at the end of value it will be ignored
- if ($c === self::COMMENT)
+ if ($c === self::COMMENT) {
// Just moving the file pointer to the or \n
while (($c = $this->handler->fgetc()) !== false && $c !== self::NEW_LINE) {
$column++;
continue;
}
- else
+ } else {
$value .= $c;
+ }
$column++;
}
return $value;
@@ -180,7 +194,7 @@ private function extractValue(array $envs, bool $raw, int & $column): string
* @param array $envs
*
* @return mixed
- * @throws \BrosSquad\DotEnv\Exceptions\EnvVariableNotFound
+ * @throws EnvVariableNotFound
*/
private function interpolation(array $envs)
{
@@ -198,7 +212,7 @@ private function interpolation(array $envs)
* Loads ENVs into $_ENV Super global variable
*
* @return void
- * @throws \BrosSquad\DotEnv\Exceptions\EnvNotParsed
+ * @throws EnvNotParsed
*/
public function loadIntoENV(): void
{
@@ -216,7 +230,7 @@ public function loadIntoENV(): void
*
* @inheritDoc
* @return void
- * @throws \BrosSquad\DotEnv\Exceptions\EnvNotParsed
+ * @throws EnvNotParsed
*/
public function loadUsingPutEnv(): void
{
@@ -239,4 +253,26 @@ public function __destruct()
unset($this->handler);
$this->handler = NULL;
}
+
+ /**
+ * @param string $envName
+ * @param string $value
+ * @param bool $shouldQuote
+ * @return int
+ * @throws DotEnvSyntaxError
+ * @throws EnvVariableNotFound
+ */
+ public function write(string $envName, string $value, bool $shouldQuote = false): int
+ {
+ if(!$this->isParsed) {
+ $this->parse();
+ }
+ if($shouldQuote === true) {
+ $value = '"' . $value . '"';
+ }
+
+ $this->envs[$envName] = $value;
+
+ return $this->handler->writeArray($this->envs);
+ }
}
diff --git a/src/EnvParserInterface.php b/src/EnvParserInterface.php
index 1e4f9d2..851427e 100644
--- a/src/EnvParserInterface.php
+++ b/src/EnvParserInterface.php
@@ -5,6 +5,9 @@
namespace BrosSquad\DotEnv;
+use BrosSquad\DotEnv\Exceptions\DotEnvSyntaxError;
+use BrosSquad\DotEnv\Exceptions\EnvVariableNotFound;
+
interface EnvParserInterface
{
/**
@@ -32,4 +35,14 @@ public function getEnvs(): array;
* @return void
*/
public function loadUsingPutEnv(): void;
+
+ /**
+ * @param string $envName
+ * @param string $value
+ * @param bool $shouldQuote
+ * @return int
+ * @throws DotEnvSyntaxError
+ * @throws EnvVariableNotFound
+ */
+ public function write(string $envName, string $value, bool $shouldQuote = false): int;
}
diff --git a/src/Exceptions/DotEnvSyntaxError.php b/src/Exceptions/DotEnvSyntaxError.php
index 9ea7511..475472b 100644
--- a/src/Exceptions/DotEnvSyntaxError.php
+++ b/src/Exceptions/DotEnvSyntaxError.php
@@ -15,7 +15,7 @@ class DotEnvSyntaxError extends Exception
/** @var integer */
private $column;
- public function __construct($message = "Check your syntax in .env file", $code = 0, Throwable $previous = NULL)
+ public function __construct($message = 'Check your syntax in .env file', $code = 0, Throwable $previous = NULL)
{
parent::__construct($message, $code, $previous);
}
diff --git a/tests/EnvTest/EnvParserTest.php b/tests/EnvTest/EnvParserTest.php
index 52a8b63..48d1875 100644
--- a/tests/EnvTest/EnvParserTest.php
+++ b/tests/EnvTest/EnvParserTest.php
@@ -6,12 +6,14 @@
use BrosSquad\DotEnv\Exceptions\DotEnvSyntaxError;
use BrosSquad\DotEnv\EnvParser;
+use BrosSquad\DotEnv\Exceptions\EnvVariableNotFound;
use Exception;
use PHPUnit\Framework\TestCase;
class EnvParserTest extends TestCase
{
- public function test_env_parser()
+
+ public function test_env_parser(): void
{
try {
@@ -33,27 +35,37 @@ public function test_env_parser()
is multi line
', $array['MULTI_LINE']);
} catch (DotEnvSyntaxError $e) {
- $this->fail(sprintf("%s %d %d", $e->getMessage(), $e->getEnvLine(), $e->getColumn()));
+ $this->fail(sprintf('%s %d %d', $e->getMessage(), $e->getEnvLine(), $e->getColumn()));
} catch (Exception $e) {
$this->fail($e->getMessage());
}
}
- public function test_env_with_error()
+ /**
+ * @throws DotEnvSyntaxError
+ * @throws EnvVariableNotFound
+ * @throws Exception
+ */
+ public function test_env_with_error(): void
{
$this->expectException(DotEnvSyntaxError::class);
$parser = new EnvParser(__DIR__ . '/.env-error');
$parser->parse();
}
- public function test_env_with_space_error_in_variable_name()
+ /**
+ * @throws DotEnvSyntaxError
+ * @throws EnvVariableNotFound
+ * @throws Exception
+ */
+ public function test_env_with_space_error_in_variable_name(): void
{
$this->expectException(DotEnvSyntaxError::class);
$parser = new EnvParser(__DIR__ . '/.env-error');
$parser->parse();
}
- public function test_interpolation()
+ public function test_interpolation(): void
{
$expected = 'Test is Interpolated';
try {