#!/usr/bin/env php in(__DIR__ . '/../src') ->exclude(['helper', 'polyfill-coroutine']) ->name('composer.json') ->files(); $require = []; $autoload = []; $autoloadFiles = []; $autoloadDev = []; $configProviders = []; $replaces = []; foreach ($files as $file) { $component = basename(dirname($file)); $composerJson = json_decode(file_get_contents($file), true); if (isset($composerJson['name']) && str_starts_with($composerJson['name'], 'hyperf')) { $replaces[$composerJson['name']] = '*'; } foreach ($composerJson['autoload']['files'] ?? [] as $file) { $autoloadFiles[] = "src/{$component}/" . preg_replace('#^./#', '', $file); } foreach ($composerJson['autoload']['psr-4'] ?? [] as $ns => $dir) { $value = "src/{$component}/" . trim($dir, '/') . '/'; if (isset($autoload[$ns])) { $autoload[$ns] = [$value, ...(array) $autoload[$ns]]; } else { $autoload[$ns] = $value; } } foreach ($composerJson['autoload-dev']['psr-4'] ?? [] as $ns => $dir) { $value = "src/{$component}/" . trim($dir, '/') . '/'; if (isset($autoloadDev[$ns])) { $autoloadDev[$ns] = [$value, ...(array) $autoloadDev[$ns]]; } else { $autoloadDev[$ns] = $value; } } if (isset($composerJson['extra']['hyperf']['config'])) { $configProviders = array_merge($configProviders, (array) $composerJson['extra']['hyperf']['config']); } } ksort($autoload); sort($autoloadFiles); ksort($autoloadDev); sort($configProviders); ksort($replaces); $json = json_decode(file_get_contents(__DIR__ . '/../composer.json')); $json->autoload->files = $autoloadFiles; $json->autoload->{'psr-4'} = $autoload; $json->{'autoload-dev'}->{'psr-4'} = $autoloadDev; $json->extra->hyperf->config = $configProviders; $json->replace = $replaces; file_put_contents( __DIR__ . '/../composer.json', json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL );