PHPackages                             componenta/caster - 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. componenta/caster

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

componenta/caster
=================

Value casting attributes and resolvers for Componenta

v1.0.0(1mo ago)092MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/caster)[ Packagist](https://packagist.org/packages/componenta/caster)[ RSS](/packages/componenta-caster/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (2)

Componenta Caster
=================

[](#componenta-caster)

Named value casters and casting pipelines.

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

[](#installation)

```
composer require componenta/caster
```

The package declares `Componenta\Caster\ConfigProvider` in `extra.componenta.config-providers`. When `componenta/composer-plugin` is installed, the provider is added to the generated provider list automatically.

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

[](#requirements)

- PHP 8.4+

Related Packages
----------------

[](#related-packages)

PackageWhy it matters here`componenta/di`Uses casters in `#[Cast]`, `#[QueryParam(cast: ...)]`, and similar attributes.`componenta/validation`Can validate DTOs after values are normalized by casters.`componenta/config`Registers `CasterProviderInterface` through `ConfigProvider`.What It Provides
----------------

[](#what-it-provides)

- `CasterInterface`: public contract for named value casters.
- `CasterProviderInterface`: registry contract for resolving casters by name.
- `CasterProvider`: default registry with scalar, string, array, date, enum, hash, and pipeline casters.
- Typed exceptions when a value cannot be cast.

Basic Usage
-----------

[](#basic-usage)

```
use Componenta\Caster\CasterProvider;

$provider = new CasterProvider();

$int = $provider->provide('int');
$int->cast('42'); // 42
```

Unknown casters return `null`:

```
$provider->provide('missing'); // null
```

Parameterized Casters
---------------------

[](#parameterized-casters)

```
$provider->provide('clamp:10,20')->cast(25); // 20.0
$provider->provide('csv_int')->cast('1,2,3'); // [1, 2, 3]
```

Pipelines
---------

[](#pipelines)

Use `|` to chain casters:

```
$provider->provide('trim|lower')->cast('  HELLO  '); // hello
```

Use `?` to pass `null` through the whole downstream chain:

```
$provider->provide('?int|bool')->cast(null); // null
$provider->provide('?int|bool')->cast('1');  // true
```

DI Registration
---------------

[](#di-registration)

`ConfigProvider` registers `CasterProviderInterface` as a factory returning `CasterProvider`.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

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

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/componenta-caster/health.svg)

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

###  Alternatives

[norkunas/youtube-dl-php

youtube-dl / yt-dlp wrapper for php

514356.8k18](/packages/norkunas-youtube-dl-php)[theodo-evolution/legacy-wrapper-bundle

40124.9k](/packages/theodo-evolution-legacy-wrapper-bundle)

PHPackages © 2026

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