Download the PHP package socarrat/environment without Composer

On this page you can find all versions of the php package socarrat/environment. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package environment

Socarrat\Environment

A super simple .env file parser that is compatible with getenv().

Test

Features

Installation

Download this package on Packagist:

Usage

The API) to load your environment variables.

How about getenv()?

One of the parameters of the parse functions is bool $putenv. If you set this to true (default), putenv() will be called for every parsed variable. If you already use getenv(), there's no need to adapt your program: you only need to call a parse function once at the start.

Examples

See the examples/ directory for some usage examples.

.env file format

The basics

A .env file contains key-value pairs of environment-specific settings. Each line contains a key-value pair. Keys should be capitalised, and should only contain A-Z characters and underscores. Thereafter comes an = sign, and then the value. See the following example:

Quoted values

To avoid confusion, you could enclose the value in double quotes ".

Note that single quotes ' are NOT stripped from the value! For example, the value of DB_TABLE='users' is 'users' and not users.

Multi-line values

Multi-line values are supported, provided that the value is enclosed in double quotes.

Special characters

You can use the following special characters in your values:

Name Notation
Backslash (\) \\
Double quote (") \"
Newline \n
Tab \t

Example:

Whitespace handling

Whitespace is handled thus:

API

class Socarrat\Environment\EnvironmentManager

static public function getParsedEnv(): array

Returns all parsed environment variables as an associative array.

static public function parseFS(string $rootDir, bool $putenv = true)

Parses .env files from the filesystem.

This method reads the files in the order specified in EnvironmentManager::$fileOrder. You can set this order using setFileOrder.

Parameter name Type Default value Description
$rootDir string - The root directory which contains your .env file/s.
$putenv bool true Whether to register the values with PHP's environment, so that they can be retrieved using getenv().

static public function parseString(string $envFile, bool $putenv = true)

Parses a single .env file passed as a string.

Parameter name Type Default value Description
$envFile string - The string to parse
$putenv bool true Whether to register the values with PHP's environment, so that they can be retrieved using getenv().

static public function setFileOrder(array $order): void

Sets the order (passed as the $order parameter) in which .env files are loaded. Lower index means higher importance.

The default file order is:

Testing

This library is unit-tested by PHPunit using the tests in the on GitHub.

Copyright

(c) 2023 Romein van Buren. Licensed under the MIT license.

For the full copyright and license information, please view the license.md file that was distributed with this source code.


All versions of environment with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package socarrat/environment contains the following files

Loading the files please wait ....