Download the PHP package nixiware/config without Composer
On this page you can find all versions of the php package nixiware/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nixiware/config
More information about nixiware/config
Files in nixiware/config
Package config
Short Description Configuration helper for containerized applications
License MIT
Informations about the package config
Config
Introduction
When running PHP applications using orchestration systems (like Docker Swarm / Kubernetes) a lot of configuration is done using environment variables.
While PHP comes with for reading environmnet variables, a lot of time it proves limited when dealing with secrets (reading values from files) or explicitly casting the values to a certain type.
Requirements
- PHP 5.3
Usage
- Import package namespace
- Import environment variables using the static method
-
- name of the environmnet variable
-
- sets the variable as required / optional for the execution
-
- default value to return if environment variable is not set
-
- explicitly cast the returned value to a type
-
EnvVar will first look for an environment variable with the suffix , and if a file path is specified, it will load the contents of that file.
If a variable is specified as required and no default value is provided, a will be thrown.
Examples
-
Reading a variable named , set as not required with a default value of
-
Reading a variable named , set as required with no default value, and casted as a boolean.
- Reading a variable from a file, named , set as required with no default value.
Path for the file will be specified using the environment variable . The variable with the suffix is automatically read to allow more flexibility in configuring your application, without requiring to modify the actual configuration files.
Testing
Giving the fact that the package is designed to help with Docker / Kubernetes deployments, the unit tests must be ran inside a Docker container.
- Open directory and run to start the container
- Connect to container (similar to SSH) by running
- Run the install script (inside the container)
- Run the tests script (inside the container)
For cleanup simply run after exiting the container.
License
Config is available under the MIT license. See the LICENSE file for more info.