PHPackages                             ap-lib/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ap-lib/env

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ap-lib/env
==========

014PHP

Since Mar 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ap-lib/env)[ Packagist](https://packagist.org/packages/ap-lib/env)[ RSS](/packages/ap-lib-env/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

AP\\Env
=======

[](#apenv)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

AP\\Env is a library for managing environment variables with validation and object transformation capabilities.

Installation
------------

[](#installation)

```
composer require ap-lib/env
```

Features
--------

[](#features)

- Retrieve environment variables as objects with validation
- Supports structured JSON environment variables
- Includes validation mechanisms with error handling

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Getting started
---------------

[](#getting-started)

### Base use case

[](#base-use-case)

```
use AP\Env\Env;
use AP\Scheme\ToObject;
use AP\Scheme\Validation;

class Config implements ToObject, Validation {
    // Implementation of ToObject and Validation
}

try {
    $config = Env::obj('CONFIG_VAR', Config::class);
    // Use $config as needed
} catch (Throwable $e) {
    echo "Error loading configuration: " . $e->getMessage();
}
```

### String Validation Example

[](#string-validation-example)

```
use AP\Validator\ValidatorInterface;

class NotEmptyValidator implements ValidatorInterface {
    public function validate(mixed $value): ?Errors {
        return empty($value) ? new Errors([new Error(["value"], "Value cannot be empty")]) : null;
    }
}

try {
    $value = Env::str('MY_ENV_VAR', [new NotEmptyValidator()]);
} catch (Throwable $e) {
    echo "Error: " . $e->getMessage();
}
```

### Boolean Parsing Example

[](#boolean-parsing-example)

```
$debugMode = Env::bool('DEBUG_MODE', false);
if ($debugMode) {
    echo "Debug mode is enabled";
}
```

### Lazy Loading with MyEnv

[](#lazy-loading-with-myenv)

You can create a custom environment loader using a static class that extends `Env`.

```
use AP\Env\Env;
use AP\Database\Mysql;

class MyEnv extends Env
{
    public static function DB_AUTH(): Mysql
    {
        return self::obj(__FUNCTION__, Mysql::class);
    }

    public static function PROD(): bool
    {
        return self::bool(__FUNCTION__, false);
    }
}

$dbAuth = MyEnv::DB_AUTH();
$isProd = MyEnv::PROD();
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1215fe5ecc9ba0ab1c730d3c992125cf6ebf460562e66be71ebae127789d465a?d=identicon)[AntonPanfilov](/maintainers/AntonPanfilov)

---

Top Contributors

[![anton-panfilov](https://avatars.githubusercontent.com/u/1083546?v=4)](https://github.com/anton-panfilov "anton-panfilov (1 commits)")

### Embed Badge

![Health badge](/badges/ap-lib-env/health.svg)

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

###  Alternatives

[drmonkeyninja/cakephp-social-share

CakePHP helper for creating social share/bookmark links

34103.3k](/packages/drmonkeyninja-cakephp-social-share)[mihanentalpo/fio-analyzer

Analyze user input string, and split it into Russian first name, second name and last name

1422.9k](/packages/mihanentalpo-fio-analyzer)

PHPackages © 2026

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