Senior Software Engineer based in London, UK. Currently @ Arabesque Asset Management.
Mainly writing Go but also doing a huge mix of Python, Java, PHP and Rust.
Env is a lightweight library bringing .env file parser compatibility to PHP. In short - it enables you to read .env files with PHP.
License: MIT License
Senior Software Engineer based in London, UK. Currently @ Arabesque Asset Management.
Mainly writing Go but also doing a huge mix of Python, Java, PHP and Rust.
We should have a strict parsing mode for .env files, specifically around general variable assignment.
Ran into an interesting issue today whereby one specific environment would crash during dotenv parsing. I tracked it down to a specific line and eventually realized that one of the auto-generated salts in the .env had created a string containing ${
and }
. Thus, the parser would crash as the gibberish in between the braces obviously matched no variable name.
The salt was single-quoted however, so this behavior is rather unexpected as it matches neither Bash nor PHP's parsing rules. I also noticed that despite the README having such a wide variety of examples, this edge-case is missing. Any parsing or expansion of variables should probably be disabled within single quote strings.
Below string can't be parsed
export mykey="aaaaaaaa\""
$ cat /tmp/test.env
TEST="namespace\\class"
$ source /tmp/test.env && echo $TEST
namespace\class
$ php -r 'require_once "vendor/autoload.php"; echo M1\Env\Parser::parse(file_get_contents("/tmp/test.env"))["TEST"].PHP_EOL;'
namespace\\class
expected: namespace\class
Hi! Thanks for the decent library!
I have a use case where I need to fetch variables from outer context, e.g. I have an external source which yields a FOO_SECRET=secret
and later my .env
refers to it, e.g.
FOO_CREDENTIALS=${FOO_USER}:${FOO_SECRET}
Currently, a lot of methods defined as private, which prevents reuse and extension. So I'm facing with two probable cases: weaken visibility from private to protected or pass array $context = []
down to VariableParser
and use it in fetchVariable()
when both hasParameterExpansion()
and checkVariableExists()
fails.
Alternatively, I would do both at once: weaken visibility and add $context
.
Do you have any suggestions on topic?
It'd be nice if you could use more than 1 space and/or tabs before comments inline so that comments could be aligned in a long config file
Reported to josegonzalez/php-dotenv#42 accidentally.
I had a file that worked with other .env parsers but failed with m1/env
The issue was a blank line containing only space characters. I agree that it's not a good style but it shouldn't break the parser.
Would be appreciated :)
This would be super useful for things like auto-generated configuration files written in .env (which is what I'm currently attempting to use)
Is there any chance on changing the visibility of the doParse
method in the Parser
class from private
to maybe just protected
?
This would allow for a class extending the Parser
to do fun things like set the value_parser
property to something else and make the call to re-parse the configuration file.
I'm happy to make a PR for it too if that'd help...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.