components env
Release 1.0.0 Packagist Ready
Ferramentas de ambiente PHP, estrutura Autoframe
Espaço para nome:
Aulas:
// GENERAL
$oEnv = AfrEnv::getInstance()->setWorkDir(__DIR__);
$oEnv->readEnv(0); //load env files from __DIR__ without cache
$oEnv->readEnv(60); //cache loaded env file for 60 seconds
$oEnv->setInlineEnvVar('FOO', 'BAR'); //set *[FOO]=BAR
$oEnv->getEnv('APP_ENV'); //get env key
$oEnv->getEnv(); //get all env keys as array
$oEnv->registerEnv($bMutableOverwrite = true, $bRegisterPutEnv = true);
// populate $_SERVER, $_ENV and getenv()
$oEnv->flush(); //total reset for class,cache, except superglobals are stil available
// INCLUDES PHP FILE THAT CONTAINS return array(...);
$oEnv = AfrEnv::getInstance();
$oEnv->readEnvPhpFile(path);
$oEnv->getEnv('FROM_PHP_FILE');
// Validator: REQUIRED or throw error on register or access
$oEnv = AfrEnv::getInstance();
$oEnv->required(['APP_ENV','SECRET']);
$oEnv->required(['NUMBER_INT'])->isInteger();
$oEnv->ifPresent(['NUMBER_FLOAT'])->isFloat();
$oEnv->ifPresent(['SOMENTHING'])->notEmpty();
$oEnv->ifPresent(['SOME_DATE_TIME'])->isDateTime();
$oEnv->unrequire(['NUMBER_INT']);
$oEnv->getEnv('SECRET');
// CUSTOM APP_ENV
$oEnv = AfrEnv::getInstance();
$this->ifPresent(['APP_ENV'])->allowedValues([
'DEV',
'PRODUCTION',
'STAGING',
'LOCAL',
'CUSTOM',
]);
$oEnv->setInlineEnvVar('APP_ENV', 'CUSTOM');
echo $oEnv->getEnv('APP_ENV'); //prints CUSTOM
// xet : set / get
$oEnv = AfrEnv::getInstance();
$oEnv->xetAfrEnvParser(AfrEnvParserInterface $oEnvParser = null): AfrEnvParserInterface
$oEnv->xetAfrEnvValidator(AfrEnvValidatorInterface $oValidator = null): AfrEnvValidatorInterface
$oEnv->xetFileList(AfrDirTraversingFileListInterface $oFileList = null): AfrDirTraversingFileListInterface
$oEnv->xetOverWrite(AfrOverWriteInterface $oOverWrite = null): AfrOverWriteInterface
$oEnv->xetExportArray(AfrArrExportArrayAsStringInterface $oExportArray = null): AfrArrExportArrayAsStringInterface