Preloader
Raxos\Foundation\Preloader walks a set of source and vendor paths and requires every PHP file it finds, so it can be used to build an OPcache preload script.
See the Preloader concept page for a guided introduction.
Signature
namespace Raxos\Foundation;
class Preloaderpublic function __construct(
array $paths = []
)Creates a preloader with an optional list of initial paths to preload.
Methods
public function path(string $path): voidAdds a file or directory to the set of paths that will be preloaded.
public function ignore(string $path): voidAdds a path prefix to ignore. The prefix is matched case-insensitively against the start of each candidate file path.
public function preload(): voidPerforms the actual preloading. It snapshots get_included_files() first, then walks every configured path and requires each PHP file that passes the filters.
INFO
The recursive directory walking, the per-file require, and the ignore check are internal implementation details (private methods). Only the constructor, path(), ignore() and preload() form the public surface.
Example
<?php
declare(strict_types=1);
use Raxos\Foundation\Preloader;
require __DIR__ . '/../vendor/autoload.php';
$preloader = new Preloader([
__DIR__ . '/../src',
]);
$preloader->path(__DIR__ . '/../vendor/raxos/database/src');
$preloader->ignore(__DIR__ . '/../src/Console');
$preloader->preload();