PHP code example of gmazzap / gea

1. Go to this page and download the library: Download gmazzap/gea 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/ */

    

gmazzap / gea example snippets


$gea = Gea\Gea::instance(__DIR__);

$gea->load();

$apiKey = $gea->read('APY_KEY');
$apiKey = $gea['APY_KEY'];
$apiKey = getenv('APY_KEY');

$gea->write('APY_KEY', 'mysupersecretkey');
$gea['APY_KEY'] = 'mysupersecretkey';
putenv('APY_KEY=mysupersecretkey');

$gea->load(); # ok
$gea->load(); # throw an exception

$gea->write('A_VAR', 'A value'); # ok
$gea->write('A_VAR', 'Another value'); # throw an exception

$gea->discard('FOO');
unset($gea['FOO']);

$gea['FOO'] = 'First Value';

echo $gea['FOO']; # print 'First Value'

unset($gea['FOO']); # Without this an exception had been thrown on next line

$gea['FOO'] = 'Second Value';

echo $gea['FOO']; # Print 'Second Value'

$gea->flush(Gea\Gea::FLUSH_SOFT);

$gea->flush(Gea\Gea::FLUSH_HARD, ['FOO', 'BAR', 'BAZ']);

$gea = Gea\Gea::instance(__DIR__, '.env', Gea\Gea::VAR_NAMES_HOLD);
$gea->load();

var_export( $gea->varNames() ); // array( 'FOO', 'BAR', 'BAZ' )

$gea = Gea\Gea::instance(__DIR__, '.env', Gea\Gea::VAR_NAMES_HOLD);
$gea->load();

$gea->flush(Gea\Gea::FLUSH_HARD, $gea->varNames());

$gea = Gea\Gea::instance(__DIR__, '.env', Gea\Gea::READ_ONLY);
$gea->load();

$flags = Gea\Gea::READ_ONLY|Gea\Gea::VAR_NAMES_HOLD;
$gea = Gea\Gea::instance(__DIR__, '.env', $flags);

$gea = Gea\Gea::instance(__DIR__);

$gea->addFilter('API_KEY', '

$gea->addFilter('MY_SWITCH', ['enum' => ['on', 'off']]);

$gea->addFilter('MY_NUMBER', 'int');

$gea->addFilter('AWESOMENESS_ALLOWED', 'bool');

$gea->addFilter('MY_LIST', 'array');

$gea->addFilter('USER', ['array' => ['|', ArrayFilter::DO_TRIM, 'ucfirst']]);
$gea->load();

var_export($gea['USER']); // array( 'John', 'Doe' )

$gea->addFilter('USER_EMAIL', ['object' => [My\App\EmailObject::class]);

$gea->addFilter('USER_ID', ['callback' => [function($userId) {
   return My\App\UserFactory::fromID($userId);
}]);

$gea->addFilter('USER_ID', ['

$gea->addFilter('MY_LIST', ['array', ['object' => [\ArrayIterator::class]]);

$gea->addFilter('USER_EMAIL', ['LTER_SANITIZE_EMAIL);
}]);

$gea = Gea\Gea::noLoaderInstance();

$gea = Gea\Gea::readOnlyInstance();

$gea = Gea\Gea::noLoaderInstance(Gea\Gea::READ_ONLY);

namespace MyApp;

class App {
  
    public function run(\ArrayAccess $configs) {
       // bootstrap the application here
    }
}

$gea = getenv('APP_ENV') === 'production'
   ? Gea\Gea::noLoaderInstance() # in production we load nothing
   : Gea\Gea::instance(__DIR__); # in development we load .env file

$gea->addFilter(['DB_NAME', 'DB_USER', 'DB_PASS'] '
bash
BASE_PATH=/var/www/app
PUBLIC_PATH=${BASE_PATH}/public
bash
export PASSWORD=mypassword