https://github.com/smuuf/koloader
Koloader is a super-lightweight directory-sniffing autoloader with caching.
https://github.com/smuuf/koloader
Last synced: 3 months ago
JSON representation
Koloader is a super-lightweight directory-sniffing autoloader with caching.
- Host: GitHub
- URL: https://github.com/smuuf/koloader
- Owner: smuuf
- License: mit
- Created: 2015-12-14T13:09:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-11-18T21:44:00.000Z (over 4 years ago)
- Last Synced: 2025-03-17T14:03:11.630Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Koloader
*Koloader* is a super-lightweight directory-sniffing autoloader with caching.
### Installation
You probably want to do either of these:
1. [Direct download](https://github.com/smuuf/koloader/archive/master.zip) **or**
2. With *Composer*: `composer require smuuf/koloader`### Usage
Koloader is created with ease-of-use in mind. Really, you will need only four lines of code in your new project. The rest will be handled for you.
##### First, include the Koloader in your project
*Koloader* needs to be included first. If you're not using *Composer*, this can be done directly by including the Koloader's *loader* script, which will load everything else that is needed:
```
require __DIR__ . "/path/to/Koloader/src/loader.php";
```##### And then use it!
```
$loader = new \Smuuf\Koloader\Autoloader(__DIR__ . "/temp/"); // The temp directory must exist beforehand.
$loader->addDirectory(__DIR__ . "/app")
->register();// Autoloading is enabled now!
$instance = new SomeClass; // Autoloading will be handled by the Koloader.
$instance->doClassStuff(); // Profit!
```The Koloader must be instantiated with a path to an existing temporary directory as an argument:
- **Autoloader::__construct**(*string* $pathToTmpDir) - Specified directory will be used for storing cached maps of scanned files. **This directory will *not* be created automatically** and thus must exist beforehand.And then you need to call only two methods on the *Koloader* instance:
- **Autoloader::addDirectory**(*string* $pathToDirectory) - Add a directory to the list of directories that will be scanned for definitions of autoloadable tokens (those good ol' **class**, **interface**, **trait** keywords)
- **Autoloader::register**() - Call this after all directories were added. This will register the Koloader and from that moment it will handle autoloading.That is all. Have fun!