| Server IP : 77.68.64.20 / Your IP : 216.73.217.60 Web Server : Apache System : Linux hp3-wp-1011317.hostingp3.local 3.10.0-1160.144.1.el7.tuxcare.els8.x86_64 #1 SMP Sun Jul 5 17:25:39 UTC 2026 x86_64 User : csh2392878 ( 2033753) PHP Version : 8.3.30 Disable Function : shell_exec,exec,system,popen,set_time_limit MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/domains/vol1/746/2880746/user/htdocs/wp-content/plugins/booknetic/ |
Upload File : |
<?php
/**
* Build-time cache generator for DI container service discovery.
*
* Usage:
* php build-di-cache.php # Core plugin only
* php build-di-cache.php booknetic-{addon-name} # Specific addon
*
* Scans all classes with #[Service] attribute and ServiceProviderInterface
* implementations, and writes a cache file that eliminates runtime reflection.
*/
require_once __DIR__ . '/vendor/autoload.php';
use BookneticApp\Providers\IoC\ServiceScanner;
$addonArg = $argv[1] ?? null;
if ($addonArg !== null) {
$addonDir = dirname(__DIR__) . '/' . $addonArg;
if (! is_dir($addonDir)) {
echo "Error: Addon directory not found: {$addonDir}\n";
exit(1);
}
$addonAutoloader = $addonDir . '/vendor/autoload.php';
if (file_exists($addonAutoloader)) {
require_once $addonAutoloader;
}
$scanDir = $addonDir . '/App';
$cacheDir = $addonDir . '/cache';
$cachePath = $cacheDir . '/di_cache.php';
echo "Building DI cache for addon: {$addonArg}\n";
} else {
$scanDir = __DIR__ . '/app';
$cacheDir = __DIR__ . '/cache';
$cachePath = $cacheDir . '/di_cache.php';
echo "Building DI cache for core plugin\n";
}
if (! is_dir($scanDir)) {
echo "Error: Scan directory not found: {$scanDir}\n";
exit(1);
}
if (! is_dir($cacheDir)) {
mkdir($cacheDir, 0755, true);
}
echo "Scanning for #[Service] classes in {$scanDir}...\n";
$scanner = new ServiceScanner($scanDir);
$result = $scanner->scan();
echo 'Found ' . count($result['services']) . " services.\n";
foreach ($result['services'] as $fqcn => $meta) {
echo " [{$meta['lifetime']}] {$fqcn}\n";
}
if (! empty($result['bindings'])) {
echo "\nBindings:\n";
foreach ($result['bindings'] as $interface => $concrete) {
echo " {$interface} → {$concrete}\n";
}
}
if (! empty($result['providers'])) {
echo "\nServiceProviders:\n";
foreach ($result['providers'] as $provider) {
echo " {$provider}\n";
}
}
$cacheContent = "<?php\n\n// Auto-generated by build-di-cache.php — do NOT edit manually.\n// Generated: " . date('Y-m-d H:i:s') . "\n\nreturn " . var_export([
'services' => $result['services'],
'bindings' => $result['bindings'],
'providers' => $result['providers'],
], true) . ";\n";
file_put_contents($cachePath, $cacheContent);
echo "\nCache written to: {$cachePath}\n";
echo 'Services: ' . count($result['services']) . ', Bindings: ' . count($result['bindings']) . ', Providers: ' . count($result['providers']) . "\n";
echo "Done.\n";