To use Circulon in your projects, you will just require PHP 5.6 or later.
You can install this package by using Composer. Link to Packagist: https://packagist.org/packages/usox/circulon
composer require usox/circulon
Simply add your dependencies as follows:
$resolver = new \Usox\Circulon\Circulon();
$resolver
->addDependency('foo', 'bar')
->addDependency('foobar', [])
->addDependency('baz', [])
->addDependency('bar', ['baz', 'foobar']);
Calling resolve()
will return the dependencies in order.
$list = $resolver->resolve();
var_dump($list);
array(4) {
[0] =>
string(3) "baz"
[1] =>
string(6) "foobar"
[2] =>
string(3) "bar"
[3] =>
string(3) "foo"
}
$resolver
->addDependency('foo', 'bar')
->addDependency('bar', 'baz')
->addDependency('baz', 'foo');
$resolver->resolve();
Circulon detects the circular dependency and throws a CircularDependencyException
with message Circular reference for baz => foo
.