Skip to content

totallyquiche/automatica

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

Automática

Automática is a PSR-4 compliant autoloader.

Usage

Load Autoloader.php, create a new instance of Autoloader, and call the register() method.

require_once('Autoloader.php');

(new TotallyQuiche\Automatica\Autoloader)->register();

You can provide a mapping of vendor namespace prefixes to the corresponding file paths relative to Automática's base directory.

// Look for Vendor\Namespace\Prefix class files in ./Library/

$autoloader = new Autoloader(
    ['Vendor\Namespace\Prefix' => 'Library']
);

$autoloader->register();

The base directory is location of Autoloader.php by default, but this can also be changed.

// Look for Vendor\Namespace\Prefix class files in ./vendor/Library/

$autoloader = new Autoloader(
    ['Vendor\Namespace\Prefix' => 'Library'],
    './vendor/'
);

$autoloader->register();

Example

Filesystem:

./index.php
./Autoloader.php
./Vendor/
     Utility.php

Utility.php

<?php declare(strict_types=1);

namespace Some\Vendor;

final class Utility
{
    //
}

index.php:

<?php declare(strict_types=1);

require_once('Autoloader.php');

(new TotallyQuiche\Automatica\Autoloader(
    ['Some\Vendor' => 'Vendor']
))->register();

new Some\Vendor\Utility;

About

Automática is a PSR-4 compliant autoloader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages