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.
You can install this package through Composer:
{
"require": {
"thecodingmachine/yaco": "~1.0"
}
}
The packages adheres to the SemVer specification, and there will be full backward compatibility between minor versions.
This package contains a Compiler
class. The goal of this class is to take a number of "entry definitions"
(as defined in definition-interop) and to transform those
into a PHP class that implements the ContainerInterface
use TheCodingMachine\Yaco\Compiler;
$compiler = new Compiler();
// ...
foreach ($definitions as $definition) {
/* @var $definition Interop\Container\Definition\DefinitionInterface */
$compiler->addDefinition($definition);
}
// Let's dump the code of the My\Container class.
file_put_contents("Container.php", $compiler->compile("My\\Container"));
You can also 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"));