usox/circulon

A PHP dependency resolver

1.0.0 2017-10-25 06:31 UTC

This package is auto-updated.

Last update: 2024-12-06 01:36:57 UTC


README

Build Status

Requirements

To use Circulon in your projects, you will just require PHP 5.6 or later.

Composer install

You can install this package by using Composer. Link to Packagist: https://packagist.org/packages/usox/circulon

composer require usox/circulon

Usage

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"
}

Circular dependencies

$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.