PHPackages                             thecodingmachine/yaml-definition-loader - 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. thecodingmachine/yaml-definition-loader

ActiveLibrary

thecodingmachine/yaml-definition-loader
=======================================

Provides a loader that can convert YAML files to container definitions compatible with the definition-interop standard.

0.1.0(10y ago)15MITPHP

Since Nov 30Pushed 10y ago6 watchersCompare

[ Source](https://github.com/thecodingmachine/yaml-definition-loader)[ Packagist](https://packagist.org/packages/thecodingmachine/yaml-definition-loader)[ RSS](/packages/thecodingmachine-yaml-definition-loader/feed)WikiDiscussions 1.0 Synced 2mo ago

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

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/07bda5bd03698a7dbf381984ecdd366048aed07906129c1c7b020935ec2844eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f79616d6c2d646566696e6974696f6e2d6c6f616465722f6261646765732f7175616c6974792d73636f72652e706e673f623d312e30)](https://scrutinizer-ci.com/g/thecodingmachine/yaml-definition-loader/?branch=1.0)[![Build Status](https://camo.githubusercontent.com/a0d242b7404603514e4d04da6d32eb34ac273de42974bfeeaa6d32b690c82704/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f79616d6c2d646566696e6974696f6e2d6c6f616465722e7376673f6272616e63683d312e30)](https://travis-ci.org/thecodingmachine/yaml-definition-loader)[![Coverage Status](https://camo.githubusercontent.com/41b591bad572e6ae4d64280a61efd9ba4b940d6a96398e604139b00d32048771/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f79616d6c2d646566696e6974696f6e2d6c6f616465722f62616467652e7376673f6272616e63683d312e3026736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/yaml-definition-loader?branch=1.0)

YAML Definition Loader for *definition-interop*
===============================================

[](#yaml-definition-loader-for-definition-interop)

This package contains a **loader** that can convert YAML files to container definitions compatible with the *definition-interop* standard.

In order to keep things simple for newcomers, the supported YAML file is a subset of Symfony services YML file format.

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

[](#installation)

You can install this package through Composer:

```
{
    "require": {
        "thecodingmachine/yaml-definition-loader": "~1.0"
    }
}
```

The packages adheres to the [SemVer](http://semver.org/) specification, and there will be full backward compatibility between minor versions.

Automatic discovery
-------------------

[](#automatic-discovery)

If you want YAML files of your package to be automatically discoverable (using Puli), you should bind your YAML files to the "definition-interop/yaml-definition-files" binding type.

Lets assume that your service file is in "services/my\_service.yml".

In your package, simply type:

```
# This maps the virtual Puli path "/my_vendor/my_package" to the "services" directory.
puli map /my_vendor/my_package services

# Binds all YML files in the directory services/*.yml (please note how the directory is a virtual Puli directory).
puli bind /my_vendor/my_package/*.yml definition-interop/yaml-definition-files
```

Binded YML files can be discovered automatically if consumers use Puli for Discovery.

Usage
-----

[](#usage)

This package contains a `YamlDefinitionLoader` class. The goal of this class is to take a YAML file and generate a number of "entry definitions" (as defined in [*definition-interop*](https://github.com/container-interop/definition-interop/)).

These definitions can then be turned into a dependency injection container using the appropriate tools (like [Yaco](https://github.com/thecodingmachine/yaco)).

```
use TheCodingMachine\Definition\YamlDefinitionLoader;

$servicesProvider = new YamlDefinitionLoader("my-services.yml");

$definitions = $servicesProvider->getDefinitions();
```

Note: the `YamlDefinitionLoader` implements the `Interop\Container\Definition\DefinitionProviderInterface`.

File format
-----------

[](#file-format)

### Declare parameters

[](#declare-parameters)

```
parameters:
    foo: bar
```

### Declare an instance

[](#declare-an-instance)

```
services:
    my_service:
        class: My\ClassName
        arguments: [ foo, bar ]
```

This will declare a "my\_service" service, from class `My\ClassName`, passing to the constructor the strings "foo" and "bar".

### Reference an instance

[](#reference-an-instance)

```
services:
    my_reference:
        class: My\ReferencedClass
    my_service:
        class: My\ClassName
        arguments: [ "@my_reference" ]
```

The `my_reference` service will be passed in parameter to the constructor of the `my_service` service. To reference a service, use the `@` prefix. If you want a string starting with a `@`, you should double it. For instance:

- `@service`
- `@@some text starting with @`

### Call a method of a service

[](#call-a-method-of-a-service)

```
services:
    my_service:
        class: My\ClassName
        calls:
            - [ setLogger, [ '@logger' ] ]
```

You can call methods of a service after generating it. For instance, you could call setters. You need to create a `calls` attribute and pass it a list of methods to be called. The first item is the method name and the second item is a list of parameters to pass to that method.

### Set a public property of a service

[](#set-a-public-property-of-a-service)

```
services:
    my_service:
        class: My\ClassName
        properties:
            foo: bar
            bar: "@baz"
```

Use the `properties` key to set a public property in a service.

### Aliases

[](#aliases)

```
services:
    my_service:
        class: My\ClassName
    my_alias:
        alias: my_service
```

You can build services alias using the `alias` attribute.

Alternatively, you can also use this syntax:

```
services:
    my_alias: "@my_service"
```

### Factories

[](#factories)

You can use factory methods of other services or classes to build your services.

**Static factories**

```
services:
    my_service:
        factory: My\ClassName::myMethod
```

The `my_service` instance will be returned from a call to `My\ClassName::myMethod`. You can even pass parameters to this method using the `arguments` attribute:

```
services:
    my_service:
        factory: My\ClassName::myMethod
        attributes: [ '@logger', 42 ]
```

You can also use this alternative syntax:

```
services:
    my_service:
        factory: [ 'My\ClassName', 'myMethod' ]
```

**Service based factories**

```
services:
    factory:
        class: My\Factory
    my_service:
        factory: factory:myMethod
```

The `my_service` instance will be returned from a call to `myMethod` on the service named `factory`. Notice how we used a single ':' instead of a double '::'.

You can also use this alternative syntax:

```
services:
    factory:
        class: My\Factory
    my_service:
        factory: 'My\ClassName@myMethod'
```

Noticeable differences with Symfony YAML services format
--------------------------------------------------------

[](#noticeable-differences-with-symfony-yaml-services-format)

- The keys are case sensitive
- Parameters do not accept references (no "@service" reference in the "parameters" section). They can only be scalars.
- These features are not supported:
    - tags
    - public/private services
    - shared services
    - synthetic services
    - lazy services
    - abstract services
    - file based services
    - deprecated services
    - decorated services
    - autowired services

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

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

Every ~14 days

Total

2

Last Release

3807d ago

Major Versions

0.1.0 → 1.0.x-dev2015-12-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

![](https://avatars.githubusercontent.com/u/1847918?v=4)[TheCodingMachine](/maintainers/thecodingmachine)[@thecodingmachine](https://github.com/thecodingmachine)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thecodingmachine-yaml-definition-loader/health.svg)

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

###  Alternatives

[getkirby/cms

The Kirby core

1.5k535.5k352](/packages/getkirby-cms)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)

PHPackages © 2026

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