PHPackages                             rstoetter/cdependencymanager-php - 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. rstoetter/cdependencymanager-php

ActiveLibrary

rstoetter/cdependencymanager-php
================================

A PHP class, which is able to resolve dependencies

v1.0.3(7y ago)010MITPHPPHP &gt;=7.0

Since May 27Pushed 7y agoCompare

[ Source](https://github.com/rstoetter/cdependencymanager-php)[ Packagist](https://packagist.org/packages/rstoetter/cdependencymanager-php)[ RSS](/packages/rstoetter-cdependencymanager-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (3)Used By (0)

The repository \\rstoetter\\cdependencymanager-php
==================================================

[](#the-repository-rstoettercdependencymanager-php)

Index
=====

[](#index)

[Description](#index_description)
---------------------------------

[](#description)

[Use Cases](#index_use_cases)
-----------------------------

[](#use-cases)

[Provided Classes](#index_classes)
----------------------------------

[](#provided-classes)

[Namespaces](#index_namespaces)
-------------------------------

[](#namespaces)

[Installation](#index_installation)
-----------------------------------

[](#installation)

[Usage Example](#index_example)
-------------------------------

[](#usage-example)

[More Informations](#index_informations)
----------------------------------------

[](#more-informations)

Description
-----------

[](#description-1)

The class **cDependencyManager** is a PHP class, which is able to resolve dependencies (ie between classes, URLs, HTML scripts .. ).

You feed the class with the known dependencies of the objects you are providing and it generates an array with the objects you provided now arranged in the correct order, which is defined by the dependencies between the specific objects

Use Cases
---------

[](#use-cases-1)

For example, if we want to create a HTML header, which loads the necessary modules in the correct order. One file after another and the dependant files should not be loaded until the files they are dependant from have been loaded.

In order to get the correct order you must not know the correct order. It is enough to know the implicit dependencies of each file. Therefore you provide the basic rules for the file ( it's unique key and the files it depends directly on) and the class cDependencyManager will then calculate the correct order of the whole dependency structure for you.

Provided Classes
----------------

[](#provided-classes-1)

The class \\rstoetter\\cdependencymanager\\cDependencyManager is the main class of the repository cdependencymanager-php.

There are no helper classes necessary in order to use the class cDependencyManager:

But you will need PHP 7 or later to use this repository

Namespace
---------

[](#namespace)

Use the [namespace](http://php.net/manual/en/language.namespaces.php) **rstoetter\\cdependencymanager** in order to access the classes provided by the repository cdependencymanager-php.

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

[](#installation-1)

The releases of the repository cdependencymanager-php are hosted by [Packagist](https://packagist.org), the main [composer](https://getcomposer.org/) repository. The repository assumes that you have composer installed. Simply add:

```
"require" : {

    "rstoetter/cdependencymanager-php" : ">=1.0.0"

}

```

to your **composer.json**, and then you can simply install it with the command:

```
composer install

```

Usage Example
-------------

[](#usage-example-1)

```
//
// First we define a class cMyDependantClass, which contains the information we need in our own project
// and add two public methods, the class cDependencyManager needs to manage the objects added:
// The method **GetDependencyCompareValue( )** returns a (commonly unique) value, which is used by
// the class cDependencyManager to distinguish between the objects of cMyDependantClass
// The method **DependsOn( )** returns true, if the current object depends on the Object provided as argument
//

class cMyDependantClass {

    // data our class is using

    protected $m_data_00 = null;
    protected $m_data_01 = null;

    //
    // extra data, which define the dependencies
    //

    // the url of the current module

    protected $m_url = '';

    // an array with urls of modules the current module is depending on

    protected $m_a_dependencies = array( );

    //
    //
    //

    function __construct(               // class cMyDependantClass
        string $url_module,             // the url of the current module
        array $a_urls = array( ),       // an array with urls of modules the current module is depending on
        $data_00 = null,
        $data_01 = null
    ) {

        $this->m_url = $url_module;
        $this->m_a_dependencies = $a_urls;
        $this->m_data_00 = $data_00;
        $this->m_data_01 = $data_01;

    }   // function __construct( )

    function __destruct( ) {            // class cMyDependantClass

        $this->m_a_dependencies = null;

    }   // function __destruct( )

    //
    // extra methods we need in order to enable the class cDependencyManagerto manage this object
    //

    public function GetDependencyCompareValue( ) {

        return $this->m_url;

    }   // function GetDependencyCompareValue( )

    public function DependsOn( cMyDependantClass $obj ) : bool {

        return in_array( $obj->GetDependencyCompareValue( ), $this->m_a_dependencies ) ;

    }   // function DependsOn( )

}   // class cMyDependantClass

//
// now let us create some objects representing modules
// we are not supplying the normal data for $m_data_00 and $m_data_01, in order to leave the code readable
// instead of supplying HTML URLs we are supplying strings, which make the dependencies clear
//

$obj_module_00 = new cMyDependantClass(
        '#01 file_without_dependencies'
);

$obj_module_01 = new cMyDependantClass(
        '#02 dependant from #1',
        array( '#01 file_without_dependencies' )
);

$obj_module_02 = new cMyDependantClass(
        '#03 dependant from #1',
        array( '#01 file_without_dependencies' )
);

$obj_module_03 = new cMyDependantClass(
        '#04 dependant from #3',
        array( '#03 dependant from #1' )
);

$obj_module_04 = new cMyDependantClass(
        '#05 dependant from #3',
        array( '#03 dependant from #1' )
);

$obj_module_05 = new cMyDependantClass(
        '#06 dependant from #2 and #3',
        array(
            '#03 dependant from #1',
            '#02 dependant from #1'
        )
);

$obj_module_06 = new cMyDependantClass(
        '#07 dependant from #2 and #3',
        array(
            '#03 dependant from #1',
            '#02 dependant from #1'
        )
);

$obj_module_07 = new cMyDependantClass(
        '#08 file_without_dependencies',
        array(  )
);

$obj_module_08 = new cMyDependantClass(
        '#09 dependant from #7',
        array( '#07 dependant from #2 and #3' )
);

$obj_module_09 = new cMyDependantClass(
        '#10 dependant from #7',
        array( '#07 dependant from #2 and #3' )
);

$obj_module_10 = new cMyDependantClass(
        '#11 dependant from #7',
        array( '#07 dependant from #2 and #3' )
);

$obj_module_11 = new cMyDependantClass(
        '#12 dependant from #9',
        array( '#09 dependant from #7' )
);

$obj_module_12 = new cMyDependantClass(
        '#13 dependant from #1',
        array( '#01 file_without_dependencies' )
);

$obj_module_13 = new cMyDependantClass(
        '#14 dependant from #1',
        array( '#01 file_without_dependencies' )
);

$obj_module_14 = new cMyDependantClass(
        '#15 file_without_dependencies',
        array( )
);

$obj_module_15 = new cMyDependantClass(
        '#16 file_without_dependencies'
);

$obj_module_16 = new cMyDependantClass(
        '#17 dependant from #7',
        array( '#07 dependant from #2 and #3' )
);

$obj_module_17 = new cMyDependantClass(
        '#18 dependant from #5 and #2',
        array(
            '#05 dependant from #3',
            '#02 dependant from #1'
        )
);

//
// after instantiating the module classes, we feed the class cDependencyManager with the modules
//

//
// create a new object of the class cDependencyManager
//
//
// For your convinience you could supply an **optional** array of objects as first parameter. The class cDependencyManager will then add
// the objects to this array
//

$a_optional = array(
    $obj_module_00,
    $obj_module_01,
    new cMyDependantClass(
        '#19 file_without_dependencies'
    )
);

// create a new dependency manager and feed the manager with the optional data

$obj_dependency_manager = new \rstoetter\cdependencymanager\cDependencyManager( $a_optional );

//
// feed the manager with the other data by calling it's method Add( )
// if the object added does not provide the expected methods or is not an object, the process will crash with an error message
// objects already added to the data base and null values will be ignored, in this case AddRule( ) will return false, otherwise true
//
// the second parameter is optional and defaults to true. If true, then the class cDependencyManager will abort, if the given object is
// not valid ( is not an object or does not provide the additional methods, the class cDependencyManagerneeds to handle the rule base ).
// If the value is false, then a warning message will be printed, when an object is not valid. In this case the invalid  object will be
// ignored by the class cDependencyManager. If an object cannot be added, then Add( ) returns false.
//

$obj_dependency_manager->AddRule( $obj_module_00 ); // ignored as the module was added already
$obj_dependency_manager->AddRule( $obj_module_01 ); // ignored as the module was added already
$obj_dependency_manager->AddRule( $obj_module_02 );
$obj_dependency_manager->AddRule( $obj_module_03 );
$obj_dependency_manager->AddRule( $obj_module_04 );
$obj_dependency_manager->AddRule( $obj_module_05 );
$obj_dependency_manager->AddRule( $obj_module_06 );
$obj_dependency_manager->AddRule( $obj_module_07 );
$obj_dependency_manager->AddRule( $obj_module_07 );  // ignored as the module was added already
$obj_dependency_manager->AddRule( $obj_module_08 );
$obj_dependency_manager->AddRule( $obj_module_09 );
$obj_dependency_manager->AddRule( $obj_module_10 );
$obj_dependency_manager->AddRule( $obj_module_11 );
$obj_dependency_manager->AddRule( $obj_module_12 );
$obj_dependency_manager->AddRule( $obj_module_13 );
$obj_dependency_manager->AddRule( $obj_module_14 );

//
// retrieve an array with the objects in the correct order from class cDependencyManager
// if you set the second parameter of the method GetDependencies( ) to true, then cDependencyManager will not reset the provided
// array and add the dependencies to the current content of tthe array
//

$a_obj_in_order = array( );
$obj_dependency_manager-> GetDependencies( $a_obj_in_order, false );

//
// print out the received list of objects
//

foreach( $a_obj_in_order as $obj_rule ) {
    echo PHP_EOL . $obj_rule->GetDependencyCompareValue( );
}

//
// end the program
//

die( PHP_EOL . PHP_EOL . " program finished in " . __FILE__ . ' on line ' . __LINE__  . PHP_EOL );
```

The code above will output the following result:

```
#08 file_without_dependencies
#19 file_without_dependencies
#16 file_without_dependencies
#15 file_without_dependencies
#01 file_without_dependencies
#13 dependant from #1
#03 dependant from #1
#02 dependant from #1
#14 dependant from #1
#04 dependant from #3
#05 dependant from #3
#06 dependant from #2 and #3
#07 dependant from #2 and #3
#18 dependant from #5 and #2
#10 dependant from #7
#11 dependant from #7
#17 dependant from #7
#09 dependant from #7
#12 dependant from #9

```

More Information
----------------

[](#more-information)

See the [project wiki of cdependencymanager-php](https://github.com/rstoetter/cdependencymanager-php/wiki) for more technical informations.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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 ~0 days

Total

2

Last Release

2903d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f638bd6cc066cad10d9187777df8782f4b4ccea4eb2b29ffac141d50744a557c?d=identicon)[rstoetter](/maintainers/rstoetter)

---

Top Contributors

[![rstoetter](https://avatars.githubusercontent.com/u/24063757?v=4)](https://github.com/rstoetter "rstoetter (15 commits)")

---

Tags

phpclassdependenciesdependency manager

### Embed Badge

![Health badge](/badges/rstoetter-cdependencymanager-php/health.svg)

```
[![Health](https://phpackages.com/badges/rstoetter-cdependencymanager-php/health.svg)](https://phpackages.com/packages/rstoetter-cdependencymanager-php)
```

###  Alternatives

[nunomaduro/mock-final-classes

Allows mocking of final methods and classes in PHP.

113854.3k23](/packages/nunomaduro-mock-final-classes)[nunomaduro/patrol

An elegant command-line tool that keeps your PHP Project's dependencies in check

271127.8k3](/packages/nunomaduro-patrol)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11812.0k](/packages/stefangabos-zebra-database)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

266.7k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

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