PHPackages                             kaiseki/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. kaiseki/container-builder

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

kaiseki/container-builder
=========================

Create a PSR-11 container with laminas-servicemanager with laminas-di

2.0.0(1mo ago)01.2kMITPHPPHP ^8.2CI passing

Since Feb 6Pushed 3w ago2 watchersCompare

[ Source](https://github.com/kaisekidev/kaiseki-container-builder)[ Packagist](https://packagist.org/packages/kaiseki/container-builder)[ Docs](https://github.com/kaisekidev/kaiseki-container-builder)[ RSS](/packages/kaiseki-container-builder/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (26)Versions (9)Used By (0)

kaiseki/container-builder
=========================

[](#kaisekicontainer-builder)

*Create a PSR-11 dependency injection container with laminas-servicemanager and laminas-di*

---

Table of Contents
-----------------

[](#table-of-contents)

- [kaiseki/container-builder](#kaisekicontainer-builder)
    - [Table of Contents](#table-of-contents)
    - [Summary](#summary)
    - [Why you should use it?](#why-you-should-use-it)
    - [Technical Details](#technical-details)
    - [Usage (in a WordPress theme)](#usage-in-a-wordpress-theme)
        - [Installation](#installation)
        - [Setup](#setup)
        - [Config Providers](#config-providers)

Summary
-------

[](#summary)

This package is a bare-bone implementation that allows you to set up a dependency injection (DI) container quickly and easily. Use this package to build high-quality WordPress themes and plugins with modern PHP development methods.

It's not limited to WordPress though. That's just what we use it for. You can technically utilize it wherever you want.

Why you should use it?
----------------------

[](#why-you-should-use-it)

While it may be daunting or seem like overhead at a first glance to use a DI container, it has many advantages. Once you clear the first hurdle of learning the basics, you will never want to go back doing things the *old* way.

To counter your first concern: **No, this is not a framework.** This package is simply a ready-to-use implementation to get you going with writing clean and awesome quality-code quickly. What you make of it is up to you.

But let's get back to the advantages of using a DI container:

1. Firstly, you'll learn how to become a better developer.
2. You will create cleaner and more readable code.
3. Become more productive by creating reusable packages.
4. Maintaining large projects becomes much easier.
5. Your code will be more testable.

Technical Details
-----------------

[](#technical-details)

**Important:** You will need [composer](https://getcomposer.org/) and set up [autoloading](https://getcomposer.org/doc/01-basic-usage.md#autoloading) to use this package.

The container builder creates a [PSR-11](http://www.php-fig.org/psr/psr-11/) container, configured to use [laminas-servicemanager](https://docs.laminas.dev/laminas-servicemanager) and [laminas-di](https://docs.laminas.dev/laminas-di).

After you have set up the autoloading and use the container builder you are ready to use dependency injection in your code.

What does the DI container do for you:

- Have it autowire your classes and packages for you.
- Require and use third-party composer packages quickly to easily extend your code.
- Reuse code you have already written.
- Create your desired namespaces and folder structure without any restrictions (other than conforming to [PSR-4](https://www.php-fig.org/psr/psr-4/)) and everything will work out of the box.
- Enjoy advanced code completion inside your IDE.
- Centralize your configuration instead of having it scattered all over the project.

Usage (in a WordPress theme)
----------------------------

[](#usage-in-a-wordpress-theme)

We'll explain the usage of this package inside a WordPress theme.

Typically `kaiseki/container-builder` is used in combination with packages that provide [**ConfigProviders**](#config-providers). [**ConfigProviders**](#config-providers) are simple callables without dependencies, that return a config array.

In our example we additionaly set up the [kaiseki/wp-hook](https://github.com/kaisekidev/kaiseki-wp-hook) package, that we use in many projects ourselves. It helps us to quickly register packages that will automatically set themselves up by hooking into WordPress actions and filters. This step is purely optional.

### Installation

[](#installation)

```
composer require kaiseki/container-builder
```

### Setup

[](#setup)

Add this to the top of your theme's `functions.php` file:

```
