PHPackages                             cmpayments/atreyu - 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. cmpayments/atreyu

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

cmpayments/atreyu
=================

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

v1.6.0(9y ago)15159MITPHPPHP &gt;=5.4.0

Since Mar 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/cmpayments/atreyu)[ Packagist](https://packagist.org/packages/cmpayments/atreyu)[ Docs](https://github.com/cmpayments/atreyu)[ RSS](/packages/cmpayments-atreyu/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (11)Used By (0)

Atreyu [![Build Status](https://camo.githubusercontent.com/77e9a46e511d209043185362be84c95796baaa3d15656d9b5bb29faac1a32a5b/68747470733a2f2f7472617669732d63692e6f72672f636d7061796d656e74732f6174726579752e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cmpayments/atreyu)
=========================================================================================================================================================================================================================================================================================

[](#atreyu-)

[![License](https://camo.githubusercontent.com/86a6479a4139b12e78f8c6e3968e42da7f069d814016df943c7f0a7e2e32c988/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636d7061796d656e74732f6174726579752e737667)](https://camo.githubusercontent.com/86a6479a4139b12e78f8c6e3968e42da7f069d814016df943c7f0a7e2e32c988/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636d7061796d656e74732f6174726579752e737667)[![Latest Stable Version](https://camo.githubusercontent.com/cb4cbefc748e44fc66744f5ddeba175f12d4ed1003694fcf3323de368f817ade/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636d7061796d656e74732f6174726579752e737667)](https://packagist.org/packages/cmpayments/atreyu)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e28b63840796e8464696f285169c51d68365ac857f42d6619cac0dc0bd6abb7d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636d7061796d656e74732f6174726579752f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/cmpayments/atreyu/)[![Total Downloads](https://camo.githubusercontent.com/fef2f5cb49c3282bcf0949a7804795ab3b641336288f3c6922e58d9763e842b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636d7061796d656e74732f6174726579752e737667)](https://packagist.org/packages/cmpayments/atreyu)[![Reference Status](https://camo.githubusercontent.com/d2eb80da67250b5bdee0f3e62dd9f94084eae7925aaa6f602abee5daa110a51d/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f636d7061796d656e74733a6174726579752f7265666572656e63655f62616467652e737667)](https://www.versioneye.com/php/cmpayments:atreyu/references)

Atreyu is an extension of [Auryn](https://github.com/rdlowrey/auryn) and is born out of the need to use typehinted parameters when instantiating classes, if no typehinting is available the use of docblock to identify parameters is also possible (as a fallback only).

The main difference between Atreyu and Auryn is that Atreyu inspects type hinted method parameters. If the method parameters are not type hinted Atreyu will inspect the docblock

Atreyu is a recursive dependency injector based on Auryn. use Atreyu to bootstrap and wire together S.O.L.I.D., object-oriented PHP applications.

##### How It Works

[](#how-it-works)

Among other things, Atreyu 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. Atreyu caches any reflections it generates to minimize the potential performance impact.

> Atreyu **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)
- [Dependency Resolution functionality on top of Auryn](#dependency-resolution-functionality-on-top-of-auryn)

**Example Use Cases**

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

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

[](#requirements-and-installation)

- Atreyu requires PHP 5.4 or higher.

#### Installation

[](#installation)

###### Github

[](#github)

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

```
$ git clone git://github.com/cmpayments/atreyu.git
```

###### Composer

[](#composer)

You may also use composer to include Atreyu as a dependency in your projects `composer.json`. The relevant package is `cmpayments/atreyu`.

Alternatively require the package using composer cli:

```
composer require cmpayments/atreyu
```

##### Manual Download

[](#manual-download)

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

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

[](#basic-usage)

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

```
