AutoloadFileWriter.php
11 months ago
AutoloadGenerator.php
11 months ago
AutoloadProcessor.php
11 months ago
CustomAutoloaderPlugin.php
11 months ago
ManifestGenerator.php
11 months ago
autoload.php
11 months ago
class-autoloader-handler.php
11 months ago
class-autoloader-locator.php
11 months ago
class-autoloader.php
11 months ago
class-container.php
11 months ago
class-hook-manager.php
11 months ago
class-latest-autoloader-guard.php
11 months ago
class-manifest-reader.php
11 months ago
class-path-processor.php
11 months ago
class-php-autoloader.php
11 months ago
class-plugin-locator.php
11 months ago
class-plugins-handler.php
11 months ago
class-shutdown-handler.php
11 months ago
class-version-loader.php
11 months ago
class-version-selector.php
11 months ago
index.php
11 months ago
ManifestGenerator.php
60 lines
| 1 | <?php |
| 2 | // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_export |
| 3 | namespace Automattic\Jetpack\Autoloader; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | class ManifestGenerator { |
| 6 | public static function buildManifest( $autoloaderType, $fileName, $content ) { |
| 7 | if ( empty( $content ) ) { |
| 8 | return null; |
| 9 | } |
| 10 | switch ( $autoloaderType ) { |
| 11 | case 'classmap': |
| 12 | case 'files': |
| 13 | return self::buildStandardManifest( $fileName, $content ); |
| 14 | case 'psr-4': |
| 15 | return self::buildPsr4Manifest( $fileName, $content ); |
| 16 | } |
| 17 | throw new \InvalidArgumentException( 'An invalid manifest type of ' . $autoloaderType . ' was passed!' ); |
| 18 | } |
| 19 | private static function buildStandardManifest( $fileName, $manifestData ) { |
| 20 | $fileContent = PHP_EOL; |
| 21 | foreach ( $manifestData as $key => $data ) { |
| 22 | $key = var_export( $key, true ); |
| 23 | $versionCode = var_export( $data['version'], true ); |
| 24 | $fileContent .= <<<MANIFEST_CODE |
| 25 | $key => array( |
| 26 | 'version' => $versionCode, |
| 27 | 'path' => {$data['path']} |
| 28 | ), |
| 29 | MANIFEST_CODE; |
| 30 | $fileContent .= PHP_EOL; |
| 31 | } |
| 32 | return self::buildFile( $fileName, $fileContent ); |
| 33 | } |
| 34 | private static function buildPsr4Manifest( $fileName, $namespaces ) { |
| 35 | $fileContent = PHP_EOL; |
| 36 | foreach ( $namespaces as $namespace => $data ) { |
| 37 | $namespaceCode = var_export( $namespace, true ); |
| 38 | $versionCode = var_export( $data['version'], true ); |
| 39 | $pathCode = 'array( ' . implode( ', ', $data['path'] ) . ' )'; |
| 40 | $fileContent .= <<<MANIFEST_CODE |
| 41 | $namespaceCode => array( |
| 42 | 'version' => $versionCode, |
| 43 | 'path' => $pathCode |
| 44 | ), |
| 45 | MANIFEST_CODE; |
| 46 | $fileContent .= PHP_EOL; |
| 47 | } |
| 48 | return self::buildFile( $fileName, $fileContent ); |
| 49 | } |
| 50 | private static function buildFile( $fileName, $content ) { |
| 51 | return <<<INCLUDE_FILE |
| 52 | <?php |
| 53 | // This file `$fileName` was auto generated by automattic/jetpack-autoloader. |
| 54 | \$vendorDir = dirname(__DIR__); |
| 55 | \$baseDir = dirname(\$vendorDir); |
| 56 | return array($content); |
| 57 | INCLUDE_FILE; |
| 58 | } |
| 59 | } |
| 60 |