PHP code example of cekurte / environment

1. Go to this page and download the library: Download cekurte/environment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cekurte / environment example snippets




use function Cekurte\Environment\env;        // To get values using a function ( 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!



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




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




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




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



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



// string(7) "unknown"
var_dump(Cekurte\Environment\Environment::get("ENV_UNKNOWN"));
bash
export ENV_BOOL=true
bash
export ENV_NULL=null
bash
export ENV_NUMERIC=123