PHPackages                             webiny/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. webiny/class-loader

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

webiny/class-loader
===================

Webiny Class Loader Component

v1.6.1(8y ago)33591MITPHPPHP ^7

Since Sep 19Pushed 8y ago8 watchersCompare

[ Source](https://github.com/Webiny/ClassLoader)[ Packagist](https://packagist.org/packages/webiny/class-loader)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-class-loader/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (24)Used By (1)

ClassLoader Component
=====================

[](#classloader-component)

Class loader component loads your PHP files automatically as long as they follow some standard naming convention. The following standards are supported:

- PEAR
- [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
- [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md)

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/class-loader
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/class-loader).

Usage
-----

[](#usage)

To use the ClassLoader, get its instance by calling ClassLoader::getInstance() method.

```
    require_once 'Webiny/Component/ClassLoader/ClassLoader.php'

    use Webiny\Component\ClassLoader;

    ClassLoader::getInstance();
```

Once you have the ClassLoader instance, you can register map rules. The ClassLoader automatically detects if you are registering a namespace or a PEAR rule. PEAR rules are identified by having a underline '\_' at the end of the prefix. If PSR is not defined, the component will use **PSR-4** standard. All paths should be absolute.

```
    ClassLoader::getInstance()->registerMap([
    										// a namespace rule (PSR-4 - default)
    										'Webiny' => realpath(dirname(__FILE__)).'/library/Webiny',
    										// a namespace rule (PSR-0)
    										'Symfony' => [
    										    'Path' => '/var/vendors/Symfony',
    										    'Psr' => 0
    										],
    										// a PEAR rule
    										'Swift_' => realpath(dirname(__FILE__)).'/library/Swift',
    										]);
```

As you can see the registerMap method takes an array of multiple rules. Each rule consists of a prefix and a location.

For better performance you can provide a Cache component to ClassLoader. Doing so, ClassLoader will cache the paths and files resulting in a faster performance.

```
    ClassLoader::getLoader()->registerCacheDriver($instanceOfCacheInterface);
```

Non-standardized libraries
--------------------------

[](#non-standardized-libraries)

If you have a library that is not following neither the PSR naming convention nor the PEAR naming convention, you'll have to manually define some of the settings.

Let's take a look at this example:

```
    ClassLoader::getInstance()->registerMap([
        'Smarty_' => [
                        'Path'      => '/var/www/Vendors/Smarty/libs/sysplugins',
                        'Normalize' => false,
                        'Case'      => lower
                     ]
    ]);
```

You can see that the `Smarty_` library is defined as an array that has `Path`, `Normalize` and `Case` parameter.

### `Path`

[](#path)

Defines the path to the library.

### `Normalize`

[](#normalize)

The `Normalize` parameter tells the autoloader if he should to change the `_`, on the class name, into directory separators. For example if you have a class names`Smarty_Internal_Compile` the normalized path would be `Smarty/Internal/Compiler`. If you set the `Normalize` parameter to `false`, the original class name will be used.

### `Case`

[](#case)

By default the autoloader transfers all the class names to CamelCase, you can set the `Case` parameter to `lower` if you wish that the class names are used in lower case inside the class path.

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/ClassLoader/
$ composer.phar install
$ phpunit

```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

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

Recently: every ~5 days

Total

23

Last Release

3201d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.2.0PHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (27 commits)")

---

Tags

autoloaderPSR-4psr-0class loader

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webiny-class-loader/health.svg)

```
[![Health](https://phpackages.com/badges/webiny-class-loader/health.svg)](https://phpackages.com/packages/webiny-class-loader)
```

###  Alternatives

[aura/autoload

Provides a PSR-4 compliant autoloader implementation.

102515.6k13](/packages/aura-autoload)[evilfreelancer/routeros-api-php

Modern Mikrotik RouterOS API PHP client for your applications (with Laravel support)

496262.3k6](/packages/evilfreelancer-routeros-api-php)[icamys/php-sitemap-generator

Simple PHP sitemap generator.

175364.1k7](/packages/icamys-php-sitemap-generator)[yidas/codeigniter-psr4-autoload

CodeIgniter 3 PSR-4 Autoloader for Application

5520.5k3](/packages/yidas-codeigniter-psr4-autoload)[genert/bbcode

BBCode parser from or to HTML.

81335.4k1](/packages/genert-bbcode)[suin/phpcs-psr4-sniff

PHP\_CodeSniffer sniff that checks class name matches PSR-4 project structure.

271.9M19](/packages/suin-phpcs-psr4-sniff)

PHPackages © 2026

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