PHPackages                             flexsounds/slim-container-builder - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. flexsounds/slim-container-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

flexsounds/slim-container-builder
=================================

A light weight container builder from a configuration file

010[3 issues](https://github.com/leroy0211/Slim-Container-Builder/issues)PHP

Since Dec 9Pushed 9y ago1 watchersCompare

[ Source](https://github.com/leroy0211/Slim-Container-Builder)[ Packagist](https://packagist.org/packages/flexsounds/slim-container-builder)[ RSS](/packages/flexsounds-slim-container-builder/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/a8bd8078f20ff125b222149da70a2b1253c50e6f98897dbf51fd309353dcb917/68747470733a2f2f7472617669732d63692e6f72672f6c65726f79303231312f536c696d2d436f6e7461696e65722d4275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/leroy0211/Slim-Container-Builder)[![Packagist](https://camo.githubusercontent.com/3feb9c2dbdb1073bc00f6955703f8aab83af832ec50785b3d86d61e54e03ce18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c6578736f756e64732f736c696d2d636f6e7461696e65722d6275696c6465722e737667)](https://packagist.org/packages/flexsounds/slim-container-builder)![license](https://camo.githubusercontent.com/07a7767a6d0a426cf17c44de99d41a10077bcebd70af27c9f2b024c618990a99/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c65726f79303231312f536c696d2d436f6e7461696e65722d4275696c6465722e737667)[![Coverage Status](https://camo.githubusercontent.com/3fddaa2c006949b3abd2705b08704f4258e43bbe6ae3c26185a6983cf267cffa/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c65726f79303231312f536c696d2d436f6e7461696e65722d4275696c6465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/leroy0211/Slim-Container-Builder?branch=master)

Slim-Container-Builder
======================

[](#slim-container-builder)

A tool to build your Slim Framework 3 container. Instead of having to define your container in php, you just define it from a configuration file.

This will not replace the `pimple` container, but will build one for you.

Installation
============

[](#installation)

User composer to install

```
composer require flexsounds/slim-container-builder

```

Install `symfony/yaml` to use yaml files!

Default usage
=============

[](#default-usage)

This will create a slim framework container with your services defined in a configuration file.

```
$containerBuilder = new \Flexsounds\Slim\ContainerBuilder\ContainerBuilder();
$containerBuilder->setLoader($loader = new \Flexsounds\Slim\ContainerBuilder\Loader\FileLoader('./config'));
$loader->addFile("config.yml");
$app = new Slim\App($containerBuilder->getContainer());

// define your routes here.

$app->run();
```

Configuration file support
==========================

[](#configuration-file-support)

We use [hassankhan/config](https://github.com/hassankhan/config) to load the configuration, which has support for YML, XML, JSON and some more.

You can import other configuration files from a configuration file, independent of what file format.

```
# config.yml
imports:
  - { Resource: otherconfig.xml }
```

All examples are created in yaml notation!

Creating your services
======================

[](#creating-your-services)

The service configuration has almost the same notation as `Symfony` does. Which means you could copy your service configuration you built to a Symfony application (keep in mind, symfony has many more features than `Slim Container Builder`)

All your services must be defined under the `services` key and are shared throughout your entire application. The default services like `settings`, `request`, `response`, `router` etc. from Slim Framework are also available as service

Basic example
-------------

[](#basic-example)

Creating a service without any arguments is very simple.

```
services:
  my.custom.service:
    class: 'App\MyBasicService'
```

In your code you can use

```
$app->get('/', function($request, $response){
    $myCustomService = $this->get('my.custom.service');
    // $myCustomService is now an instance of 'App\MyBasicService'
});
```

Non-Shared services
-------------------

[](#non-shared-services)

All services are shared by default. Which means each time you retrieve the service, you get the same instance. When you want a new instance each time you call the service, use the `shared` key

```
services:
    my.nonshared.service:
        class: 'App\MyNonSharedService'
        shared: false
```

Dependency Injection
--------------------

[](#dependency-injection)

Some of your services might need some dependency injection, this could be done with the `arguments` key. You can inject anyting you want, even other services.

```
services:
  mailer:
    class: 'Location\To\Mailer'

  newslettermanager:
    class: 'App\Newsletter\NewsletterManager'
    arguments:
      - '@mailer'
```

```
namespace App\Newsletter;

use Location\To\Mailer;

class NewsletterManager {

    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }
}
```

Contributing
============

[](#contributing)

Read the [CONTRIBUTING](CONTRIBUTING.md) for details

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b82e8f8f4f040f19cbd9172d80a84a6e6d68912fa774b5675512dc1f3552f91?d=identicon)[devnul](/maintainers/devnul)

---

Top Contributors

[![leroy0211](https://avatars.githubusercontent.com/u/2051658?v=4)](https://github.com/leroy0211 "leroy0211 (21 commits)")

### Embed Badge

![Health badge](/badges/flexsounds-slim-container-builder/health.svg)

```
[![Health](https://phpackages.com/badges/flexsounds-slim-container-builder/health.svg)](https://phpackages.com/packages/flexsounds-slim-container-builder)
```

###  Alternatives

[tempusdominus/bootstrap-4

A date/time picker component designed to work with Bootstrap 4 and Momentjs.

6079.3k](/packages/tempusdominus-bootstrap-4)[superbig/craft3-mobiledetect

Use Mobile\_Detect for detecting mobile devices (including tablets)

1953.3k](/packages/superbig-craft3-mobiledetect)[sheadawson/silverstripe-responsive-wysiwyg-images

Extends silverstripe-responsive-images to allow responsive images in WYSIWYG editor.

111.6k](/packages/sheadawson-silverstripe-responsive-wysiwyg-images)

PHPackages © 2026

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