Download the PHP package silinternational/php-env without Composer

On this page you can find all versions of the php package silinternational/php-env. 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 php-env

Sil/PhpEnv/

Simple PHP library for getting (or requiring) environment variables, designed to handle true, false, and null more intelligently. If desired, an environment variable's value can be split into an array automatically.

Build Status

Unit Tests

Setup

  1. Clone this repo.
  2. Copy local.env.dist to local.env and update GitHub.com token as appropriate.
  3. Run make test to install dependencies and run PHPUnit tests.

Makefile script

There is a Makefile in place to simplify common tasks.


Classes in Sil/PhpEnv namespace

  1. Env: use Sil\PhpEnv\Env;
  2. EnvVarNotFoundException: use Sil\PhpEnv\EnvVarNotFoundException;

Class Env summary of functions

  1. get - public static function get($varname, $default = null)

    • searches the local environment for $varname and returns the corresponding value string
    • if $varname is not set or the value is empty (only whitespace), get returns $default parameter
    • if the value string corresponding to $varname is 'true', 'false' or 'null', get returns php values of true, false, or null respectively
    • NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php true.
      false and null are handled similarly. Other value strings will have leading/trailing whitespace trimmed.
  2. getString - public static function getString($varname, $default = null): ?string

    • searches the local environment for $varname and returns the corresponding trimmed value string
    • if $varname is not set or the value is empty (only whitespace), getString returns $default parameter
  3. getBoolean - public static function getBoolean($varname, $default = null): ?bool

    • searches the local environment for $varname and returns the corresponding boolean value string
    • if $varname is not set or the value is empty (only whitespace), getBoolean returns $default parameter
    • if the value string corresponding to $varname is 'true', 'false' or 'null', getBoolean returns php values of true, false, or null respectively
    • if the value is not boolean, getBoolean returns $default parameter
    • NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php true. false and null are handled similarly.
  4. getArray - public static function getArray($varname, array $default = [])

    • searches the local environment for $varname and returns the corresponding value string with comma separated elements as a php array
    • if $varname is not set or the value is empty (only whitespace), getArray returns $default parameter which must be an array
    • if $default is not an array, it throws a TypeError exception
  5. requireEnv - public static function requireEnv($varname)

    • searches the local environment for $varname and returns the corresponding value string
    • if $varname is not set or the value is empty (only whitespace), it throws EnvVarNotFoundException
    • 'true', 'false', and 'null' are handled the same as get()
  6. requireArray - public static function requireArray($varname)

    • searches the local environment for $varname and returns the corresponding value string with comma separated elements as a php array
    • if $varname is not set or the value is empty (only whitespace), it throws EnvVarNotFoundException

Class EnvVarNotFoundException

class EnvVarNotFoundException extends \Exception

EnvVarNotFoundException is thrown by requireEnv() and requireArray() when $varname is not found in the local environment or the corresponding value string is empty (only whitespace)


Env example function calls

Assume this local.env file

EMPTY=
SPACES=      
WHITESPACE= Some whitespace    
FALSE=False
TRUE=TRUE
NULL=null
LOWERCASE=abc123
UPPERCASE=ABC123
ARRAY0=
ARRAY1=one
ARRAY=one,two,,three

Example function calls and results


All versions of php-env with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
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 silinternational/php-env contains the following files

Loading the files please wait ....