PHPackages                             sciactive/requirephp - 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. sciactive/requirephp

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

sciactive/requirephp
====================

An implementation of dependency injection (like RequireJS) in PHP.

1.3.0(11y ago)241.0k41LGPLPHP

Since Oct 7Pushed 10y ago4 watchersCompare

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

READMEChangelog (9)DependenciesVersions (7)Used By (1)

[![logo](https://raw.githubusercontent.com/sciactive/2be-extras/master/logo/product-icon-40-bw.png)](https://raw.githubusercontent.com/sciactive/2be-extras/master/logo/product-icon-40-bw.png) RequirePHP
==========================================================================================================================================================================================================

[](#-requirephp)

[![Latest Stable Version](https://camo.githubusercontent.com/ca0fa7325ea9e063a06346e6853fefb740c0f5579532e3136f7795bd76aa2f0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363696163746976652f726571756972657068702e7376673f7374796c653d666c6174)](https://packagist.org/packages/sciactive/requirephp) [![License](https://camo.githubusercontent.com/75e0292423e39d71a5a1c42ab6b8734734eec79b2d3e309fd73a3be5d36d4b05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7363696163746976652f726571756972657068702e7376673f7374796c653d666c6174)](https://packagist.org/packages/sciactive/requirephp) [![Total Downloads](https://camo.githubusercontent.com/f7fe5473b8a23bce4f5e912a4b369e2339ba7ffa4977d6d5f9416fc1ff8ee2fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7363696163746976652f726571756972657068702e7376673f7374796c653d666c6174)](https://packagist.org/packages/sciactive/requirephp) [![Open Issues](https://camo.githubusercontent.com/02095f6ba745c5a6813a8e9a18b28a832fe86fdd4e5486b179c1d86cf341b878/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f7363696163746976652f726571756972657068702e7376673f7374796c653d666c6174)](https://github.com/sciactive/requirephp/issues)

An implementation of dependency injection and service locator (like RequireJS) in PHP.

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

[](#installation)

You can install RequirePHP with Composer or Bower.

```
composer require sciactive/requirephp

bower install https://github.com/sciactive/requirephp.git
```

Getting Started
---------------

[](#getting-started)

If you don't use an autoloader, all you need to do is include the RequirePHP.php file.

```
require("RequirePHP.php");
```

Now you can start giving code that requires a module, or modules, to run. This code will not run until all the required modules (in this case, only 'test') are available.

```
\SciActive\RequirePHP::_(array('test'), function($test){
	$test->value = 'Hello, world.';
});
```

You can define modules. This module has no dependencies, hence the empty array.

```
\SciActive\RequirePHP::_('test', array(), function(){
	class test {
		public $value;

		public function talk() {
			echo $this->value;
		}
	}

	// Returning a new instantiation is important if you are
	// providing a service.
	return new test();
});
```

You can create aliases to modules (and other aliases).

```
\SciActive\RequirePHP::alias('testing', 'test');
```

You can keep using the same instance in other code, using RequirePHP as a service locator. This function uses the alias from above.

```
\SciActive\RequirePHP::_(array('testing'), function($test){
	$test->talk(); // Prints 'Hello, world.'.
});
```

You can also retrieve modules outside of a closure. However, if this module is not available at the time you request it, RequirePHP will throw a RequireModuleFailedException. Such is the price of not using a closure.

```
$test = \SciActive\RequirePHP::_('test');
$test->talk(); // Prints 'Hello, world.'.
```

Service Location
----------------

[](#service-location)

The repository contains [an example](https://github.com/sciactive/requirephp/blob/master/test_service_locator.php) of using RequirePHP as a service locator.

Dependency Injection
--------------------

[](#dependency-injection)

The repository contains [an example](https://github.com/sciactive/requirephp/blob/master/test_dependency_injector.php) of using RequirePHP as a dependency injector.

Contacting the Developer
------------------------

[](#contacting-the-developer)

There are several ways to contact RequirePHP's developer with your questions, concerns, comments, bug reports, or feature requests.

- RequirePHP is part of [SciActive on Twitter](http://twitter.com/SciActive).
- Bug reports, questions, and feature requests can be filed at the [issues page](https://github.com/sciactive/requirephp/issues).
- You can directly [email Hunter Perrin](mailto:hunter@sciactive.com), the creator of RequirePHP.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

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

Total

6

Last Release

4153d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/133c9c4eff1268723fc1be664b5312a40527c6a94bfd40215bf4ff276832738f?d=identicon)[hperrin](/maintainers/hperrin)

---

Top Contributors

[![hperrin](https://avatars.githubusercontent.com/u/195918?v=4)](https://github.com/hperrin "hperrin (26 commits)")

---

Tags

dependency-injectionphpdependency-injectionamdservice locatorservice locationdependency injector

### Embed Badge

![Health badge](/badges/sciactive-requirephp/health.svg)

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

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26764.7M69](/packages/php-di-invoker)[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

436797.2k21](/packages/level-2-dice)[maba/webpack-bundle

Bundle to Integrate Webpack to Symfony

123268.4k4](/packages/maba-webpack-bundle)[matthiasnoback/symfony-service-definition-validator

Library for validating service definitions created with the Symfony Dependency Injection Component

90361.3k7](/packages/matthiasnoback-symfony-service-definition-validator)[arokettu/phpstorm-metadata-export

Export PhpStorm Advanced Metadata from DI containers

1238.4k1](/packages/arokettu-phpstorm-metadata-export)[x-wp/di

The dependency injection container for WordPress

314.3k14](/packages/x-wp-di)

PHPackages © 2026

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