PHPackages                             phine/psr4 - 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. phine/psr4

AbandonedArchivedLibrary

phine/psr4
==========

A PHP library that implements the PSR-4 standard.

1.0.0(12y ago)31.1k1MITPHPPHP &gt;=5.3.3

Since Dec 5Pushed 12y agoCompare

[ Source](https://github.com/kherge-archive/lib-psr4)[ Packagist](https://packagist.org/packages/phine/psr4)[ Docs](https://github.com/phine/lib-psr4)[ RSS](/packages/phine-psr4/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

PSR-4
=====

[](#psr-4)

[![Build Status](https://camo.githubusercontent.com/92491fc59f0de94bd81f676520d2753d42ee5014d1a8c72f08ce99273282793c/68747470733a2f2f7472617669732d63692e6f72672f7068696e652f6c69622d707372342e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/phine/lib-psr4)[![Coverage Status](https://camo.githubusercontent.com/55f86ae4acc1c2f7498651459908783f0105084a5382a70831128662ffbf13bc/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7068696e652f6c69622d707372342f62616467652e706e67)](https://coveralls.io/r/phine/lib-psr4)[![Latest Stable Version](https://camo.githubusercontent.com/4a646976cdbf734563d1e9931f36d897e6e70009755bb3c5d6298ffb2d3b593c/68747470733a2f2f706f7365722e707567782e6f72672f7068696e652f707372342f762f737461626c652e706e67)](https://packagist.org/packages/phine/psr4)[![Total Downloads](https://camo.githubusercontent.com/4169e9f5b4881850b9dd7b59eb8279e16cae1d19b42400f994da1ef52aa040fc/68747470733a2f2f706f7365722e707567782e6f72672f7068696e652f707372342f646f776e6c6f6164732e706e67)](https://packagist.org/packages/phine/psr4)

A simple implementation of the [PSR-4](http://www.php-fig.org/psr/psr-4/) standard.

Summary
-------

[](#summary)

The PSR-4 library provides a simple implementation of the [PSR-4](http://www.php-fig.org/psr/psr-4/) standard. Also bundled with the library are classes for debugging the class autoloading process, as well as caching for improved performance.

Requirement
-----------

[](#requirement)

- PHP &gt;= 5.3.3
- APC (if using `APCLoader` on PHP 5.4 and older)
- APCu (if using `APCLoader` on PHP 5.5 and newer)

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

[](#installation)

Via [Composer](http://getcomposer.org/):

```
$ composer require "phine/psr4=~1.0"

```

Usage
-----

[](#usage)

You may want to start by using the standard loading class:

```
use Phine\PSR4\Loader();

$loader = new Loader();
```

With a new loader available, you will then want to map your namespace prefixes to their base directory paths.

```
$loader->map('Namespace\\Prefix', '/base/directory/path');
```

While you may only register one namespace prefix at a time, you may specify one or more directory paths for each call to `map()`. To pass more than one directory path, you may simply pass an array of directory paths.

You may also chain calls to `map()` together:

```
$loader
    ->map('One\\Prefix', '/one/path')
    ->map('Two\\Prefix', '/two/path')
    ->map('Three\\Prefix', '/three/path');
```

When you are ready to use the loader, you will then need to register it:

```
$loader->register();
```

> You may register the loader at any point, such as before you begin mapping namespace prefixes to paths. Any namespace prefixes mapped after the loader is registered will be used by the loader as well.

You can now autoload classes for the namespace prefixes you registered:

```
$myInstance = new One\Prefix\MyClass();
```

Debugging
---------

[](#debugging)

If you find that you are having problems autoloading classes, you may want to use the `DebugLoader` class. This class will throw an exception when either the file for the class could not be found, or if the class did not actually exist in the file that was loaded.

Using the debugging loader is as simple as using the standard loader:

```
use Phine\PSR4\DebugLoader;

$loader = new DebugLoader();
```

Caching
-------

[](#caching)

When you are ready to use your project in a production environment, you may want to use a version of the loader that supports caching. Currently, only APC is supported, but additional support can be bundled with enough demand. If you need to support a caching library, you will want to mimic the code used for the bundled caching classes.

### APC

[](#apc)

You will need to create a new instance of `APCLoader` to use APC caching:

```
use Phine\PSR4\APCLoader;

$loader = new APCLoader($cacheKeyPrefix);
```

As part of the constructor, you need to specify a cache key prefix that will be used when storing class file paths in APC. The prefix can be whatever you need it to be.

Using the prefix `PSR4-Classes-` and loading the class `My\Example` will generate the cache key `PSR4-Classes-My\Example` for the class's file path.

> It may be useful to know that once a class file path is cached, it will not expire or be refreshed if it no longer exists. You will need to flush the cache or using a versioning scheme for the prefix.

API Documentation
-----------------

[](#api-documentation)

You can find the [API documentation](http://phine.github.io/lib-psr4/) here.

License
-------

[](#license)

This library is available under the [MIT license](LICENSE).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4543d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9122157?v=4)[Kevin Herrera](/maintainers/kherge)[@kherge](https://github.com/kherge)

---

Top Contributors

[![kherge](https://avatars.githubusercontent.com/u/9122157?v=4)](https://github.com/kherge "kherge (35 commits)")

---

Tags

autoloadclasspsr4

### Embed Badge

![Health badge](/badges/phine-psr4/health.svg)

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.4k187.2M2.6k](/packages/composer-composer)[nette/robot-loader

🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.

89152.7M321](/packages/nette-robot-loader)[classpreloader/classpreloader

Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case

37642.4M32](/packages/classpreloader-classpreloader)[shipmonk/name-collision-detector

Simple tool to find ambiguous classes or any other name duplicates within your project.

362.1M35](/packages/shipmonk-name-collision-detector)[classpreloader/console

Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case

10235.0k5](/packages/classpreloader-console)

PHPackages © 2026

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