PHPackages                             maksimovic/auryn - 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. [Framework](/categories/framework)
4. /
5. maksimovic/auryn

ActiveLibrary[Framework](/categories/framework)

maksimovic/auryn
================

PHP 8.1-8.5 compatible fork of rdlowrey/auryn — a dependency injector for bootstrapping object-oriented PHP applications.

1.5.1(1mo ago)01.1k↑120.5%MITPHPPHP ^8.1CI passing

Since Apr 29Pushed 1mo agoCompare

[ Source](https://github.com/maksimovic/auryn)[ Packagist](https://packagist.org/packages/maksimovic/auryn)[ Docs](https://github.com/maksimovic/auryn)[ RSS](/packages/maksimovic-auryn/feed)WikiDiscussions 1.5.x Synced 1w ago

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

auryn [![CI](https://github.com/maksimovic/auryn/actions/workflows/ci.yml/badge.svg?branch=1.5.x)](https://github.com/maksimovic/auryn/actions/workflows/ci.yml)
================================================================================================================================================================

[](#auryn-)

auryn is a recursive dependency injector. Use auryn to bootstrap and wire together S.O.L.I.D., object-oriented PHP applications.

> **About this fork.** `maksimovic/auryn` is a maintained fork of [`rdlowrey/auryn`](https://github.com/rdlowrey/auryn) that targets PHP 8.1–8.5. Upstream has not been tagged past `v1.4.4`, which predates the PHP 8.4 deprecation fix. This fork starts from the upstream `master` tip (`895d666`), bumps the minimum PHP to 8.1, moves the test suite to PHPUnit 10, and runs CI against PHP 8.1, 8.2, 8.3, 8.4, and 8.5. The package declares `replace: { "rdlowrey/auryn": "^1.4.4" }`, so transitive consumers that require `rdlowrey/auryn` resolve cleanly. The library API is unchanged.

##### How It Works

[](#how-it-works)

Among other things, auryn recursively instantiates class dependencies based on the parameter type-hints specified in class constructor signatures. This requires the use of Reflection. You may have heard that "reflection is slow". Let's clear something up: *anything* can be "slow" if you're doing it wrong. Reflection is an order of magnitude faster than disk access and several orders of magnitude faster than retrieving information (for example) from a remote database. Additionally, each reflection offers the opportunity to cache the results if you're worried about speed. auryn caches any reflections it generates to minimize the potential performance impact.

> auryn **is NOT** a Service Locator. DO NOT turn it into one by passing the injector into your application classes. Service Locator is an anti-pattern; it hides class dependencies, makes code more difficult to maintain and makes a liar of your API! You should *only* use an injector for wiring together the disparate parts of your application during your bootstrap phase.

The Guide
---------

[](#the-guide)

**Basic Usage**

- [Basic Instantiation](#basic-instantiation)
- [Injection Definitions](#injection-definitions)
- [Type-Hint Aliasing](#type-hint-aliasing)
- [Non-Class Parameters](#non-class-parameters)
- [Global Parameter Definitions](#global-parameter-definitions)

**Advanced Usage**

- [Instance Sharing](#instance-sharing)
- [Instantiation Delegates](#instantiation-delegates)
- [Prepares and Setter Injection](#prepares-and-setter-injection)
- [Injecting for Execution](#injecting-for-execution)
- [Dependency Resolution](#dependency-resolution)

**Example Use Cases**

- [Avoiding Evil Singletons](#avoiding-evil-singletons)
- [Application Bootstrapping](#app-bootstrapping)

Requirements and Installation
-----------------------------

[](#requirements-and-installation)

- auryn requires PHP 8.1 or higher.

#### Installation

[](#installation)

###### Github

[](#github)

You can clone the latest auryn iteration at anytime from the github repository:

```
$ git clone https://github.com/maksimovic/auryn.git
```

###### Composer

[](#composer)

You may also use composer to include auryn as a dependency in your projects `composer.json`. The relevant package is `maksimovic/auryn`, which `replace`s `rdlowrey/auryn ^1.4.4` so that transitive consumers continue to resolve correctly.

Alternatively require the package using composer cli:

```
composer require maksimovic/auryn
```

##### Manual Download

[](#manual-download)

Archived tagged release versions are also available for manual download on the project [tags page](https://github.com/maksimovic/auryn/tags)

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

[](#basic-usage)

To start using the injector, simply create a new instance of the `Auryn\Injector` ("the Injector") class:

```
