AutoloadFileWriter.php
1 year ago
AutoloadGenerator.php
1 year ago
AutoloadProcessor.php
1 year ago
CustomAutoloaderPlugin.php
1 year ago
ManifestGenerator.php
1 year ago
autoload.php
1 year ago
class-autoloader-handler.php
1 year ago
class-autoloader-locator.php
1 year ago
class-autoloader.php
1 year ago
class-container.php
1 year ago
class-hook-manager.php
1 year ago
class-latest-autoloader-guard.php
1 year ago
class-manifest-reader.php
1 year ago
class-path-processor.php
1 year ago
class-php-autoloader.php
1 year ago
class-plugin-locator.php
1 year ago
class-plugins-handler.php
1 year ago
class-shutdown-handler.php
1 year ago
class-version-loader.php
1 year ago
class-version-selector.php
1 year ago
index.php
1 year ago
AutoloadFileWriter.php
60 lines
| 1 | <?php |
| 2 | namespace Automattic\Jetpack\Autoloader; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use Composer\IO\IOInterface; |
| 5 | class AutoloadFileWriter { |
| 6 | const COMMENT = <<<AUTOLOADER_COMMENT |
| 7 | AUTOLOADER_COMMENT; |
| 8 | public static function copyAutoloaderFiles( $io, $outDir, $suffix ) { |
| 9 | $renameList = array( |
| 10 | 'autoload.php' => '../autoload_packages.php', |
| 11 | ); |
| 12 | $ignoreList = array( |
| 13 | 'AutoloadGenerator.php', |
| 14 | 'AutoloadProcessor.php', |
| 15 | 'CustomAutoloaderPlugin.php', |
| 16 | 'ManifestGenerator.php', |
| 17 | 'AutoloadFileWriter.php', |
| 18 | ); |
| 19 | // Copy all of the autoloader files. |
| 20 | $files = scandir( __DIR__ ); |
| 21 | foreach ( $files as $file ) { |
| 22 | // Only PHP files will be copied. |
| 23 | if ( substr( $file, -4 ) !== '.php' ) { |
| 24 | continue; |
| 25 | } |
| 26 | if ( in_array( $file, $ignoreList, true ) ) { |
| 27 | continue; |
| 28 | } |
| 29 | $newFile = $renameList[ $file ] ?? $file; |
| 30 | $content = self::prepareAutoloaderFile( $file, $suffix ); |
| 31 | $written = file_put_contents( $outDir . '/' . $newFile, $content ); |
| 32 | if ( $io ) { |
| 33 | if ( $written ) { |
| 34 | $io->writeError( " <info>Generated: $newFile</info>" ); |
| 35 | } else { |
| 36 | $io->writeError( " <error>Error: $newFile</error>" ); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | private static function prepareAutoloaderFile( $filename, $suffix ) { |
| 42 | $header = self::COMMENT; |
| 43 | $header .= PHP_EOL; |
| 44 | if ( $suffix === 'Current' ) { |
| 45 | // Unit testing. |
| 46 | $header .= 'namespace Automattic\Jetpack\Autoloader\jpCurrent;'; |
| 47 | } else { |
| 48 | $header .= 'namespace Automattic\Jetpack\Autoloader\jp' . $suffix . '\al' . preg_replace( '/[^0-9a-zA-Z]/', '_', AutoloadGenerator::VERSION ) . ';'; |
| 49 | } |
| 50 | $header .= PHP_EOL . PHP_EOL; |
| 51 | $sourceLoader = fopen( __DIR__ . '/' . $filename, 'r' ); |
| 52 | $file_contents = stream_get_contents( $sourceLoader ); |
| 53 | return str_replace( |
| 54 | '/* HEADER */', |
| 55 | $header, |
| 56 | $file_contents |
| 57 | ); |
| 58 | } |
| 59 | } |
| 60 |