merophp/autoloader

Simple PSR-4 autoloader

0.1-beta 2022-02-03 14:41 UTC

This package is auto-updated.

Last update: 2024-10-29 06:06:27 UTC


README

Simple PSR-4 autoloader for the merophp framework.

Installation

Via composer:

composer require merophp/autoloader

Basic Usage

require_once 'vendor/autoload.php';

use Merophp\Autoloader\NamespacePrefix\NamespacePrefix;
use Merophp\Autoloader\NamespacePrefix\Collection\NamespacePrefixCollection;
use Merophp\Autoloader\NamespacePrefix\Provider\NamespacePrefixProvider;
use Merophp\Autoloader\Autoloader;

$collection = new NamespacePrefixCollection();
$collection->addMultiple([
     new NamespacePrefix('Vendor1\\Test', './tests/integration/testData/vendor1'),
     new NamespacePrefix('Vendor2\\Test', './tests/integration/testData/vendor2'),
]);
$provider = new NamespacePrefixProvider($collection);

$autoloader = new Autoloader($provider);

//Now you can call your classes
$serviceA = new Vendor1\Test\Service\ServiceA();
//Expect class in ./tests/integration/testData/vendor1/Service/ServiceA.php