PHPackages                             thecodingmachine/yaco - 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. thecodingmachine/yaco

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

thecodingmachine/yaco
=====================

YACO (Yet Another COmpiler) is a PHP tool that generates a PHP container based on entry definitions.

v1.0.0(10y ago)113271[1 issues](https://github.com/thecodingmachine/yaco/issues)1MITPHP

Since Aug 17Pushed 7y ago5 watchersCompare

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

READMEChangelog (4)Dependencies (8)Versions (11)Used By (1)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/46b96a53562db7e9b67f83760de6ed129e2bb991b95f262ce082ad01ecb26364/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f7961636f2f6261646765732f7175616c6974792d73636f72652e706e673f623d312e32)](https://scrutinizer-ci.com/g/thecodingmachine/yaco/?branch=1.2)[![Build Status](https://camo.githubusercontent.com/81cc28d2c21d250f7a57ee99168c5a8ec8d5806d0b3361ec95e42745f2a3d13c/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f7961636f2e7376673f6272616e63683d312e32)](https://travis-ci.org/thecodingmachine/yaco)[![Coverage Status](https://camo.githubusercontent.com/e67e757057e47a1e144d2195f353352f64481c20ef7ef488cebdd71f7c918ed7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f7961636f2f62616467652e7376673f6272616e63683d312e3226736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/yaco?branch=1.2)

YACO - Yet another compiler
===========================

[](#yaco---yet-another-compiler)

YACO (Yet Another COmpiler) is a PHP tool that generates a PHP container based on entry definitions. It is fully compatible with entry definitions from [*definition-interop*](https://github.com/container-interop/definition-interop/).

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

[](#installation)

You can install this package through Composer:

```
{
    "require": {
        "thecodingmachine/yaco": "^1.2"
    }
}
```

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

Usage
-----

[](#usage)

This package contains a `Compiler` class. The goal of this class is to take a number of "entry definitions" (as defined in [*definition-interop*](https://github.com/container-interop/definition-interop/)) and to transform those into a PHP class that implements the [`ContainerInterface`](https://github.com/container-interop/container-interop/)

```
use TheCodingMachine\Yaco\Compiler;

$compiler = new Compiler();

// ...

foreach ($definitions as $identifier => $definition) {
    /* @var $definition Interop\Container\Definition\DefinitionInterface */
    $compiler->addDefinition($identifier, $definition);
}

// Let's dump the code of the My\Container class.
file_put_contents("Container.php", $compiler->compile("My\\Container"));
```

Now, you can instantiate your container using this code:

```
$container = new My\Container();

$service = $container->get('a_service');
```

Note: Yaco is consuming **container definitions** (implementing `Interop\Container\Definition\DefinitionInterface`). Out of the box, Yaco does not provide any classes implementing this interface. However, you can find such classes in a package like [mnapoli/assembly](https://github.com/mnapoli/assembly).

Here is a complete sample using Yaco and Assembly:

**Compile phase:**

```
use TheCodingMachine\Yaco\Compiler;
use function \Assembly\object;
use function \Assembly\alias;

$compiler = new Compiler();

$loggerDefinition = object('MyLogger')
    ->setConstructorArguments('warning')
    ->addMethodCall('setDebug', true);

$compiler->addDefinition('logger', $loggerDefinition);

// Let's dump the code of the My\Container class.
file_put_contents("Container.php", $compiler->compile("My\\Container"));
```

**Usage:**

```
require_once('Container.php');

$container = new My\Container();
$logger = $container->get('logger');
```

Note: the `My\Container` class implements the `Interop\Container\ContainerInterface`. Therefore, it can be used with any framework compatible with container-interop.

Service provider support
------------------------

[](#service-provider-support)

This package supports container agnostic service providers as defined in [*container-interop/service-provider*](https://github.com/container-interop/service-provider).

To register service providers, you must pass to the compiler a `TheCodingMachine\ServiceProvider\Registry` object.

Here is a sample:

```
use TheCodingMachine\Yaco\Compiler;
use TheCodingMachine\ServiceProvider\Registry;

$registry = new Registry([
    MyServiceProvider::class
]);

// The registry is passed as first argument to the compiler.
$compiler = new Compiler($registry);

// Let's dump the code of the My\Container class.
file_put_contents("MyContainer.php", $compiler->compile("MyContainer"));
```

Important! When you want to use the compiled container, you have to pass **a registry containing the same service providers**, in the same order.

Below is an instantiation of the container generated by the code above:

```
use TheCodingMachine\ServiceProvider\Registry;

$registry = new Registry([
    MyServiceProvider::class
]);

// The registry is passed as first argument to the compiler.
$container = new MyContainer($registry);

$service = $container->get('a_service');
```

Miscellaneous
-------------

[](#miscellaneous)

### Delegate lookup support

[](#delegate-lookup-support)

Containers generated by Yaco support the ["delegate lookup" feature](https://github.com/container-interop/container-interop/blob/master/docs/Delegate-lookup.md) of container-interop.

If you pass a container as the second argument to the generated container, all dependency lookups will be done on the passed container rather than on the generated container.

Here is a sample:

```
// $rootContainer is a composite container from the acclimate library
$rootContainer = new Acclimate\CompositeContainer();

$myContainer = new MyContainer(null, $rootContainer);

$rootContainer->addContainer($myContainer);
```

### Definition providers

[](#definition-providers)

You can directly register a **definition provider** using the `register` method:

```
use TheCodingMachine\Yaco\Compiler;

$compiler = new Compiler();

// ...

$compiler->register($definitionProvider);

// Let's dump the code of the My\Container class.
file_put_contents("Container.php", $compiler->compile("My\\Container"));
```

Definition providers are classes implementing the `Interop\Container\Definition\DefinitionProviderInterface`. They provide a list of container definitions to be compiled by the compiler.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~111 days

Recently: every ~228 days

Total

11

Last Release

2815d ago

Major Versions

v0.4.0 → v1.0.02016-03-01

v0.4.1 → 1.0.x-dev2016-03-01

### Community

Maintainers

![](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 (62 commits)")[![nguyenk](https://avatars.githubusercontent.com/u/2227554?v=4)](https://github.com/nguyenk "nguyenk (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thecodingmachine-yaco/health.svg)

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

###  Alternatives

[api-clients/command-bus

Light weight wrapper around league/tactician adding promised based interface(s) and next tick execution

11196.7k4](/packages/api-clients-command-bus)[michaels/data-manager

Simple data manager for nested data, dot notation array access, extendability, and container interoperability.

121.9k2](/packages/michaels-data-manager)

PHPackages © 2026

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