PHP Classes

PHP Dependency Resolver: Create class objects and others that it needs

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-05-07 (9 days ago) RSS 2.0 feedNot enough user ratingsTotal: 84 All time: 10,053 This week: 206Up
Version License PHP version Categories
dependency-resolver 1.0.3GNU General Publi...5.3PHP 5, Language, Design Patterns
Description 

Author

This class can create class objects and others that it needs.

It uses reflection to retrieve the information about a class and the parameters that it may need to pass on the constructor function.

If the constructor of the object to be created also needs objects of other classes, this class can also create objects of those other classes and pass them to the current object constructor.

The class may also pass values to the constructor of other types that were previous defined.

Picture of Vinicius Dias
Name: Vinicius Dias <contact>
Classes: 2 packages by
Country: Brazil Brazil

Documentation

Dependency Resolver

:stop_sign: Attention!

This project was built for educational purposes, therefore it should NOT run in production environments.

Description

This is a simple Dependency Resolver to resolve classes dependencies and instantiate them automagically.

Instalation

Install the latest version with:

$ composer require cviniciussdias/dependency-resolver

Usage

<?php
use CViniciusSDias\DependencyResolver\Resolver;

// Classes definitions
class Class1
{
    private $class2;

    public function __construct(Class2 $class, Class3 $class3)
    {
        echo $class3->method();
        $this->class2 = $class;
    }

    public function test()
    {
        echo $this->class2;
    }
}

class Class2
{
    public function __construct(Class3 $test, $param = 'default value')
    {
        echo $param . PHP_EOL;
    }

    public function __toString()
    {
        return 'Class2::__toString()';
    }
}

class Class3
{
    public function __construct($paramWithoutDefaulValue)
    {
    }

    public function method()
    {
        return 'Class3::method()' . PHP_EOL;
    }
}

// Resolver usage
$resolver = new Resolver();
$resolver->setParameters(Class3::class, ['paramWithoutDefaulValue' => 'manual value']);
$class1 = $resolver->resolve(Class1::class);
$class1->test();

Author

Vinicius Dias - [email protected] - https://github.com/CViniciusSDias/

License

This component is licensed under the GPL License


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
  Plain text file Resolver.php Class Class source
  Plain text file ResolverException.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:84
This week:0
All time:10,053
This week:206Up