PHPackages                             autoframe/components-env - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. autoframe/components-env

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

autoframe/components-env
========================

PHP Environment Tools, Autoframe Framework

1.0.0(3y ago)010MITPHPPHP ^7.4 || ^8.0

Since Jul 2Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/autoframe/components-env)[ Packagist](https://packagist.org/packages/autoframe/components-env)[ Docs](https://github.com/autoframe)[ RSS](/packages/autoframe-components-env/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

Autoframe is a low level framework that is oriented on SOLID flexibility
========================================================================

[](#autoframe-is-a-low-level-framework-that-is-oriented-on-solid-flexibility)

[![Build Status](https://github.com/autoframe/components-env/workflows/PHPUnit-tests/badge.svg?branch=main)](https://github.com/autoframe/components-env/actions?query=branch:main)[![License: The 3-Clause BSD License](https://camo.githubusercontent.com/8aa2016e31135b0a5c0aaccaac395f79dfa3e4aa6e71ceb64a166412b10ce633/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6175746f6672616d652f636f6d706f6e656e74732d656e76)](https://opensource.org/license/bsd-3-clause/)[![Packagist Version](https://camo.githubusercontent.com/386b0cec153f51c2afeba52ef1e904fbae004ad947534fe10a9b3af1650a9f5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6175746f6672616d652f636f6d706f6e656e74732d656e763f6c6162656c3d7061636b6167697374253230737461626c65)](https://camo.githubusercontent.com/386b0cec153f51c2afeba52ef1e904fbae004ad947534fe10a9b3af1650a9f5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6175746f6672616d652f636f6d706f6e656e74732d656e763f6c6162656c3d7061636b6167697374253230737461626c65)[![Downloads](https://camo.githubusercontent.com/7669ba8331e8d05eeff5fa007c4846601ab25c13b242478d0dfca82d80baa9ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6175746f6672616d652f636f6d706f6e656e74732d656e762e737667)](https://packagist.org/packages/autoframe/components-env)

*PHP Environment Tools, Autoframe Framework*

Namespace:

- Autoframe\\Components\\Env
- **AfrEnv::getInstance()-&gt;isDev() returns true if APP\_ENV is null**
- **APP\_ENV is not mandatory but recommended AfrEnv::getInstance()-&gt;setInlineEnvVar('APP\_ENV', 'DEV');**

Classes:

- class AfrEnv extends AfrSingletonAbstractClass implements AfrEnvInterface
    - setWorkDir(string $sDir)
    - readEnv(int $iCacheSeconds, array $aExtraEnvDirsFiles = \[\])
        - iCacheSeconds is the number of cache seconds before expire. Use zero for no cache
        - aExtraEnvDirsFiles to add extra env directories and .env files
    - readEnvPhpFile(string $sFilePath)
    - setInlineEnvVar(string $sKey, $mData)
    - - populate inline keys
    - required(array $aKeys): AfrEnvValidatorInterface
    - ifPresent(array $aKeys): AfrEnvValidatorInterface
    - unrequire(array $aKeys): AfrEnvValidatorInterface
    - - unset required or ifPresent
    - registerEnv(bool $bMutableOverwrite = false, bool $bRegisterPutEnv = false)
    - - will populate $\_ENV, $\_SERVER and getenv()
    - getEnv(string $sKey = '') single key or all registered values
    - - storage only inside class without $\_ENV, $\_SERVER or getenv()
    - flush() reset and clear all
    - isProduction()
    - isStaging()
    - isLocal()
    - isDev()
- class AfrEnvParserClass extends AfrSingletonAbstractClass implements AfrEnvParserInterface
    - parseStr
    - parseFile
- class AfrEnvValidatorClass implements AfrEnvValidatorInterface
    - reusable validator using closures
    - required(array $aKeys)
    - ifPresent(array $aKeys)
    - customClosure(callable $fX)
    - allowedValues(array $aAllowed)
    - validateAll(array $aDataSet): bool
    - reset()
    - reset(array $aKeys)
    - unrequire(array $aKeys)
    - isInteger()
    - isFloat()
    - isBoolean()
    - isArray()
    - isString()
    - isDateTime()
    - notEmpty()

---

AfrEnv
======

[](#afrenv)

```
// 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

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance42

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1097d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34517931?v=4)[Software Engineering Brasov](/maintainers/autoframe)[@autoframe](https://github.com/autoframe)

---

Top Contributors

[![autoframe](https://avatars.githubusercontent.com/u/34517931?v=4)](https://github.com/autoframe "autoframe (4 commits)")

---

Tags

parserenvgetenvputenvEnvoirement

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/autoframe-components-env/health.svg)

```
[![Health](https://phpackages.com/badges/autoframe-components-env/health.svg)](https://phpackages.com/packages/autoframe-components-env)
```

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k954.1M2.5k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k959.9M160](/packages/doctrine-lexer)[erusev/parsedown

Parser for Markdown.

15.1k156.8M870](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

3.0k437.5M1.0k](/packages/league-commonmark)[masterminds/html5

An HTML5 parser and serializer.

1.8k269.7M322](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k211.0M75](/packages/sabberworm-php-css-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
