PHPackages                             exteon/mapping-class-loader - 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. exteon/mapping-class-loader

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

exteon/mapping-class-loader
===========================

Class loader for PHP with ability to modify on-the-fly and map class files, caching and static initialisation

4.0.0(4y ago)0631Apache-2.0PHP

Since Dec 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/exteon/mapping-class-loader)[ Packagist](https://packagist.org/packages/exteon/mapping-class-loader)[ Docs](https://github.com/exteon/mapping-class-loader)[ RSS](/packages/exteon-mapping-class-loader/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (12)Used By (1)

MappingClassLoader
==================

[](#mappingclassloader)

Abstract
--------

[](#abstract)

When loading classes, there are occasions where we need to do source code manipulation before loading, mainly for weaving classes in the context of AOP or creating class proxies for other purposes. One of the most common operations is rewriting class ancestry before loading the class.

One of the problems with this approach is maintaining debugging capabilities with Xdebug, so that the modified interpreted source file is step debugged against the original source.

`MappingClassLoader` is an advanced class loader framework providing the following functionalities:

- Class resolvers with the ability to provide modified source code for the classes being loaded
- Caching for the modified source files
- Enabling debug via mapping of the modified sources to the original source files using stream wrappers
- Static class initializers that allow implementing static constructors or static dependency injection

Requirements
------------

[](#requirements)

- PHP 7.2

Usage
-----

[](#usage)

### Installing with `composer`

[](#installing-with-composer)

```
composer require exteon/mapping-class-loader
```

Class resolvers
---------------

[](#class-resolvers)

`MappingClassLoader` has a modular design allowing the implementation of multiple resolvers; a resolver is the first thing to implement in order to load classes.

Resolvers implement `ClassResolver` to resolve a requested class name to one or more `LoadAction`'s. A `LoadAction` is the identification of a source code to load, which can be one of the three types:

- Pure code: only provides the `source` property containing the code to be evaluated
- Source file: only provides the `file` property
- Modified, mappable source file: provides both a `file` property to identify the original source file and a `source` property containing the modified source code to be evaluated

**Example**

*A.php*

```
