PHPackages                             pfaciana/composer-smart-autoloader - 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. pfaciana/composer-smart-autoloader

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

pfaciana/composer-smart-autoloader
==================================

A PHP autoloader that manages class loading across multiple Composer dependencies, prioritizing the latest compatible versions.

1.3.5(9mo ago)0793GPL-2.0-onlyPHPCI passing

Since Oct 17Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/pfaciana/composer-smart-autoloader)[ Packagist](https://packagist.org/packages/pfaciana/composer-smart-autoloader)[ Docs](https://renderdev.com/)[ RSS](/packages/pfaciana-composer-smart-autoloader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (11)Used By (3)

Composer Smart Autoloader
=========================

[](#composer-smart-autoloader)

Overview
--------

[](#overview)

Composer Smart Autoloader is an autoloading solution designed to handle PHP project structures with multiple Composer dependencies. It's useful when multiple `composer.json` files are include the same codebase and the same repo is included with different versions (like a WordPress site with multiple plugins that have a composer.json and vendor folder).

### Purpose

[](#purpose)

The primary goal of Composer Smart Autoloader is to enhance the reliability and consistency of autoloading in complex PHP applications. It addresses the common issue of "first loaded, first served" in traditional autoloading mechanisms, which can lead to missing features or inconsistent behavior when older versions of packages are loaded instead of newer ones.

Usage
-----

[](#usage)

To use Composer Smart Autoloader in your project, you can simply get the instance and run it:

```
\Render\Autoload\ClassLoader::getInstance();
```

If you're using this in a WordPress plugin, you can run after all the plugins have loaded

```
add_action( 'plugins_loaded', function () {
	\Render\Autoload\ClassLoader::getInstance();
}, PHP_INT_MIN );
```

If new vendor packages have been added since you last ran it, you can re-run it using the `run` method:

```
\Render\Autoload\ClassLoader::getInstance()->run();
```

For example, you many want to run this ClassLoad right away, but then re-run after all plugins are installed

```
require_once ( __DIR__ ) . '/vendor/autoload.php';

\Render\Autoload\ClassLoader::getInstance();

\add_action( 'plugins_loaded', function () {
	\Render\Autoload\ClassLoader::getInstance()->run();
}, PHP_INT_MIN );
```

This will replace the cached class maps with the classes added since the last run.

> NOTE: `run()` will automatically run just the first time you instantiate the ClassLoader. If you call `getInstance()` a second time, nothing will happen. If you want to re-run setting the class map, you need to call the `run()` method. If you don't want the ClassLoader to automatically execute `run()` at all, set the `$run` parameter to `FALSE` like `\Render\Autoload\ClassLoader::getInstance( FALSE );` on instantiation.

### Dump Autoloading (Optimize)

[](#dump-autoloading-optimize)

To ensure dependencies of dependencies are loaded in the same manner, you can run `composer dumpautoload --optimize` for each `composer.json`. This will still work without it, but those additional dependencies might fall back to the default Composer Autoload. If using WordPress, you can do this part of a hook that runs on a plugin install (assuming composer is installed on that server).

If you're only concerned with packages you/your team personally created, then you can make sure to run `composer dumpautoload --optimize` as part of your build process.

How It Works
------------

[](#how-it-works)

1. **Version Analysis**: Composer Smart Autoloader analyzes the versions of all installed packages across different `composer.json` files in the project.
2. **Weight Calculation**: It assigns weights to different versions of the same package, favoring more recent versions.
3. **Smart Loading**: When autoloading classes, it prioritizes loading from the most up-to-date version of a package.
4. **Conflict Resolution**: In case of version conflicts, it attempts to use the latest compatible version, reducing the risk of missing required features.

Key Features and Benefits
-------------------------

[](#key-features-and-benefits)

- **Version Resolution**: Attempts to estimate and load the latest version of Composer packages when conflicts arise.
- **Prioritized Loading**: Implements a weight-based system to prioritize loading of more up-to-date package versions.
- **Conflict Resolution**: Resolves conflicts when multiple projects include the same package with different versions.
- **Improved Reliability**: Reduces the chance of missing features by always attempting to load the latest version of a package.
- **Consistency**: Provides a more consistent environment across different parts of a complex application.
- **Flexibility**: Adapts to various project structures and composer setups.
- **Performance**: Optimizes class loading by prioritizing the most relevant and up-to-date sources.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance55

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity45

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

Every ~30 days

Recently: every ~62 days

Total

10

Last Release

298d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4542fd31b9db1d4fef42a3336d2271856f1b78a89cdb6c0afd9834e950bddf1d?d=identicon)[pfaciana](/maintainers/pfaciana)

---

Top Contributors

[![pfaciana](https://avatars.githubusercontent.com/u/7454630?v=4)](https://github.com/pfaciana "pfaciana (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/pfaciana-composer-smart-autoloader/health.svg)

```
[![Health](https://phpackages.com/badges/pfaciana-composer-smart-autoloader/health.svg)](https://phpackages.com/packages/pfaciana-composer-smart-autoloader)
```

###  Alternatives

[prooph/standard-projections

Standard Projections for Prooph EventStore

1526.7k](/packages/prooph-standard-projections)[it-quasar/atol-online

Библиотека для работы с АТОЛ Онлайн

119.4k](/packages/it-quasar-atol-online)

PHPackages © 2026

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