classpreloader/classpreloader
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
nikic/php-parser | v4.19.1 | - | BSD-3-Clause | prod |
Classpreloader/classpreloader is a highly useful tool that optimizes PHP application performance. It does this by generating a single PHP file that houses all of the autoloaded files needed for a specific use case, thereby minimizing the repeated cost of autoloading necessary classes over and over again. However, it's critical to understand that this tool should be employed only for specific use cases and a balance must be maintained between preloading and autoloading. The potential benefits can be best determined through application-specific benchmarks.
Classpreloader/classpreloader can be integrated into your PHP application with a few straightforward steps. Initially, you must define ClassPreloader as a dependency in your composer.json file by incorporating "classpreloader/classpreloader": "^4.1"
into your require block. If you intend to use the CLI tool, ensure to also add "classpreloader/console": "^3.1"
to the require block.
Once the installation is done, use the command ./vendor/bin/classpreloader
compile along with several command-line flags to generate a preloader. Each flag serves a unique purpose, for example, --config
is used to list files to combine into a classmap, --output
defines the path for the compiled PHP file, --skip_dir_file
skips files with __DIR__
or __FILE__
for portability, and other flags aim at dealing with constants and strict types among other things.
It's also possible to incorporate an automated process with Composer that generates preloaders each time the project's autoloader is regenerated or updated.
Here's a PHP code usage example:
require __DIR__.'/src/ClassLoader.php';
use ClassPreloader\ClassLoader;
$config = ClassLoader::getIncludes(function (ClassLoader $loader) {
require __DIR__.'/vendor/autoload.php';
$loader->register();
});
return $config;
And a Composer automation example:
{
"require": {
"classpreloader/console": "^3.1"
},
"scripts": {
"post-autoload-dump": "@php vendor/bin/classpreloader compile --config=/path/to/the_example.php --output=/path/to/preload.php"
},
"config": {
"bin-dir": "bin"
}
}
For detailed information about classpreloader/classpreloader, you can visit the official documentation at its GitHub repository: https://github.com/ClassPreloader/ClassPreloader. The repository contains comprehensive explanations about the package, its installation, usage examples along with information about the commands and functionalities it provides.