PHPackages                             smpita/configas - 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. smpita/configas

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

smpita/configas
===============

Typed Config Resolver for Laravel

v2.0.1(6mo ago)128.2k↓72.3%1[2 PRs](https://github.com/smpita/configas/pulls)MITPHPPHP &gt;=8.1CI passing

Since Feb 26Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/smpita/configas)[ Packagist](https://packagist.org/packages/smpita/configas)[ Docs](https://github.com/smpita/makeas)[ GitHub Sponsors](https://github.com/smpita)[ RSS](/packages/smpita-configas/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (6)Versions (14)Used By (0)

Typed Config Resolver for Laravel
=================================

[](#typed-config-resolver-for-laravel)

Don't settle for **mixed** signatures from `config()` when you can enforce types.

[![Total Downloads](https://camo.githubusercontent.com/9c772e7ce5f3645a47239ceb51135bba2a79c5119d12da131ad9e250ec5799d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d706974612f636f6e66696761732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smpita/configas)[![Latest Version on Packagist](https://camo.githubusercontent.com/4efd7cdeeccd31db85b19afbf87fe1a14c97b1e5393b1a66dbc154a656ec9dc9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d706974612f636f6e66696761732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smpita/configas)[![License](https://camo.githubusercontent.com/bc0a23b35bf05b9912824e6a31eeb7b1ff8ee23eb59a7caa1203dcf684b28045/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736d706974612f636f6e66696761732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smpita/configas)

[![GitHub Tests Action Status](https://camo.githubusercontent.com/b6e822b6fbfed6b08115021f136085134df16b6e14cd9138c8ba074737b5b6eb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d706974612f636f6e66696761732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/smpita/configas/actions?query=workflow%3Arun-tests+branch%3Amain)[![Coverage Status](https://camo.githubusercontent.com/a0e1345b0fdafe2f5460fed1c7b9d6265c47655634d8ae697ed281a42bf3197f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736d706974612f636f6e66696761732f62616467652e737667)](https://coveralls.io/github/smpita/configas)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/605ac970e22a5ef2b781dbf1fa2b9c8240a4492e2faabdf4e5bbb0845056c4ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d706974612f636f6e66696761732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/smpita/configas/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)

[![FOSSA Status](https://camo.githubusercontent.com/9cc5605be14c9424b19c8b2f838fe7313a5d4328ad0f49cd5c56cb4d2a71a665/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246736d70697461253246636f6e66696761732e7376673f747970653d736869656c64266973737565547970653d7365637572697479)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsmpita%2Fconfigas?ref=badge_shield&issueType=security)[![FOSSA Status](https://camo.githubusercontent.com/a276af00da68f7df8de4841da3face288686c4b146c96693b3800bfbee8990f9/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246736d70697461253246636f6e66696761732e7376673f747970653d736869656c64266973737565547970653d6c6963656e7365)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsmpita%2Fconfigas?ref=badge_shield&issueType=license)

---

Table of Contents
-----------------

[](#table-of-contents)

- [Quick Start](#quick-start)
    - [Installation](#installation)
    - [Resolving Types](#resolving-types)
    - [Cache](#cache)
    - [Cache Invalidation](#cache-invalidation)
    - [Fresh Values](#fresh-values)
    - [Helpers](#helpers)
- [Deprecations](#deprecations)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

---

This package wraps [Smpita/TypeAs](https://github.com/smpita/typeas), a generalized PHP library useful on any PHP project employing static analysis or tight type enforcement.

Quick Start
-----------

[](#quick-start)

### Installation

[](#installation)

Install the package via composer:

```
composer require smpita/configas
```

See [SIGNATURES](docs/signatures.md) for the full list of methods and signatures.

### Resolving types

[](#resolving-types)

[SIGNATURES#resolving](docs/signatures.md#resolving)

```
use Smpita\ConfigAs\ConfigAs;

// Throws \Smpita\ConfigAs\ConfigAsResolutionException if 'config.key' can't resolve to the type.
$array = ConfigAs::array('config.key');
$bool = ConfigAs::bool('config.key');
$class = ConfigAs::class(Expected::class, 'config.key');
$float = ConfigAs::float('config.key');
$int = ConfigAs::int('config.key');
$string = ConfigAs::string('config.key');

// Returns null if 'config.key' can't resolve to the type.
$nullableArray = ConfigAs::nullableArray('config.key');
$nullableBool = ConfigAs::nullableBool('config.key');
$nullableClass = ConfigAs::nullableClass(Expected::class, 'config.key');
$nullableFloat = ConfigAs::nullableFloat('config.key');
$nullableInt = ConfigAs::nullableInt('config.key');
$nullableString = ConfigAs::nullableString('config.key');
```

To suppress throwing exceptions, provide a default.

```
use Smpita\ConfigAs\ConfigAs;

// Returns the default if passed null, or if 'config.key' can't resolve to the type.
$array = ConfigAs::array('config.key', []);
$bool = ConfigAs::bool('config.key', false);
$class = ConfigAs::class(Expected::class, 'config.key', new StdClass());
$float = ConfigAs::float('config.key', 0.0);
$int = ConfigAs::int('config.key', 0);
$string = ConfigAs::string('config.key', '');

// Nullable types can specify defaults.
$nullableArray = ConfigAs::nullableArray('config.key', []);
$nullableBool = ConfigAs::nullableBool('config.key', false);
$nullableClass = ConfigAs::nullableClass(Expected::class, 'config.key', new StdClass());
$nullableFloat = ConfigAs::nullableFloat('config.key', 0.0);
$nullableInt = ConfigAs::nullableInt('config.key', 0);
$nullableString = ConfigAs::nullableString('config.key', '');
```

---

Cache
-----

[](#cache)

[SIGNATURES#cache](docs/signatures.md#cache)

To keep things performant, types are validated once and results are cached in static arrays for the lifetime of the request.

### Cache Invalidation

[](#cache-invalidation)

[SIGNATURES#cache-invalidation](docs/signatures.md#cache-invalidation)

You can flush all caches or invalidate any given key.

```
use Smpita\ConfigAs\ConfigAs;

// Invalidate all caches
ConfigAs::flush();

// Invalidate all of a type
ConfigAs::flushArrays();
ConfigAs::flushBools();
ConfigAs::flushClasses();
ConfigAs::flushInts();
ConfigAs::flushStrings();

// Invalidate a specific key
ConfigAs::forgetArray('config.key');
ConfigAs::forgetBool('config.key');
ConfigAs::forgetClass(Expected::class, 'config.key');
ConfigAs::forgetFloat('config.key');
ConfigAs::forgetInt('config.key');
ConfigAs::forgetString('config.key');
ConfigAs::forgetNullableArray('config.key');
ConfigAs::forgetNullableBool('config.key');
ConfigAs::forgetNullableClass(Expected::class, 'config.key');
ConfigAs::forgetNullableFloat('config.key');
ConfigAs::forgetNullableInt('config.key');
ConfigAs::forgetNullableString('config.key');
```

### Fresh values

[](#fresh-values)

To bypass the cache, you may use the `fresh` methods that are available for each type. This method bypasses the cache entirely. Returns from these methods will not be cached. To update a cache, [invalidate](#cache-invalidation) the `config.key`, then use a [standard resolver](#resolving-types).

```
use Smpita\ConfigAs\ConfigAs;

$array = ConfigAs::freshArray('config.key');
$bool = ConfigAs::freshBool('config.key');
$class = ConfigAs::freshClass(Expected::class, 'config.key');
$float = ConfigAs::freshFloat('config.key');
$int = ConfigAs::freshInt('config.key');
$string = ConfigAs::freshString('config.key');
$nullableArray = ConfigAs::freshNullableArray('config.key');
$nullableBool = ConfigAs::freshNullableBool('config.key');
$nullableClass = ConfigAs::freshNullableClass(Expected::class, 'config.key');
$nullableFloat = ConfigAs::freshNullableFloat('config.key');
$nullableInt = ConfigAs::freshNullableInt('config.key');
$nullableString = ConfigAs::freshNullableString('config.key');
```

---

Helpers
-------

[](#helpers)

[SIGNATURES#helpers](docs/signatures.md#helpers)

There are helper methods located in the `Smpita\ConfigAs` namespace.

```
use function Smpita\ConfigAs\configArray;
use function Smpita\ConfigAs\configBool;
use function Smpita\ConfigAs\configClass;
use function Smpita\ConfigAs\configFloat;
use function Smpita\ConfigAs\configInt;
use function Smpita\ConfigAs\configString;
use function Smpita\ConfigAs\configNullableArray;
use function Smpita\ConfigAs\configNullableBool;
use function Smpita\ConfigAs\configNullableClass;
use function Smpita\ConfigAs\configNullableFloat;
use function Smpita\ConfigAs\configNullableInt;
use function Smpita\ConfigAs\configNullableString;

$array = configArray('config.key');
$bool = configBool('config.key');
$class = configClass(Expected::class, 'config.key');
$float = configFloat('config.key');
$int = configInt('config.key');
$string = configString('config.key');
$nullableArray = configNullableArray('config.key');
$nullableBool = configNullableBool('config.key');
$nullableClass = configNullableClass(Expected::class, 'config.key');
$nullableFloat = configNullableFloat('config.key');
$nullableInt = configNullableInt('config.key');
$nullableString = configNullableString('config.key');
```

Additionally:

```
use function Smpita\ConfigAs\configAs;

$configAs = configAs();

$array = $configAs->array('config.key');
$bool = $configAs->bool('config.key');
$class = $configAs->class(Expected::class, 'config.key');
$float = $configAs->float('config.key');
$int = $configAs->int('config.key');
$string = $configAs->string('config.key');
$nullableArray = $configAs->nullableArray('config.key');
$nullableBool = $configAs->nullableBool('config.key');
$nullableClass = $configAs->nullableClass(Expected::class, 'config.key');
$nullableFloat = $configAs->nullableFloat('config.key');
$nullableInt = $configAs->nullableInt('config.key');
$nullableString = $configAs->nullableString('config.key');
```

---

Custom Resolvers
----------------

[](#custom-resolvers)

[SIGNATURES#resolver-registration](https://github.com/smpita/typeas/blob/main/docs/signatures.md#resolver-registration)

ConfigAs methods will pass custom resolves to the underlying [Smpita\\TypeAs](https://github.com/smpita/typeas/) library to enable you to use your own custom resolvers. For creation, global registration, and full instructions, see the [library docs](https://github.com/smpita/typeas/blob/main/README.md#resolvers).

#### Single use

[](#single-use)

```
$string = \Smpita\ConfigAs::string('config.key', null, new CustomStringResolver());
```

---

Deprecations
------------

[](#deprecations)

[SIGNATURES#deprecations](docs/signatures.md#deprecations)

---

Testing
-------

[](#testing)

```
composer test
```

---

Changelog
---------

[](#changelog)

Please see [RELEASES](https://github.com/smpita/configas/releases) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Sean Pearce](https://github.com/smpita)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance78

Regular maintenance activity

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.8% 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

Every ~74 days

Recently: every ~9 days

Total

10

Last Release

189d ago

Major Versions

v1.4.1 → v2.0.02025-12-02

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14220530?v=4)[Sean Pearce](/maintainers/smpita)[@smpita](https://github.com/smpita)

---

Top Contributors

[![smpita](https://avatars.githubusercontent.com/u/14220530?v=4)](https://github.com/smpita "smpita (159 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")

---

Tags

laravelsmpitaconfigas

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smpita-configas/health.svg)

```
[![Health](https://phpackages.com/badges/smpita-configas/health.svg)](https://phpackages.com/packages/smpita-configas)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

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