2017 © Pedro PelĆ”ez
 

library environment

A library to get the values from environment variables and process to php data types

image

cekurte/environment

A library to get the values from environment variables and process to php data types

  • Friday, May 27, 2016
  • by jpcercal
  • Repository
  • 1 Watchers
  • 52 Stars
  • 18,328 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 18 Versions
  • 7 % Grown

The README.md

Environment

Build Status Code Climate Coverage Status Latest Stable Version License SensioLabsInsight, (*1)

  • A simple library (with all methods covered by php unit tests) to increase the power of your environment variables, contribute with this project!

Installation

  • The package is available on Packagist.
  • The source files is PSR-2 compatible.
  • Autoloading is PSR-4 compatible.
composer require cekurte/environment

Documentation

Setup your variables to PHP with putenv("KEY=VALUE") or put your environment variables into OS directly. Additionally you can use this library to perform this task vlucas/phpdotenv (we recommend that you use this library)., (*2)

And now, use our library to get values and increase the power of your environment variables., (*3)

<?php

use function Cekurte\Environment\env;        // To get values using a function (requires php >=5.6)
use Cekurte\Environment\Environment;         // To get values using a static class
use Cekurte\Environment\EnvironmentVariable; // To get values using a object

// ...

$data = Environment::get("YOUR_ENVIRONMENT_KEY");

// Getting default data if your environment variable not exists or not is loaded.
$data = Environment::get("APP_DEBUG", true);

// ...
// Other ways to get the values of environment variables.

// Using a object...
$data = (new EnvironmentVariable())->get("YOUR_ENVIRONMENT_KEY", "defaultValue");

// Using a function... @deprecated
$data = env("YOUR_ENVIRONMENT_KEY", "defaultValue");

// Note that if the second parameter is omitted
// then the return value (if your key not exists) will be null.

// A new way was added to you get all environment variables as an array.
$data = Environment::getAll();

// You can use a filter to get only the environment variables that you need.
$data = Environment::getAll([
    new Cekurte\Environment\Filter\KeyRegexFilter('/PROCESSOR/'),
    new Cekurte\Environment\Filter\ValueRegexFilter('/6/'),
]);

// The method above will get all environment variables, where:
// the environment variable name has the word PROCESSOR AND
// the environment variable value has the number six.

// And you can develop your own filters, contribute with this project!

This command will get the value of the environment variable and will convert values to respective php data type., (*4)

Actually are available the following resources to process your environment variables:, (*5)

Examples

In this section you can see the examples to all resource types., (*6)

ArrayResource

The array resource parse a value from environment variable that is a string to the array php data type. Supposing that there exists an environment variable named "ENV_ARRAY" with the following value [1,2,3,"key"=>"value"]., (*7)

export ENV_ARRAY=[1,2,3,"key"=>"value"]

When you read this environment variable with our library, then it will convert the data to the correct data type (in this case to array) using the ArrayResource class., (*8)

<?php

// array(4) {
//   [0]=> int(1)
//   [1]=> int(2)
//   [2]=> int(3)
//   ["key"]=> string(5) "value"
// }
var_dump(Cekurte\Environment\Environment::get("ENV_ARRAY"));

BooleanResource

The boolean resource parse a value from environment variable that is a string to the boolean php data type. Supposing that there exists an environment variable named "ENV_BOOL" with the following value true., (*9)

export ENV_BOOL=true

When you read this environment variable with our library, then it will convert the data to the correct data type (in this case to boolean) using the BooleanResource class., (*10)

<?php

// bool(true)
var_dump(Cekurte\Environment\Environment::get("ENV_BOOL"));

JsonResource

The json resource parse a value from environment variable that is a string to the array php data type. Supposing that there exists an environment variable named "ENV_JSON" with the following value {"key":"value"}., (*11)

export ENV_JSON={"key":"value"}

When you read this environment variable with our library, then it will convert the data to the correct data type (in this case to array) using the JsonResource class., (*12)

<?php

// array(1) {
//   ["key"]=> string(5) "value"
// }
var_dump(Cekurte\Environment\Environment::get("ENV_JSON"));

NullResource

The null resource parse a value from environment variable that is a string to the null php data type. Supposing that there exists an environment variable named "ENV_NULL" with the following value null., (*13)

export ENV_NULL=null

When you read this environment variable with our library, then it will convert the data to the correct data type (in this case to null) using the NullResource class., (*14)

<?php

// NULL
var_dump(Cekurte\Environment\Environment::get("ENV_NULL"));

NumericResource

The numeric resource parse a value from environment variable that is a string to the numeric php data type (an integer or a float). Supposing that there exists an environment variable named "ENV_NUMERIC" with the following value 123., (*15)

export ENV_NUMERIC=123

When you read this environment variable with our library, then it will convert the data to the correct data type (in this case to int) using the NumericResource class., (*16)

<?php

// int(123)
var_dump(Cekurte\Environment\Environment::get("ENV_NUMERIC"));

UnknownResource

The unknown resource no parse the values from environment variable and is used to get values when all resource types can not parse the data. Supposing that there exists an environment variable named "ENV_UNKNOWN" with the following value "unknown"., (*17)

export ENV_UNKNOWN="unknown"

When you read this environment variable with our library, then it will get the raw value using the UnknownResource class., (*18)

<?php

// string(7) "unknown"
var_dump(Cekurte\Environment\Environment::get("ENV_UNKNOWN"));

If you liked of this library, give me a star =)., (*19)

Contributing

  1. Give me a star =)
  2. Fork it
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Make your changes
  5. Run the tests, adding new ones for your own code if necessary (vendor/bin/phpunit)
  6. Commit your changes (git commit -am 'Added some feature')
  7. Push to the branch (git push origin my-new-feature)
  8. Create new Pull Request

The Versions

27/05 2016

dev-master

9999999-dev

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

config types data environment env process variables

27/05 2016

v0.3.0

0.3.0.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

config types data environment env process variables

02/05 2016

v0.2.3

0.2.3.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

config types data environment env process variables

30/03 2016

v0.2.2

0.2.2.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

config types data environment env process variables

30/03 2016

v0.2.1

0.2.1.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

config types data environment env process variables

07/12 2015

v0.1.2

0.1.2.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

config types data environment env process variables

20/11 2015

v0.1.1

0.1.1.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

20/11 2015

v0.1.0

0.1.0.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

20/11 2015

v0.0.10

0.0.10.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

04/11 2015

v0.0.9

0.0.9.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

04/11 2015

v0.0.8

0.0.8.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

30/09 2015

v0.0.7

0.0.7.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

29/09 2015

v0.0.6

0.0.6.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php ^5.5

 

The Development Requires

config types data environment env process variables

29/09 2015

v0.0.5

0.0.5.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

 

The Development Requires

config types data environment env process variables

29/09 2015

v0.0.3

0.0.3.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

 

The Development Requires

config types data environment env process variables

29/09 2015

v0.0.2

0.0.2.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

 

The Development Requires

config types data environment env process variables

28/09 2015

v0.0.1

0.0.1.0

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

 

The Development Requires

config types data environment env process variables

27/05 2015

dev-develop

dev-develop

A library to get the values from environment variables and process to php data types

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

config types data environment env process variables