Download the PHP package phine/psr4 without Composer
On this page you can find all versions of the php package phine/psr4. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package psr4
Short Description A PHP library that implements the PSR-4 standard.
License MIT
Homepage https://github.com/phine/lib-psr4
Informations about the package psr4
PSR-4
A simple implementation of the PSR-4 standard.
Summary
The PSR-4 library provides a simple implementation of the PSR-4 standard. Also bundled with the library are classes for debugging the class autoloading process, as well as caching for improved performance.
Requirement
- PHP >= 5.3.3
- APC (if using
APCLoader
on PHP 5.4 and older) - APCu (if using
APCLoader
on PHP 5.5 and newer)
Installation
Via Composer:
$ composer require "phine/psr4=~1.0"
Usage
You may want to start by using the standard loading class:
With a new loader available, you will then want to map your namespace prefixes to their base directory paths.
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:
When you are ready to use the loader, you will then need to register it:
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:
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:
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
You will need to create a new instance of APCLoader
to use APC caching:
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
You can find the API documentation here.
License
This library is available under the MIT license.