PHPackages                             unicon/yaml - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. unicon/yaml

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

unicon/yaml
===========

Validates YAML file using given class and, if matches, creates an object. Understands PhpDoc, converts values if necessary. Works recursively, so the YAML file may have complicated structure, and the given class may have properties of other classes.

1.0.0(2y ago)13.1kGPL-2.0-onlyPHPPHP &gt;=8.1

Since Jan 10Pushed 2y ago2 watchersCompare

[ Source](https://github.com/sasha-bo/yaml-to-object)[ Packagist](https://packagist.org/packages/unicon/yaml)[ RSS](/packages/unicon-yaml/feed)WikiDiscussions master Synced yesterday

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

Yaml Reader
===========

[](#yaml-reader)

Validates YAML file using given class and, if matches, creates an object. Understands PhpDoc, converts values if necessary. Works recursively, so the YAML file may have complicated structure, and the given class may have properties of other classes.

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

[](#installation)

`composer require unicon/yarn`

Usage
-----

[](#usage)

```
$reader = new Yaml(MyClass::class);
$object = $reader->read('my_yaml.yml');
```

Example
-------

[](#example)

```
class Simple
{
    public int $integerParameter = 1;
    /** @var positive-int */
    public int $positiveIntegerParameter;
    public ?bool $booleanOrNullParameter;
    public string $stringParameter = 'default';
}
```

### Success example

[](#success-example)

```
integer_parameter: '777'
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888
```

### Failures

[](#failures)

`YamlException` is thrown if the YAML file doesn't match the class:

` Yaml parameter positive_integer_parameter must be greater or equal to 1, "-1" given`

```
integer_parameter: '777'
positive_integer_parameter: '-1'
boolean_or_null_parameter: null
string_parameter: 888
```

`Can't convert integer_parameter 777.777 to int`

```
integer_parameter: 777.777
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888
```

`Can't convert integer_parameter "xxx" to int`

```
integer_parameter: 'xxx'
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888
```

`Yaml parameter positive_integer_parameter is missed`

(`integer_parameter` and `boolean_or_null_parameter` are missed too, but one has default values, another is nullable)

```
string_parameter: 'aaa'
```

`Yaml parameter extra_parameter with value true is unexpected`

(this exception is never thrown for `stdClass` or `\AllowDynamicProperties` classes)

```
extra_parameter: true
integer_parameter: '777'
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888
```

You can find more examples in the [test directory](https://github.com/sasha-bo/yaml-to-object/tree/master/tests/examples)including dates, complicated structures and trees (classes with `array` properties).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

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

906d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5369c71152f0feb0c57d12044c87c7f8be9c4640586b042629a6c50638d4e2e8?d=identicon)[sashabo](/maintainers/sashabo)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/unicon-yaml/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[getkirby/cms

The Kirby core

1.5k584.8k474](/packages/getkirby-cms)[drupal/coder

Coder is a library to review Drupal code.

3045.9M575](/packages/drupal-coder)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

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