PHPackages                             alicemajere/wonderland-container - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. alicemajere/wonderland-container

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

alicemajere/wonderland-container
================================

A small simple service container to include in projects

1.1.0(7y ago)16[1 issues](https://github.com/AliceMajere/wonderland-container/issues)MITPHPPHP &gt;=7.2

Since Oct 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/AliceMajere/wonderland-container)[ Packagist](https://packagist.org/packages/alicemajere/wonderland-container)[ RSS](/packages/alicemajere-wonderland-container/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/c37a0325a38122b427067d790c50b20a37101d366f168407dafc503d3d58a2c5/68747470733a2f2f7472617669732d63692e6f72672f416c6963654d616a6572652f776f6e6465726c616e642d636f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AliceMajere/wonderland-container)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/652b0bd71339cf3c489371cd5a31d049fc85aceee6383220e03778d9511b7655/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f416c6963654d616a6572652f776f6e6465726c616e642d636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/AliceMajere/wonderland-container/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/06d305d09db9ec3f1cc01f80fed2caea5cd1d6d1e1da5a5e4a4d0ec412825355/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f416c6963654d616a6572652f776f6e6465726c616e642d636f6e7461696e65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/AliceMajere/wonderland-container/?branch=master)[![Code Intelligence Status](https://camo.githubusercontent.com/6fb1cbdd71b9ef8b65be8de0d06da6b8d64d456fa5626dae01a4fc12c894025f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f416c6963654d616a6572652f776f6e6465726c616e642d636f6e7461696e65722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![License](https://camo.githubusercontent.com/e3b314623eb9209eb5dceaca5b4d19123b8c5b81a0fa448bbad7336e256ed857/68747470733a2f2f706f7365722e707567782e6f72672f616c6963656d616a6572652f776f6e6465726c616e642d636f6e7461696e65722f6c6963656e7365)](https://packagist.org/packages/alicemajere/wonderland-container)

Wonderland Container
====================

[](#wonderland-container)

A small simple service container to include in projects

Recent Update
-------------

[](#recent-update)

Update 1.1.0 available. Check the [release page](https://github.com/AliceMajere/wonderland-container/releases) for the changelog

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

[](#installation)

```
composer require alicemajere/wonderland-container

```

Usage
-----

[](#usage)

### Initializing the container

[](#initializing-the-container)

Create a new instance of the container

```
$container = new Wonderland\Container\Container();
```

Create a new service definition and register it in the container with the following parameters

- \[STRING\] service name
- \[STRING\] class name
- \[ARRAY\] constructor parameters
- \[ARRAY\] methods calls with their arguments. The index is the method name, the value is the array of the method parameters

```
// creating a service definition
$definition = new Wonderland\Container\Service\ServiceDefinition(
    'service.name',
    MyClass::class,
    ['args1', '@service.name2', ['array_args']],
    ['methodCall1' => ['args1', '@service.name3']]
);

// register the definition into the container
$container->addService($definition);
```

You can also create a new service by directly injecting an object instance

```
$instance = new MyClass();
$serviceInstance = new Wonderland\Container\Service\InstanceDefinition(
    'service.name2',
    $instance
);

// register the instance definition into the container
$container->addServiceInstance(serviceInstance);
```

### Using the container

[](#using-the-container)

To check if a service exists into the container

```
if ($container->has('service.name')) {
    // code here
}
```

To retrieve the service instance

```
// retrieve the instance. Will create a new one if not created yet. Shared by default
$instance = $container->get('service.name');

// retrieve a new instance of the service. Setting the second parameters to true will not retrieve the shared service
 instance
$newInstance = $container->get('service.name', true);

// retrieve the instance of the instance service definition. Setting the second parameter to true will do nothing if
// the service is not a definition service but a instance definition service; only the shared instance will be retrieved
$instance = $container->get('service.name2');
```

### Loading configuration with YAML files

[](#loading-configuration-with-yaml-files)

```
$container = new \Wonderland\Container\ServiceContainer();
$serviceLoader = new \Wonderland\Container\Configuration\ServiceLoader(new YamlParser());
// load every yml in a folder
$container->loadServices($serviceLoader->loadDirectory(__DIR__ . '/Resource/'));
// or a single file
$container->loadServices($serviceLoader->loadFile(__DIR__ . '/Resource/test.yml'));
```

Yaml file examples

```
services:
    service.name:
        class: Wonderland\Container\Example\Yml\SampleClass
        arguments:
            - 'param1'
            - 'param2'
        calls:
            callMethod:
                - 'param11'
                - '@service.name3'
    service.name2:
        class: Wonderland\Container\Example\Yml\SampleClass
        arguments:
            - 'param3'
            - 'param4'
        calls:
            callMethod:
                - '@service.name'
                - 'param44'

    service.name3:
        class: \DateTime
```

Examples
--------

[](#examples)

You can check out the `examples` folder for more running examples of the library.

Prerequisites
-------------

[](#prerequisites)

PHP &gt;= 7.2

Getting help
------------

[](#getting-help)

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Authors
-------

[](#authors)

- **Alice Praud** - *Initial work* - [AliceMajere](https://github.com/AliceMajere/wonderland-container/)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

2760d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16051792?v=4)[AliceMajere](/maintainers/AliceMajere)[@AliceMajere](https://github.com/AliceMajere)

---

Top Contributors

[![AliceMajere](https://avatars.githubusercontent.com/u/16051792?v=4)](https://github.com/AliceMajere "AliceMajere (27 commits)")

---

Tags

service-containeryaml

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/alicemajere-wonderland-container/health.svg)

```
[![Health](https://phpackages.com/badges/alicemajere-wonderland-container/health.svg)](https://phpackages.com/packages/alicemajere-wonderland-container)
```

###  Alternatives

[wikimedia/parsoid

Parsoid, a bidirectional parser between wikitext and HTML5

171524.3k1](/packages/wikimedia-parsoid)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

14440.0k8](/packages/symfony-json-streamer)[prohalexey/the-choice

253.3k](/packages/prohalexey-the-choice)[sspooky13/yaml-standards

Standards for yaml files

11518.3k3](/packages/sspooky13-yaml-standards)[opensoft/simple-serializer

Simple Serializer

1914.2k1](/packages/opensoft-simple-serializer)

PHPackages © 2026

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