PHPackages                             italystrap/empress - 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. italystrap/empress

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

italystrap/empress
==================

Config driven for Auryn Injector the OOP way

2.0.0(4y ago)01.9k↓100%[1 PRs](https://github.com/ItalyStrap/empress/pulls)2MITPHPPHP &gt;=7.4

Since Jan 30Pushed 6mo ago1 watchersCompare

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

READMEChangelog (5)Dependencies (24)Versions (7)Used By (2)

ItalyStrap Empress API
======================

[](#italystrap-empress-api)

[![Build Status](https://github.com/ItalyStrap/empress/actions/workflows/test.yml/badge.svg)](https://github.com/ItalyStrap/empress/actions)[![Latest Stable Version](https://camo.githubusercontent.com/6b0f0b1a0b11b94ce125ce1c59052b765ff12ed753257a8056c8a92e6b65c533/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6974616c7973747261702f656d70726573732e737667)](https://packagist.org/packages/italystrap/empress)[![Total Downloads](https://camo.githubusercontent.com/435b033e105e069392d2307e5f8d1f9188f735b1c26e8b94ebb32951f167abaf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6974616c7973747261702f656d70726573732e737667)](https://packagist.org/packages/italystrap/empress)[![Latest Unstable Version](https://camo.githubusercontent.com/62b2b48eb4434bff8b50fcc4488aebbb99ca1b4cb2744f08eabd9d9a2e4dd98a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6974616c7973747261702f656d70726573732e737667)](https://packagist.org/packages/italystrap/empress)[![License](https://camo.githubusercontent.com/332b12e39aed71b60cca5956e3f64c05007e3b19f3ba03f19a014a6ce32dc2cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6974616c7973747261702f656d70726573732e737667)](https://packagist.org/packages/italystrap/empress)[![PHP from Packagist](https://camo.githubusercontent.com/3afebf210a8a0c7e9e8c0b95f9847bcd04072b6bab8c042d52c20c2f6ff21be6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6974616c7973747261702f656d7072657373)](https://camo.githubusercontent.com/3afebf210a8a0c7e9e8c0b95f9847bcd04072b6bab8c042d52c20c2f6ff21be6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6974616c7973747261702f656d7072657373)[![Scrutinizer code quality (GitHub/Bitbucket)](https://camo.githubusercontent.com/d3bf1c66fdfe389634cb901c90bd1d14be031d478f1b4ceffd72f2a5d78884a9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f4974616c7953747261702f656d70726573733f6c6162656c3d5363727574696e697a6572)](https://camo.githubusercontent.com/d3bf1c66fdfe389634cb901c90bd1d14be031d478f1b4ceffd72f2a5d78884a9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f4974616c7953747261702f656d70726573733f6c6162656c3d5363727574696e697a6572)

Config driven for [Auryn Injector](https://github.com/rdlowrey/auryn) the OOP way

In this library it is also included a bridge for the [Auryn\\Injector](https://github.com/rdlowrey/auryn) and [ProxyManager](https://github.com/Ocramius/ProxyManager) for lazily initializes a "real" instance of the proxied class.

**This library is still a WIP (work in progres)**

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Contributing](#contributing)
- [License](#license)
- [Notes](#notes)
- [Credits](#credits)

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

[](#installation)

The best way to use this package is through Composer:

```
composer require italystrap/empress
```

This package adheres to the [SemVer](http://semver.org/) specification and will be fully backward compatible between minor versions.

Basic Usage
-----------

[](#basic-usage)

> For more information on how to use Auryn\\Injector see the [Auryn README](https://github.com/rdlowrey/auryn/blob/master/README.md)

Keep in mind that `$injector->(SomeClass::class)` hides the word `new` and does the instantiation for you.

Do not use Injector as a service locator or your server will blown up.

```
namespace MyApp;

use ItalyStrap\Config\Config;
use ItalyStrap\Config\ConfigFactory;
use ItalyStrap\Config\ConfigInterface;
use ItalyStrap\Empress\AurynConfigInterface;
use ItalyStrap\Empress\AurynConfig;
use ItalyStrap\Empress\Extension;
use ItalyStrap\Empress\Injector;

/**
 * The better way to add keys to the array configuration is to use the
 * AurynResolver::
 *
 * Keys available are:
 *
 * AurynResolver::PROXY = 'proxies';
 * AurynResolver::SHARING = 'sharing';
 * AurynResolver::ALIASES = 'aliases';
 * AurynResolver::DEFINITIONS = 'definitions';
 * AurynResolver::DEFINE_PARAM = 'define_param';
 * AurynResolver::DELEGATIONS = 'delegations';
 * AurynResolver::PREPARATIONS = 'preparations';
 */

/**
 * First off all we need a configuration
 */
$config = [

	/**
	 * Example:
	 * class MyCLass( ConfigInterface $config ) {}
	 * You alias a `ConfigInterface::class` to `Config::class`
	 * $injector->make(MyCLass::class); will be injected with a Config object
	 * @see [Type-Hint Aliasing](https://github.com/rdlowrey/auryn#type-hint-aliasing)
	 */
	AurynConfig::ALIASES		=> [
		ConfigInterface::class	=> Config::class,
	],

	/**
	 * Example:
	 * class MyCLass( ConfigInterface $global_config, \stdClass $class ) {}
	 * class MyOtherCLass( ConfigInterface $global_config, \stdClass $class ) {}
	 * A new Config instance will be shared, think of it like a singleton but more better and OOP oriented (You can mock it ;-))
	 * The same instance of Config will be injected to MyCLass and MyOtherCLass
	 * $injector->make(MyCLass::class); // Will have $global_config
	 * $injector->make(MyOtherCLass::class); // Will have $global_config
	 * @see [Instance Sharing](https://github.com/rdlowrey/auryn#instance-sharing)
	 */
	AurynConfig::SHARING		=> [
		stdClass::class,
		ConfigInterface::class,
	],

	/**
	 * This is the new feature for the Auryn\Injector implemented in the bridge adapter
	 * You usually need a lazy value holder in cases where the following applies:
	 *  * your object takes a lot of time and memory to be initialized (with all dependencies)
	 *  * your object is not always used, and the instantiation overhead is avoidable
	 *
	 * Example:
	 * class HeavyComplexObject( ...HeavyDependency ){}; // Declared somewhere
	 * $object = $injector->make(HeavyComplexObject::class);
	 * add_{filter|action}( 'event_name', [ $object, 'doSomeStuff' ] );
	 *
	 * You can proxies the `HeavyComplexObject::class` dependency
	 * $injector->proxy(HeavyDependency::class);
	 * Or the `HeavyComplexObject::class`
	 * $injector->proxy(HeavyComplexObject::class);
	 *
	 * It depends on your business logic.
	 *
	 * Let see for example if you have proxies the HeavyComplexObject::class
	 *
	 * $proxy = $injector->make(HeavyComplexObject::class);
	 *
	 * Now $proxy will be the lazy version of the object (as a proxy) and when the event call it
	 * add_{filter|action}( 'event_name', [ $proxy, 'doSomeStuff' ] );
	 * ::doSomeStuff() will just work as before.
	 *
	 * @see [Lazy Loading Value Holder Proxy](https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.md)
	 */
	AurynConfig::PROXY		=> [
		Config::class,
	],

	/**
	 * Define global parameter
	 * class SomeCLass(string $text) {}
	 * class SomeOtherCLass(string $text) {}
	 * $injector->make(SomeCLass::class);
	 * $injector->make(SomeOtherCLass::class);
	 * Now the `$text` param will be decorated with 'Some Text'
	 * @see [Global Parameter Definitions](https://github.com/rdlowrey/auryn#global-parameter-definitions)
	 */
	AurynConfig::DEFINE_PARAM	=> [
		'text'	=> 'Some Text'
	],

	/**
	 * Definition for class specific
	 * Example:
	 * class Example(int $param) {}
	 * Now the `$param` will be decorated with 42
	 * class OtherExample(int $param) {}
	 * This will not be decorated with 42 because you have defined only the Example::class parameter
	 * @see [Injection Definitions](https://github.com/rdlowrey/auryn#injection-definitions)
	 */
	AurynConfig::DEFINITIONS	=> [
		Example::class	=> [
			':param'	=> 42,
		]
	],

	/**
	 * As soon as the instance is created you can prepare some action before use the new created instance
	 * This is the same as:
	 * $class = new \stdClass;
	 * $class->param = 42;
	 * echo $class->param;
	 * @see [Prepares and Setter Injection](https://github.com/rdlowrey/auryn#prepares-and-setter-injection)
	 */
	AurynConfig::PREPARATIONS	=> [
		stdClass::class	=> function ( stdClass $class, Injector $injector ) {
			$class->param = 42;
		},
	],

	/**
	 * You can delegate the instantiation of an object to a some kind of callable factory
	 * This will be always used to get the instance of a class.
	 * @see [Instantiation Delegates](https://github.com/rdlowrey/auryn#instantiation-delegates)
	 */
	AurynConfig::DELEGATIONS	=> [
		ConfigInterface::class	=> [ ConfigFactory::class, 'make']
	],
];

/**
 * Instantiate the Injector
 * Remember that ItalyStrap\Empress\Injector() is the extended class with the proxy functionality
 * The superclass \Auryn\Injector() does not have the ProxyManager in it.
 */
$injector = new \ItalyStrap\Empress\Injector();

/**
 * Pass the $injector instance to the AurynResolver::class as first parameter and a
 * Config::class instance at the second parameters with the configuration array.
 */
$app = new AurynConfig( $injector, ConfigFactory::make( $config ) );

/**
 * Call the AurynResolver::resolve() method to do the autowiring of the application
 */
$app->resolve();

/**
 * Now that you have autoload your application dependency you can call $injector for instantiating objects
 * when you need them
 */
$example = $injector->make( Example::class );
// $example instanceof Example::class
```

Advanced Usage
--------------

[](#advanced-usage)

```
namespace MyApp;

use ItalyStrap\Config\Config;
use ItalyStrap\Config\ConfigFactory;
use ItalyStrap\Config\ConfigInterface;
use ItalyStrap\Empress\AurynConfigInterface;
use ItalyStrap\Empress\AurynConfig;
use ItalyStrap\Empress\Extension;
use ItalyStrap\Empress\Injector;

$config = [
    'your-key'	=> [
        'Key' => 'Value',
    ],
];

$injector = new \ItalyStrap\Empress\Injector();
$app = new AurynConfig( $injector, ConfigFactory::make( $config ) );

/**
 * If you need more power you can extend the AurynResolver::class BEFORE calling the AurynResolver::resolve() method
 * Create your custom configuration like the follow:
 * $config = [
 * 	'your-key'	=> [
 * 		'Key' => 'Value',
 *  ],
 * ];
 *
 * Now extend the AurynResolver:
 */
$app->extend(
	new class implements Extension {

		/** @var string */
		const YOUR_KEY = 'your-key';

		public function name(): string {
			return (string) self::YOUR_KEY;
		}

		/**
		 * Called inside the AurynResolver instance
		 * @param AurynConfigInterface $application
		 */
		public function execute( AurynConfigInterface $application ) {

			/**
			 * ::walk() accept:
			 * self::YOUR_KEY will be a key to search against the config array
			 * [ $this, 'doSomeStuff' ] will be a valid callable to do the work you need.
			 */
			$application->walk( (string) self::YOUR_KEY, [$this, 'doSomeStuff'] );
		}

		/**
		 * @param string     $array_value Array value from yous configuration
		 * @param int|string $array_key   Array key from your configuration
		 * @param Injector   $injector    An instance of the Injector::class
		 */
		public function doSomeStuff( string $array_value, $array_key, Injector $injector ) {
			// Do your logic here
		}
	}
);

/**
 * You can add as many extensions as you need
 * Now you can call the ::resolve() method
 */
$app->resolve();

// Do the rest of your stuff
```

Contributing
------------

[](#contributing)

All feedback / bug reports / pull requests are welcome.

License
-------

[](#license)

Copyright (c) 2019 Enea Overclokk, ItalyStrap

This code is licensed under the [MIT](LICENSE).

Notes
-----

[](#notes)

- Maintained under the [Semantic Versioning Guide](http://semver.org)

Credits
-------

[](#credits)

- [`rdlowrey/auryn`](https://github.com/rdlowrey/auryn)
- [`brightnucleus/injector`](https://github.com/brightnucleus/injector)

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance49

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

5

Last Release

1684d ago

Major Versions

1.1.0 → 2.0.02021-09-27

PHP version history (2 changes)1.0.0PHP &gt;=7.2

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/13d145319a065be260ee79e728655780ddd63002e5ac6c317701c8996ec8d94c?d=identicon)[overclokk](/maintainers/overclokk)

---

Top Contributors

[![overclokk](https://avatars.githubusercontent.com/u/4604932?v=4)](https://github.com/overclokk "overclokk (80 commits)")

---

Tags

injectorphp-librarywordpress-php-library

###  Code Quality

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/italystrap-empress/health.svg)

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

###  Alternatives

[wallabag/wallabag

open source self hostable read-it-later web application

12.6k2.2k](/packages/wallabag-wallabag)[ezsystems/ez-support-tools

Providing information about the system eZ Platform/Enterprise/Commerce is running on, and eZ install itself

44979.6k18](/packages/ezsystems-ez-support-tools)[bitexpert/disco

Dependency Injection Container

1401.8k3](/packages/bitexpert-disco)[honeybee/honeybee

Library for implementing CQRS driven, event-sourced and distributed architectures.

222.1k4](/packages/honeybee-honeybee)[meklis/switcher-core

SNMP switcher core module

181.6k](/packages/meklis-switcher-core)

PHPackages © 2026

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