PHPackages                             martin-hughes/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. martin-hughes/auryn

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

martin-hughes/auryn
===================

Auryn is a dependency injector for bootstrapping object-oriented PHP applications.

v1.4.9(3mo ago)614511MITPHPPHP &gt;=7.4.0 &lt;8.6CI passing

Since Oct 6Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/martin-hughes/auryn)[ Packagist](https://packagist.org/packages/martin-hughes/auryn)[ Docs](https://github.com/martin-hughes/auryn)[ RSS](/packages/martin-hughes-auryn/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (44)Used By (1)

auryn
=====

[](#auryn)

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

Maintenance Status
------------------

[](#maintenance-status)

*This package is abandoned.* I've decided to stop maintenance of this package for two reasons:

1. It has very low usage - so low, I'm not sure anyone uses it any more.
2. I no longer regularly use PHP.

You may be able to find other forks of auryn but most also seem to be abandoned. This fork will work with PHP versions up to 8.5. Probably it will work with future versions as well, but it will not be tested.

> In a new project I'd suggest using an implementation of PSR-11 instead of auryn.

The original version of this package - `rdlowrey/auryn` - was effectively abandoned many years ago. The current maintenance status of that package hasn't even make into `master` - it's only made it to the [dev branch](https://github.com/rdlowrey/auryn/tree/dev)!

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 7.4 or higher. It is tested on at least one point release from each of PHP 7.4, 8.0 - 8.3 and 8.4 beta.

### Installation

[](#installation)

#### Github

[](#github)

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

```
$ git clone git://github.com/martin-hughes/auryn.git
```

#### Composer

[](#composer)

You may also use composer to include auryn as a dependency in your projects `composer.json`. The relevant package is `martin-hughes/auryn`.

Alternatively require the package using composer cli:

```
composer require martin-hughes/auryn
```

#### Manual Download

[](#manual-download)

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

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

[](#basic-usage)

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

```
