Skip to content

Commit

Permalink
Improve opcode cachability for autoloading
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Jan 14, 2024
1 parent bb3ff4e commit d102ab0
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 179 deletions.
22 changes: 14 additions & 8 deletions build/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ static function (SplFileInfo $file) use ($tab): string {
$function = $file->getFilenameWithoutExtension();
$namespace = str_replace('/', '\\', $file->getRelativePath());

return sprintf($tab.'$functions[\'%s\'] = __DIR__.\'/%s\';', $namespace.'\\'.$function, $path);
return sprintf($tab.$tab.'\'%s\' => __DIR__.\'/%s\',', $namespace.'\\'.$function, $path);
}
),
static fn (iterable $codeLines): iterable => concat([
'<?php declare(strict_types=1);',
'',
'(static function (): void {',
$tab . '/** @var array<string, string> $functions */',
$tab . '$functions = [];',
], $codeLines),
static fn (iterable $codeLines): iterable => concat(
[
'<?php declare(strict_types=1);',
'',
'(static function (): void {',
$tab . '/** @var array<string, string> $functions */',
$tab . '$functions = [',
],
$codeLines,
[
$tab.'];'
]
),
static fn (iterable $codeLines): iterable => concat($codeLines, ['', $autoload, '})();', '']),
static fn (iterable $codeLines): string => join($codeLines, PHP_EOL)
);
Expand Down
Loading

0 comments on commit d102ab0

Please sign in to comment.