PHPackages                             theorx/sdic - 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. theorx/sdic

ActiveLibrary

theorx/sdic
===========

Simple dependency injection container

0.4.0(9y ago)073GPLv3PHPPHP &gt;=7

Since Dec 12Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (0)

Simple dependency injection container for PHP
=============================================

[](#simple-dependency-injection-container-for-php)

*There are many dependency injection containers out there, this one is minimalistic and straight forward. Doesn't have any third-party dependencies.*

[![Build Status](https://camo.githubusercontent.com/a1d604f887f1d93d60dc609f38fad243d9d4c06ff1cace9d68668df4cc45ce52/68747470733a2f2f7472617669732d63692e6f72672f7468656f72782f736469632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/theorx/sdic)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

Author
------

[](#author)

*Lauri Orgla *

Documentation
-------------

[](#documentation)

### Dependency registration usage

[](#dependency-registration-usage)

```
$container = new \Theorx\SDIC\SDIC();

//Register single dependency
$container->register(DependencyClassInterface::class, function(Theorx\SDIC\SDIC $container) {

    return new DependencyClass($container->get(DependencyClassDependency::class));
});
```

*Register shared dependency ( Singleton wrapper )*

```
$container->register(DependencyClassInterface::class, function(Theorx\SDIC\SDIC $container) {

    return $container->shared(DependencyClassInterface::class, function() {
        return new DependencyClass();
    });
});
```

*Register array of dependencies*

```
$container->registerArray([
    DependencyAInterface::class => function(){
        return new DependencyA();
    },
    DependencyBInterface::class => function (){
        return new DependencyB();
    }
]);
```

*You can check whether container contains dependency by name using **has** method*

```
if($container->has(DependencyAInterface::class)){
    //has dependency
}
```

*Getting dependencies from the container using **get** method*

```
$instance = $container->get(DependencyBInterface::class);
```

### Container extension

[](#container-extension)

*Container extensions are meant to be used for adding dependencies to the container**Container extensions must implement `SDICExtension` interface which requires you to implement single method for defining array of dependencies*

### Example extension

[](#example-extension)

```
/**
 * Class ExampleExtension
 */
class ExampleExtension implements \Theorx\SDIC\Interfaces\SDICExtension {

    /**
     * @return array
     */
    public function registerDependencies() : array {

        return [
            DependencyDInterface::class => function() {

                return new DependencyD();
            },
            DependencyEInterface::class => function() {

                return new DependencyE();
            }
            //...
        ];
    }
}
```

### Loading container extension / extensions

[](#loading-container-extension--extensions)

*Method `loadExtension` loads extension to the container and registers new dependencies*

```
$container->loadExtension(new ExampleExtension);
```

*For loading multiple extensions there is method `loadExtensions` which accepts array of objects which implement `SDICExtension` interface*

---

SDIC api overview
-----------------

[](#sdic-api-overview)

```

    /**
     * @author Lauri Orgla
     *
     *         Register name => callback,
     *         Callback example:
     *         function ($container) {
     *              return $container->shared(NAME, function($container){
     *                  return {{shared instance}};
     *              });
     *          }
     *
     *         This method is chainable, register()->register()->register()-> etc..
     *
     * @param string   $name
     * @param callable $callback
     *
     * @return SDIC
     */

```

- `register`(string $name, callable $callback) : SDIC

```
    /**
     * Accepts array of dependencies. Example. [name => callback]
     *
     * @author Lauri Orgla
     *
     * @param array $dependencies
     */

```

- `registerArray`(array $dependencies)

```
    /**
     * Used for creating shared instances
     *
     * @author Lauri Orgla
     *
     * @param string   $name
     * @param callable $callback
     *
     * @return mixed
     */

```

- `shared`(string $name, callable $callback)

```
    /**
     * Fetches dependency by name
     *
     * @author Lauri Orgla
     *
     * @param string $name
     *
     * @return mixed
     * @throws DependencyNotFoundException
     */

```

- `get`(string $name)

```
    /**
     * Checks whether the container has given dependency
     *
     * @author Lauri Orgla
     *
     * @param string $name
     *
     * @return bool
     */

```

- `has`(string $name)

```
    /**
     * Gets shared instances
     *
     * @author Lauri Orgla
     * @return array
     */

```

- `getInstances`()

```
    /**
     * Gets current registry
     *
     * @author Lauri Orgla
     * @return array
     */

```

- `getRegistry`()

```
    /**
     * Load container extension which is instance of class that implements SDICExtension
     *
     * @author Lauri Orgla
     *
     * @param SDICExtension $extension
     */

```

- `loadExtension`(SDICExtension $extension)

```
    /**
     * Loads a set of extensions
     *
     * @author Lauri Orgla
     *
     * @param array $extensions
     */

```

- `loadExtensions`(array $extensions)

```
    /**
     * Gets list of loaded extensions
     *
     * @author Lauri Orgla
     * @return SDICExtension[]
     */

```

- `getLoadedExtensions`() : array

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

5

Last Release

3431d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6234106acda5310e9f7d38f73e5451acc7bfef238d36ef2092f65f6607c3b11e?d=identicon)[theorx](/maintainers/theorx)

---

Top Contributors

[![theorx](https://avatars.githubusercontent.com/u/5157406?v=4)](https://github.com/theorx "theorx (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/theorx-sdic/health.svg)

```
[![Health](https://phpackages.com/badges/theorx-sdic/health.svg)](https://phpackages.com/packages/theorx-sdic)
```

PHPackages © 2026

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