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 1mo ago

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 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

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

859d 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

[drupal/coder

Coder is a library to review Drupal code.

3043.6M461](/packages/drupal-coder)[karser/karser-recaptcha3-bundle

Google ReCAPTCHA v3 for Symfony

1862.4M7](/packages/karser-karser-recaptcha3-bundle)[romaricdrigon/metayaml

Using \[Yaml|Xml|json\] schemas files to validate \[Yaml|Xml|json\]

103306.5k8](/packages/romaricdrigon-metayaml)[ddtraceweb/smtp-validator-email

Validate your email by smtp protocol

28143.4k](/packages/ddtraceweb-smtp-validator-email)

PHPackages © 2026

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