Download the PHP package 24hoursmedia/php-env-inject without Composer
On this page you can find all versions of the php package 24hoursmedia/php-env-inject. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 24hoursmedia/php-env-inject
More information about 24hoursmedia/php-env-inject
Files in 24hoursmedia/php-env-inject
Package php-env-inject
Short Description Inject and interpolate environment variables into strings. Supports substituting default values of env variables, and escapers/formatters using callbacks.
License Apache-2.0
Informations about the package php-env-inject
EnvInject
Inject/interpolate environment variables in strings.
- Substitutes raw environment variables in strings
- Supports default values if environment variable is not set
- Supports escaping JSON strings
- Supports a callback to write your own value modifiers / escapers
Security Considerations
:warning: As often environment variables on a system may contain sensitive data, especially if you use dotenv, you should NEVER ALLOW USER INPUT into the interpolator.
:warning: Only interpolate into strings that are under your control and fully trusted!
Install
Usage
Interpolate env vars in a string
Interpolation in JSON strings
Escape json values with JsonEnvInject::interpolate()
:
Substituting raw environment variables in JSON strings can result in failures if you have special characters in your values such as quotes. The JsonEnvInject class can escape JSON strings for you before interpolation.
Modify values with a callback function
Use EnvInject::interpolateWithCallback(string $string, Closure $callback)
to
modify values with a callback function.
The callback function receives the value as first argument and the key as second argument. It should return the modified value to interpolate.
Use this to create your own escape functions or more complex modifiers.
Develop and run tests
Open project in a docker container:
docker run -it --rm -v $(pwd):/app -w /app php:8.0-cli-alpine /bin/sh
apk add php-curl php-mbstring php-openssl php-zip php-phar
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
composer install
# run tests
./vendor/bin/phpunit tests --testdox