@@ -20,93 +20,93 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class ManifestGenerator { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Builds a manifest file for the given autoloader type. |
|
| 25 | - * |
|
| 26 | - * @param string $autoloaderType The type of autoloader to build a manifest for. |
|
| 27 | - * @param string $fileName The filename of the manifest. |
|
| 28 | - * @param array $content The manifest content to generate using. |
|
| 29 | - * |
|
| 30 | - * @return string|null $manifestFile |
|
| 31 | - * @throws \InvalidArgumentException When an invalid autoloader type is given. |
|
| 32 | - */ |
|
| 33 | - public static function buildManifest( $autoloaderType, $fileName, $content ) { |
|
| 34 | - if ( empty( $content ) ) { |
|
| 35 | - return null; |
|
| 36 | - } |
|
| 23 | + /** |
|
| 24 | + * Builds a manifest file for the given autoloader type. |
|
| 25 | + * |
|
| 26 | + * @param string $autoloaderType The type of autoloader to build a manifest for. |
|
| 27 | + * @param string $fileName The filename of the manifest. |
|
| 28 | + * @param array $content The manifest content to generate using. |
|
| 29 | + * |
|
| 30 | + * @return string|null $manifestFile |
|
| 31 | + * @throws \InvalidArgumentException When an invalid autoloader type is given. |
|
| 32 | + */ |
|
| 33 | + public static function buildManifest( $autoloaderType, $fileName, $content ) { |
|
| 34 | + if ( empty( $content ) ) { |
|
| 35 | + return null; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - switch ( $autoloaderType ) { |
|
| 39 | - case 'classmap': |
|
| 40 | - case 'files': |
|
| 41 | - return self::buildStandardManifest( $fileName, $content ); |
|
| 42 | - case 'psr-4': |
|
| 43 | - return self::buildPsr4Manifest( $fileName, $content ); |
|
| 44 | - } |
|
| 38 | + switch ( $autoloaderType ) { |
|
| 39 | + case 'classmap': |
|
| 40 | + case 'files': |
|
| 41 | + return self::buildStandardManifest( $fileName, $content ); |
|
| 42 | + case 'psr-4': |
|
| 43 | + return self::buildPsr4Manifest( $fileName, $content ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - throw new \InvalidArgumentException( 'An invalid manifest type of ' . $autoloaderType . ' was passed!' ); |
|
| 47 | - } |
|
| 46 | + throw new \InvalidArgumentException( 'An invalid manifest type of ' . $autoloaderType . ' was passed!' ); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Builds the contents for the standard manifest file. |
|
| 51 | - * |
|
| 52 | - * @param string $fileName The filename we are building. |
|
| 53 | - * @param array $manifestData The formatted data for the manifest. |
|
| 54 | - * |
|
| 55 | - * @return string|null $manifestFile |
|
| 56 | - */ |
|
| 57 | - private static function buildStandardManifest( $fileName, $manifestData ) { |
|
| 58 | - $fileContent = PHP_EOL; |
|
| 59 | - foreach ( $manifestData as $key => $data ) { |
|
| 60 | - $key = var_export( $key, true ); |
|
| 61 | - $versionCode = var_export( $data['version'], true ); |
|
| 62 | - $fileContent .= <<<MANIFEST_CODE |
|
| 49 | + /** |
|
| 50 | + * Builds the contents for the standard manifest file. |
|
| 51 | + * |
|
| 52 | + * @param string $fileName The filename we are building. |
|
| 53 | + * @param array $manifestData The formatted data for the manifest. |
|
| 54 | + * |
|
| 55 | + * @return string|null $manifestFile |
|
| 56 | + */ |
|
| 57 | + private static function buildStandardManifest( $fileName, $manifestData ) { |
|
| 58 | + $fileContent = PHP_EOL; |
|
| 59 | + foreach ( $manifestData as $key => $data ) { |
|
| 60 | + $key = var_export( $key, true ); |
|
| 61 | + $versionCode = var_export( $data['version'], true ); |
|
| 62 | + $fileContent .= <<<MANIFEST_CODE |
|
| 63 | 63 | $key => array( |
| 64 | 64 | 'version' => $versionCode, |
| 65 | 65 | 'path' => {$data['path']} |
| 66 | 66 | ), |
| 67 | 67 | MANIFEST_CODE; |
| 68 | - $fileContent .= PHP_EOL; |
|
| 69 | - } |
|
| 68 | + $fileContent .= PHP_EOL; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return self::buildFile( $fileName, $fileContent ); |
|
| 72 | - } |
|
| 71 | + return self::buildFile( $fileName, $fileContent ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Builds the contents for the PSR-4 manifest file. |
|
| 76 | - * |
|
| 77 | - * @param string $fileName The filename we are building. |
|
| 78 | - * @param array $namespaces The formatted PSR-4 data for the manifest. |
|
| 79 | - * |
|
| 80 | - * @return string|null $manifestFile |
|
| 81 | - */ |
|
| 82 | - private static function buildPsr4Manifest( $fileName, $namespaces ) { |
|
| 83 | - $fileContent = PHP_EOL; |
|
| 84 | - foreach ( $namespaces as $namespace => $data ) { |
|
| 85 | - $namespaceCode = var_export( $namespace, true ); |
|
| 86 | - $versionCode = var_export( $data['version'], true ); |
|
| 87 | - $pathCode = 'array( ' . implode( ', ', $data['path'] ) . ' )'; |
|
| 88 | - $fileContent .= <<<MANIFEST_CODE |
|
| 74 | + /** |
|
| 75 | + * Builds the contents for the PSR-4 manifest file. |
|
| 76 | + * |
|
| 77 | + * @param string $fileName The filename we are building. |
|
| 78 | + * @param array $namespaces The formatted PSR-4 data for the manifest. |
|
| 79 | + * |
|
| 80 | + * @return string|null $manifestFile |
|
| 81 | + */ |
|
| 82 | + private static function buildPsr4Manifest( $fileName, $namespaces ) { |
|
| 83 | + $fileContent = PHP_EOL; |
|
| 84 | + foreach ( $namespaces as $namespace => $data ) { |
|
| 85 | + $namespaceCode = var_export( $namespace, true ); |
|
| 86 | + $versionCode = var_export( $data['version'], true ); |
|
| 87 | + $pathCode = 'array( ' . implode( ', ', $data['path'] ) . ' )'; |
|
| 88 | + $fileContent .= <<<MANIFEST_CODE |
|
| 89 | 89 | $namespaceCode => array( |
| 90 | 90 | 'version' => $versionCode, |
| 91 | 91 | 'path' => $pathCode |
| 92 | 92 | ), |
| 93 | 93 | MANIFEST_CODE; |
| 94 | - $fileContent .= PHP_EOL; |
|
| 95 | - } |
|
| 94 | + $fileContent .= PHP_EOL; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return self::buildFile( $fileName, $fileContent ); |
|
| 98 | - } |
|
| 97 | + return self::buildFile( $fileName, $fileContent ); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Generate the PHP that will be used in the file. |
|
| 102 | - * |
|
| 103 | - * @param string $fileName The filename we are building. |
|
| 104 | - * @param string $content The content to be written into the file. |
|
| 105 | - * |
|
| 106 | - * @return string $fileContent |
|
| 107 | - */ |
|
| 108 | - private static function buildFile( $fileName, $content ) { |
|
| 109 | - return <<<INCLUDE_FILE |
|
| 100 | + /** |
|
| 101 | + * Generate the PHP that will be used in the file. |
|
| 102 | + * |
|
| 103 | + * @param string $fileName The filename we are building. |
|
| 104 | + * @param string $content The content to be written into the file. |
|
| 105 | + * |
|
| 106 | + * @return string $fileContent |
|
| 107 | + */ |
|
| 108 | + private static function buildFile( $fileName, $content ) { |
|
| 109 | + return <<<INCLUDE_FILE |
|
| 110 | 110 | <?php |
| 111 | 111 | |
| 112 | 112 | // This file `$fileName` was auto generated by automattic/jetpack-autoloader. |
@@ -117,5 +117,5 @@ discard block |
||
| 117 | 117 | return array($content); |
| 118 | 118 | |
| 119 | 119 | INCLUDE_FILE; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -30,20 +30,20 @@ discard block |
||
| 30 | 30 | * @return string|null $manifestFile |
| 31 | 31 | * @throws \InvalidArgumentException When an invalid autoloader type is given. |
| 32 | 32 | */ |
| 33 | - public static function buildManifest( $autoloaderType, $fileName, $content ) { |
|
| 34 | - if ( empty( $content ) ) { |
|
| 33 | + public static function buildManifest($autoloaderType, $fileName, $content) { |
|
| 34 | + if (empty($content)) { |
|
| 35 | 35 | return null; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - switch ( $autoloaderType ) { |
|
| 38 | + switch ($autoloaderType) { |
|
| 39 | 39 | case 'classmap': |
| 40 | 40 | case 'files': |
| 41 | - return self::buildStandardManifest( $fileName, $content ); |
|
| 41 | + return self::buildStandardManifest($fileName, $content); |
|
| 42 | 42 | case 'psr-4': |
| 43 | - return self::buildPsr4Manifest( $fileName, $content ); |
|
| 43 | + return self::buildPsr4Manifest($fileName, $content); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - throw new \InvalidArgumentException( 'An invalid manifest type of ' . $autoloaderType . ' was passed!' ); |
|
| 46 | + throw new \InvalidArgumentException('An invalid manifest type of ' . $autoloaderType . ' was passed!'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return string|null $manifestFile |
| 56 | 56 | */ |
| 57 | - private static function buildStandardManifest( $fileName, $manifestData ) { |
|
| 57 | + private static function buildStandardManifest($fileName, $manifestData) { |
|
| 58 | 58 | $fileContent = PHP_EOL; |
| 59 | - foreach ( $manifestData as $key => $data ) { |
|
| 60 | - $key = var_export( $key, true ); |
|
| 61 | - $versionCode = var_export( $data['version'], true ); |
|
| 59 | + foreach ($manifestData as $key => $data) { |
|
| 60 | + $key = var_export($key, true); |
|
| 61 | + $versionCode = var_export($data['version'], true); |
|
| 62 | 62 | $fileContent .= <<<MANIFEST_CODE |
| 63 | 63 | $key => array( |
| 64 | 64 | 'version' => $versionCode, |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $fileContent .= PHP_EOL; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - return self::buildFile( $fileName, $fileContent ); |
|
| 71 | + return self::buildFile($fileName, $fileContent); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -79,22 +79,22 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return string|null $manifestFile |
| 81 | 81 | */ |
| 82 | - private static function buildPsr4Manifest( $fileName, $namespaces ) { |
|
| 82 | + private static function buildPsr4Manifest($fileName, $namespaces) { |
|
| 83 | 83 | $fileContent = PHP_EOL; |
| 84 | - foreach ( $namespaces as $namespace => $data ) { |
|
| 85 | - $namespaceCode = var_export( $namespace, true ); |
|
| 86 | - $versionCode = var_export( $data['version'], true ); |
|
| 87 | - $pathCode = 'array( ' . implode( ', ', $data['path'] ) . ' )'; |
|
| 84 | + foreach ($namespaces as $namespace => $data) { |
|
| 85 | + $namespaceCode = var_export($namespace, true); |
|
| 86 | + $versionCode = var_export($data['version'], true); |
|
| 87 | + $pathCode = 'array( ' . implode(', ', $data['path']) . ' )'; |
|
| 88 | 88 | $fileContent .= <<<MANIFEST_CODE |
| 89 | 89 | $namespaceCode => array( |
| 90 | 90 | 'version' => $versionCode, |
| 91 | 91 | 'path' => $pathCode |
| 92 | 92 | ), |
| 93 | 93 | MANIFEST_CODE; |
| 94 | - $fileContent .= PHP_EOL; |
|
| 94 | + $fileContent .= PHP_EOL; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - return self::buildFile( $fileName, $fileContent ); |
|
| 97 | + return self::buildFile($fileName, $fileContent); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return string $fileContent |
| 107 | 107 | */ |
| 108 | - private static function buildFile( $fileName, $content ) { |
|
| 108 | + private static function buildFile($fileName, $content) { |
|
| 109 | 109 | return <<<INCLUDE_FILE |
| 110 | 110 | <?php |
| 111 | 111 | |
@@ -6,77 +6,77 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class PHP_Autoloader { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Registers the autoloader with PHP so that it can begin autoloading classes. |
|
| 11 | - * |
|
| 12 | - * @param Version_Loader $version_loader The class loader to use in the autoloader. |
|
| 13 | - */ |
|
| 14 | - public function register_autoloader( $version_loader ) { |
|
| 15 | - // Make sure no other autoloaders are registered. |
|
| 16 | - $this->unregister_autoloader(); |
|
| 9 | + /** |
|
| 10 | + * Registers the autoloader with PHP so that it can begin autoloading classes. |
|
| 11 | + * |
|
| 12 | + * @param Version_Loader $version_loader The class loader to use in the autoloader. |
|
| 13 | + */ |
|
| 14 | + public function register_autoloader( $version_loader ) { |
|
| 15 | + // Make sure no other autoloaders are registered. |
|
| 16 | + $this->unregister_autoloader(); |
|
| 17 | 17 | |
| 18 | - // Set the global so that it can be used to load classes. |
|
| 19 | - global $jetpack_autoloader_loader; |
|
| 20 | - $jetpack_autoloader_loader = $version_loader; |
|
| 18 | + // Set the global so that it can be used to load classes. |
|
| 19 | + global $jetpack_autoloader_loader; |
|
| 20 | + $jetpack_autoloader_loader = $version_loader; |
|
| 21 | 21 | |
| 22 | - // Ensure that the autoloader is first to avoid contention with others. |
|
| 23 | - spl_autoload_register( array( self::class, 'load_class' ), true, true ); |
|
| 24 | - } |
|
| 22 | + // Ensure that the autoloader is first to avoid contention with others. |
|
| 23 | + spl_autoload_register( array( self::class, 'load_class' ), true, true ); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Unregisters the active autoloader so that it will no longer autoload classes. |
|
| 28 | - */ |
|
| 29 | - public function unregister_autoloader() { |
|
| 30 | - // Remove any v2 autoloader that we've already registered. |
|
| 31 | - $autoload_chain = spl_autoload_functions(); |
|
| 32 | - foreach ( $autoload_chain as $autoloader ) { |
|
| 33 | - // We can identify a v2 autoloader using the namespace. |
|
| 34 | - $namespace_check = null; |
|
| 26 | + /** |
|
| 27 | + * Unregisters the active autoloader so that it will no longer autoload classes. |
|
| 28 | + */ |
|
| 29 | + public function unregister_autoloader() { |
|
| 30 | + // Remove any v2 autoloader that we've already registered. |
|
| 31 | + $autoload_chain = spl_autoload_functions(); |
|
| 32 | + foreach ( $autoload_chain as $autoloader ) { |
|
| 33 | + // We can identify a v2 autoloader using the namespace. |
|
| 34 | + $namespace_check = null; |
|
| 35 | 35 | |
| 36 | - // Functions are recorded as strings. |
|
| 37 | - if ( is_string( $autoloader ) ) { |
|
| 38 | - $namespace_check = $autoloader; |
|
| 39 | - } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { |
|
| 40 | - // Static method calls have the class as the first array element. |
|
| 41 | - $namespace_check = $autoloader[0]; |
|
| 42 | - } else { |
|
| 43 | - // Since the autoloader has only ever been a function or a static method we don't currently need to check anything else. |
|
| 44 | - continue; |
|
| 45 | - } |
|
| 36 | + // Functions are recorded as strings. |
|
| 37 | + if ( is_string( $autoloader ) ) { |
|
| 38 | + $namespace_check = $autoloader; |
|
| 39 | + } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { |
|
| 40 | + // Static method calls have the class as the first array element. |
|
| 41 | + $namespace_check = $autoloader[0]; |
|
| 42 | + } else { |
|
| 43 | + // Since the autoloader has only ever been a function or a static method we don't currently need to check anything else. |
|
| 44 | + continue; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // Check for the namespace without the generated suffix. |
|
| 48 | - if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { |
|
| 49 | - spl_autoload_unregister( $autoloader ); |
|
| 50 | - } |
|
| 51 | - } |
|
| 47 | + // Check for the namespace without the generated suffix. |
|
| 48 | + if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { |
|
| 49 | + spl_autoload_unregister( $autoloader ); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // Clear the global now that the autoloader has been unregistered. |
|
| 54 | - global $jetpack_autoloader_loader; |
|
| 55 | - $jetpack_autoloader_loader = null; |
|
| 56 | - } |
|
| 53 | + // Clear the global now that the autoloader has been unregistered. |
|
| 54 | + global $jetpack_autoloader_loader; |
|
| 55 | + $jetpack_autoloader_loader = null; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Loads a class file if one could be found. |
|
| 60 | - * |
|
| 61 | - * Note: This function is static so that the autoloader can be easily unregistered. If |
|
| 62 | - * it was a class method we would have to unwrap the object to check the namespace. |
|
| 63 | - * |
|
| 64 | - * @param string $class_name The name of the class to autoload. |
|
| 65 | - * |
|
| 66 | - * @return bool Indicates whether or not a class file was loaded. |
|
| 67 | - */ |
|
| 68 | - public static function load_class( $class_name ) { |
|
| 69 | - global $jetpack_autoloader_loader; |
|
| 70 | - if ( ! isset( $jetpack_autoloader_loader ) ) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 58 | + /** |
|
| 59 | + * Loads a class file if one could be found. |
|
| 60 | + * |
|
| 61 | + * Note: This function is static so that the autoloader can be easily unregistered. If |
|
| 62 | + * it was a class method we would have to unwrap the object to check the namespace. |
|
| 63 | + * |
|
| 64 | + * @param string $class_name The name of the class to autoload. |
|
| 65 | + * |
|
| 66 | + * @return bool Indicates whether or not a class file was loaded. |
|
| 67 | + */ |
|
| 68 | + public static function load_class( $class_name ) { |
|
| 69 | + global $jetpack_autoloader_loader; |
|
| 70 | + if ( ! isset( $jetpack_autoloader_loader ) ) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $file = $jetpack_autoloader_loader->find_class_file( $class_name ); |
|
| 75 | - if ( ! isset( $file ) ) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 74 | + $file = $jetpack_autoloader_loader->find_class_file( $class_name ); |
|
| 75 | + if ( ! isset( $file ) ) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - require $file; |
|
| 80 | - return true; |
|
| 81 | - } |
|
| 79 | + require $file; |
|
| 80 | + return true; |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * |
| 12 | 12 | * @param Version_Loader $version_loader The class loader to use in the autoloader. |
| 13 | 13 | */ |
| 14 | - public function register_autoloader( $version_loader ) { |
|
| 14 | + public function register_autoloader($version_loader) { |
|
| 15 | 15 | // Make sure no other autoloaders are registered. |
| 16 | 16 | $this->unregister_autoloader(); |
| 17 | 17 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | $jetpack_autoloader_loader = $version_loader; |
| 21 | 21 | |
| 22 | 22 | // Ensure that the autoloader is first to avoid contention with others. |
| 23 | - spl_autoload_register( array( self::class, 'load_class' ), true, true ); |
|
| 23 | + spl_autoload_register(array(self::class, 'load_class'), true, true); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | public function unregister_autoloader() { |
| 30 | 30 | // Remove any v2 autoloader that we've already registered. |
| 31 | 31 | $autoload_chain = spl_autoload_functions(); |
| 32 | - foreach ( $autoload_chain as $autoloader ) { |
|
| 32 | + foreach ($autoload_chain as $autoloader) { |
|
| 33 | 33 | // We can identify a v2 autoloader using the namespace. |
| 34 | 34 | $namespace_check = null; |
| 35 | 35 | |
| 36 | 36 | // Functions are recorded as strings. |
| 37 | - if ( is_string( $autoloader ) ) { |
|
| 37 | + if (is_string($autoloader)) { |
|
| 38 | 38 | $namespace_check = $autoloader; |
| 39 | - } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { |
|
| 39 | + } elseif (is_array($autoloader) && is_string($autoloader[0])) { |
|
| 40 | 40 | // Static method calls have the class as the first array element. |
| 41 | 41 | $namespace_check = $autoloader[0]; |
| 42 | 42 | } else { |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Check for the namespace without the generated suffix. |
| 48 | - if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { |
|
| 49 | - spl_autoload_unregister( $autoloader ); |
|
| 48 | + if ('Automattic\\Jetpack\\Autoloader\\jp' === substr($namespace_check, 0, 32)) { |
|
| 49 | + spl_autoload_unregister($autoloader); |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return bool Indicates whether or not a class file was loaded. |
| 67 | 67 | */ |
| 68 | - public static function load_class( $class_name ) { |
|
| 68 | + public static function load_class($class_name) { |
|
| 69 | 69 | global $jetpack_autoloader_loader; |
| 70 | - if ( ! isset( $jetpack_autoloader_loader ) ) { |
|
| 70 | + if (!isset($jetpack_autoloader_loader)) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $file = $jetpack_autoloader_loader->find_class_file( $class_name ); |
|
| 75 | - if ( ! isset( $file ) ) { |
|
| 74 | + $file = $jetpack_autoloader_loader->find_class_file($class_name); |
|
| 75 | + if (!isset($file)) { |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -6,79 +6,79 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Shutdown_Handler { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The Plugins_Handler instance. |
|
| 11 | - * |
|
| 12 | - * @var Plugins_Handler |
|
| 13 | - */ |
|
| 14 | - private $plugins_handler; |
|
| 9 | + /** |
|
| 10 | + * The Plugins_Handler instance. |
|
| 11 | + * |
|
| 12 | + * @var Plugins_Handler |
|
| 13 | + */ |
|
| 14 | + private $plugins_handler; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The plugins cached by this autoloader. |
|
| 18 | - * |
|
| 19 | - * @var string[] |
|
| 20 | - */ |
|
| 21 | - private $cached_plugins; |
|
| 16 | + /** |
|
| 17 | + * The plugins cached by this autoloader. |
|
| 18 | + * |
|
| 19 | + * @var string[] |
|
| 20 | + */ |
|
| 21 | + private $cached_plugins; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Indicates whether or not this autoloader was included by another. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - private $was_included_by_autoloader; |
|
| 23 | + /** |
|
| 24 | + * Indicates whether or not this autoloader was included by another. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + private $was_included_by_autoloader; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param Plugins_Handler $plugins_handler The Plugins_Handler instance to use. |
|
| 34 | - * @param string[] $cached_plugins The plugins cached by the autoloaer. |
|
| 35 | - * @param bool $was_included_by_autoloader Indicates whether or not the autoloader was included by another. |
|
| 36 | - */ |
|
| 37 | - public function __construct( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) { |
|
| 38 | - $this->plugins_handler = $plugins_handler; |
|
| 39 | - $this->cached_plugins = $cached_plugins; |
|
| 40 | - $this->was_included_by_autoloader = $was_included_by_autoloader; |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param Plugins_Handler $plugins_handler The Plugins_Handler instance to use. |
|
| 34 | + * @param string[] $cached_plugins The plugins cached by the autoloaer. |
|
| 35 | + * @param bool $was_included_by_autoloader Indicates whether or not the autoloader was included by another. |
|
| 36 | + */ |
|
| 37 | + public function __construct( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) { |
|
| 38 | + $this->plugins_handler = $plugins_handler; |
|
| 39 | + $this->cached_plugins = $cached_plugins; |
|
| 40 | + $this->was_included_by_autoloader = $was_included_by_autoloader; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Handles the shutdown of the autoloader. |
|
| 45 | - */ |
|
| 46 | - public function __invoke() { |
|
| 47 | - // Don't save a broken cache if an error happens during some plugin's initialization. |
|
| 48 | - if ( ! did_action( 'plugins_loaded' ) ) { |
|
| 49 | - // Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame. |
|
| 50 | - if ( ! empty( $this->cached_plugins ) ) { |
|
| 51 | - $this->plugins_handler->cache_plugins( array() ); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * Handles the shutdown of the autoloader. |
|
| 45 | + */ |
|
| 46 | + public function __invoke() { |
|
| 47 | + // Don't save a broken cache if an error happens during some plugin's initialization. |
|
| 48 | + if ( ! did_action( 'plugins_loaded' ) ) { |
|
| 49 | + // Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame. |
|
| 50 | + if ( ! empty( $this->cached_plugins ) ) { |
|
| 51 | + $this->plugins_handler->cache_plugins( array() ); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return; |
|
| 55 | - } |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - // Load the active plugins fresh since the list we pulled earlier might not contain |
|
| 58 | - // plugins that were activated but did not reset the autoloader. This happens |
|
| 59 | - // when a plugin is in the cache but not "active" when the autoloader loads. |
|
| 60 | - // We also want to make sure that plugins which are deactivating are not |
|
| 61 | - // considered "active" so that they will be removed from the cache now. |
|
| 62 | - try { |
|
| 63 | - $active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader ); |
|
| 64 | - } catch ( \Exception $ex ) { |
|
| 65 | - // When the package is deleted before shutdown it will throw an exception. |
|
| 66 | - // In the event this happens we should erase the cache. |
|
| 67 | - if ( ! empty( $this->cached_plugins ) ) { |
|
| 68 | - $this->plugins_handler->cache_plugins( array() ); |
|
| 69 | - } |
|
| 70 | - return; |
|
| 71 | - } |
|
| 57 | + // Load the active plugins fresh since the list we pulled earlier might not contain |
|
| 58 | + // plugins that were activated but did not reset the autoloader. This happens |
|
| 59 | + // when a plugin is in the cache but not "active" when the autoloader loads. |
|
| 60 | + // We also want to make sure that plugins which are deactivating are not |
|
| 61 | + // considered "active" so that they will be removed from the cache now. |
|
| 62 | + try { |
|
| 63 | + $active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader ); |
|
| 64 | + } catch ( \Exception $ex ) { |
|
| 65 | + // When the package is deleted before shutdown it will throw an exception. |
|
| 66 | + // In the event this happens we should erase the cache. |
|
| 67 | + if ( ! empty( $this->cached_plugins ) ) { |
|
| 68 | + $this->plugins_handler->cache_plugins( array() ); |
|
| 69 | + } |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // The paths should be sorted for easy comparisons with those loaded from the cache. |
|
| 74 | - // Note we don't need to sort the cached entries because they're already sorted. |
|
| 75 | - sort( $active_plugins ); |
|
| 73 | + // The paths should be sorted for easy comparisons with those loaded from the cache. |
|
| 74 | + // Note we don't need to sort the cached entries because they're already sorted. |
|
| 75 | + sort( $active_plugins ); |
|
| 76 | 76 | |
| 77 | - // We don't want to waste time saving a cache that hasn't changed. |
|
| 78 | - if ( $this->cached_plugins === $active_plugins ) { |
|
| 79 | - return; |
|
| 80 | - } |
|
| 77 | + // We don't want to waste time saving a cache that hasn't changed. |
|
| 78 | + if ( $this->cached_plugins === $active_plugins ) { |
|
| 79 | + return; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $this->plugins_handler->cache_plugins( $active_plugins ); |
|
| 83 | - } |
|
| 82 | + $this->plugins_handler->cache_plugins( $active_plugins ); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string[] $cached_plugins The plugins cached by the autoloaer. |
| 35 | 35 | * @param bool $was_included_by_autoloader Indicates whether or not the autoloader was included by another. |
| 36 | 36 | */ |
| 37 | - public function __construct( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) { |
|
| 37 | + public function __construct($plugins_handler, $cached_plugins, $was_included_by_autoloader) { |
|
| 38 | 38 | $this->plugins_handler = $plugins_handler; |
| 39 | 39 | $this->cached_plugins = $cached_plugins; |
| 40 | 40 | $this->was_included_by_autoloader = $was_included_by_autoloader; |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function __invoke() { |
| 47 | 47 | // Don't save a broken cache if an error happens during some plugin's initialization. |
| 48 | - if ( ! did_action( 'plugins_loaded' ) ) { |
|
| 48 | + if (!did_action('plugins_loaded')) { |
|
| 49 | 49 | // Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame. |
| 50 | - if ( ! empty( $this->cached_plugins ) ) { |
|
| 51 | - $this->plugins_handler->cache_plugins( array() ); |
|
| 50 | + if (!empty($this->cached_plugins)) { |
|
| 51 | + $this->plugins_handler->cache_plugins(array()); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return; |
@@ -60,25 +60,25 @@ discard block |
||
| 60 | 60 | // We also want to make sure that plugins which are deactivating are not |
| 61 | 61 | // considered "active" so that they will be removed from the cache now. |
| 62 | 62 | try { |
| 63 | - $active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader ); |
|
| 64 | - } catch ( \Exception $ex ) { |
|
| 63 | + $active_plugins = $this->plugins_handler->get_active_plugins(false, !$this->was_included_by_autoloader); |
|
| 64 | + } catch (\Exception $ex) { |
|
| 65 | 65 | // When the package is deleted before shutdown it will throw an exception. |
| 66 | 66 | // In the event this happens we should erase the cache. |
| 67 | - if ( ! empty( $this->cached_plugins ) ) { |
|
| 68 | - $this->plugins_handler->cache_plugins( array() ); |
|
| 67 | + if (!empty($this->cached_plugins)) { |
|
| 68 | + $this->plugins_handler->cache_plugins(array()); |
|
| 69 | 69 | } |
| 70 | 70 | return; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // The paths should be sorted for easy comparisons with those loaded from the cache. |
| 74 | 74 | // Note we don't need to sort the cached entries because they're already sorted. |
| 75 | - sort( $active_plugins ); |
|
| 75 | + sort($active_plugins); |
|
| 76 | 76 | |
| 77 | 77 | // We don't want to waste time saving a cache that hasn't changed. |
| 78 | - if ( $this->cached_plugins === $active_plugins ) { |
|
| 78 | + if ($this->cached_plugins === $active_plugins) { |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $this->plugins_handler->cache_plugins( $active_plugins ); |
|
| 82 | + $this->plugins_handler->cache_plugins($active_plugins); |
|
| 83 | 83 | } |
| 84 | 84 | } |
@@ -8,132 +8,132 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Autoloader_Handler { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * The PHP_Autoloader instance. |
|
| 13 | - * |
|
| 14 | - * @var PHP_Autoloader |
|
| 15 | - */ |
|
| 16 | - private $php_autoloader; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * The Hook_Manager instance. |
|
| 20 | - * |
|
| 21 | - * @var Hook_Manager |
|
| 22 | - */ |
|
| 23 | - private $hook_manager; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The Manifest_Reader instance. |
|
| 27 | - * |
|
| 28 | - * @var Manifest_Reader |
|
| 29 | - */ |
|
| 30 | - private $manifest_reader; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The Version_Selector instance. |
|
| 34 | - * |
|
| 35 | - * @var Version_Selector |
|
| 36 | - */ |
|
| 37 | - private $version_selector; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * The constructor. |
|
| 41 | - * |
|
| 42 | - * @param PHP_Autoloader $php_autoloader The PHP_Autoloader instance. |
|
| 43 | - * @param Hook_Manager $hook_manager The Hook_Manager instance. |
|
| 44 | - * @param Manifest_Reader $manifest_reader The Manifest_Reader instance. |
|
| 45 | - * @param Version_Selector $version_selector The Version_Selector instance. |
|
| 46 | - */ |
|
| 47 | - public function __construct( $php_autoloader, $hook_manager, $manifest_reader, $version_selector ) { |
|
| 48 | - $this->php_autoloader = $php_autoloader; |
|
| 49 | - $this->hook_manager = $hook_manager; |
|
| 50 | - $this->manifest_reader = $manifest_reader; |
|
| 51 | - $this->version_selector = $version_selector; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Checks to see whether or not an autoloader is currently in the process of initializing. |
|
| 56 | - * |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - public function is_initializing() { |
|
| 60 | - // If no version has been set it means that no autoloader has started initializing yet. |
|
| 61 | - global $jetpack_autoloader_latest_version; |
|
| 62 | - if ( ! isset( $jetpack_autoloader_latest_version ) ) { |
|
| 63 | - return false; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // When the version is set but the classmap is not it ALWAYS means that this is the |
|
| 67 | - // latest autoloader and is being included by an older one. |
|
| 68 | - global $jetpack_packages_classmap; |
|
| 69 | - if ( empty( $jetpack_packages_classmap ) ) { |
|
| 70 | - return true; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // Version 2.4.0 added a new global and altered the reset semantics. We need to check |
|
| 74 | - // the other global as well since it may also point at initialization. |
|
| 75 | - // Note: We don't need to check for the class first because every autoloader that |
|
| 76 | - // will set the latest version global requires this class in the classmap. |
|
| 77 | - $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version']; |
|
| 78 | - if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) { |
|
| 79 | - global $jetpack_autoloader_loader; |
|
| 80 | - if ( ! isset( $jetpack_autoloader_loader ) ) { |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return false; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Activates an autoloader using the given plugins and activates it. |
|
| 90 | - * |
|
| 91 | - * @param string[] $plugins The plugins to initialize the autoloader for. |
|
| 92 | - */ |
|
| 93 | - public function activate_autoloader( $plugins ) { |
|
| 94 | - global $jetpack_packages_psr4; |
|
| 95 | - $jetpack_packages_psr4 = array(); |
|
| 96 | - $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 ); |
|
| 97 | - |
|
| 98 | - global $jetpack_packages_classmap; |
|
| 99 | - $jetpack_packages_classmap = array(); |
|
| 100 | - $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap ); |
|
| 101 | - |
|
| 102 | - global $jetpack_packages_filemap; |
|
| 103 | - $jetpack_packages_filemap = array(); |
|
| 104 | - $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap ); |
|
| 105 | - |
|
| 106 | - $loader = new Version_Loader( |
|
| 107 | - $this->version_selector, |
|
| 108 | - $jetpack_packages_classmap, |
|
| 109 | - $jetpack_packages_psr4, |
|
| 110 | - $jetpack_packages_filemap |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - $this->php_autoloader->register_autoloader( $loader ); |
|
| 114 | - |
|
| 115 | - // Now that the autoloader is active we can load the filemap. |
|
| 116 | - $loader->load_filemap(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Resets the active autoloader and all related global state. |
|
| 121 | - */ |
|
| 122 | - public function reset_autoloader() { |
|
| 123 | - $this->php_autoloader->unregister_autoloader(); |
|
| 124 | - $this->hook_manager->reset(); |
|
| 125 | - |
|
| 126 | - // Clear all of the autoloader globals so that older autoloaders don't do anything strange. |
|
| 127 | - global $jetpack_autoloader_latest_version; |
|
| 128 | - $jetpack_autoloader_latest_version = null; |
|
| 129 | - |
|
| 130 | - global $jetpack_packages_classmap; |
|
| 131 | - $jetpack_packages_classmap = array(); // Must be array to avoid exceptions in old autoloaders! |
|
| 132 | - |
|
| 133 | - global $jetpack_packages_psr4; |
|
| 134 | - $jetpack_packages_psr4 = array(); // Must be array to avoid exceptions in old autoloaders! |
|
| 135 | - |
|
| 136 | - global $jetpack_packages_filemap; |
|
| 137 | - $jetpack_packages_filemap = array(); // Must be array to avoid exceptions in old autoloaders! |
|
| 138 | - } |
|
| 11 | + /** |
|
| 12 | + * The PHP_Autoloader instance. |
|
| 13 | + * |
|
| 14 | + * @var PHP_Autoloader |
|
| 15 | + */ |
|
| 16 | + private $php_autoloader; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * The Hook_Manager instance. |
|
| 20 | + * |
|
| 21 | + * @var Hook_Manager |
|
| 22 | + */ |
|
| 23 | + private $hook_manager; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The Manifest_Reader instance. |
|
| 27 | + * |
|
| 28 | + * @var Manifest_Reader |
|
| 29 | + */ |
|
| 30 | + private $manifest_reader; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The Version_Selector instance. |
|
| 34 | + * |
|
| 35 | + * @var Version_Selector |
|
| 36 | + */ |
|
| 37 | + private $version_selector; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * The constructor. |
|
| 41 | + * |
|
| 42 | + * @param PHP_Autoloader $php_autoloader The PHP_Autoloader instance. |
|
| 43 | + * @param Hook_Manager $hook_manager The Hook_Manager instance. |
|
| 44 | + * @param Manifest_Reader $manifest_reader The Manifest_Reader instance. |
|
| 45 | + * @param Version_Selector $version_selector The Version_Selector instance. |
|
| 46 | + */ |
|
| 47 | + public function __construct( $php_autoloader, $hook_manager, $manifest_reader, $version_selector ) { |
|
| 48 | + $this->php_autoloader = $php_autoloader; |
|
| 49 | + $this->hook_manager = $hook_manager; |
|
| 50 | + $this->manifest_reader = $manifest_reader; |
|
| 51 | + $this->version_selector = $version_selector; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Checks to see whether or not an autoloader is currently in the process of initializing. |
|
| 56 | + * |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + public function is_initializing() { |
|
| 60 | + // If no version has been set it means that no autoloader has started initializing yet. |
|
| 61 | + global $jetpack_autoloader_latest_version; |
|
| 62 | + if ( ! isset( $jetpack_autoloader_latest_version ) ) { |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // When the version is set but the classmap is not it ALWAYS means that this is the |
|
| 67 | + // latest autoloader and is being included by an older one. |
|
| 68 | + global $jetpack_packages_classmap; |
|
| 69 | + if ( empty( $jetpack_packages_classmap ) ) { |
|
| 70 | + return true; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // Version 2.4.0 added a new global and altered the reset semantics. We need to check |
|
| 74 | + // the other global as well since it may also point at initialization. |
|
| 75 | + // Note: We don't need to check for the class first because every autoloader that |
|
| 76 | + // will set the latest version global requires this class in the classmap. |
|
| 77 | + $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version']; |
|
| 78 | + if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) { |
|
| 79 | + global $jetpack_autoloader_loader; |
|
| 80 | + if ( ! isset( $jetpack_autoloader_loader ) ) { |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return false; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Activates an autoloader using the given plugins and activates it. |
|
| 90 | + * |
|
| 91 | + * @param string[] $plugins The plugins to initialize the autoloader for. |
|
| 92 | + */ |
|
| 93 | + public function activate_autoloader( $plugins ) { |
|
| 94 | + global $jetpack_packages_psr4; |
|
| 95 | + $jetpack_packages_psr4 = array(); |
|
| 96 | + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 ); |
|
| 97 | + |
|
| 98 | + global $jetpack_packages_classmap; |
|
| 99 | + $jetpack_packages_classmap = array(); |
|
| 100 | + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap ); |
|
| 101 | + |
|
| 102 | + global $jetpack_packages_filemap; |
|
| 103 | + $jetpack_packages_filemap = array(); |
|
| 104 | + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap ); |
|
| 105 | + |
|
| 106 | + $loader = new Version_Loader( |
|
| 107 | + $this->version_selector, |
|
| 108 | + $jetpack_packages_classmap, |
|
| 109 | + $jetpack_packages_psr4, |
|
| 110 | + $jetpack_packages_filemap |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + $this->php_autoloader->register_autoloader( $loader ); |
|
| 114 | + |
|
| 115 | + // Now that the autoloader is active we can load the filemap. |
|
| 116 | + $loader->load_filemap(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Resets the active autoloader and all related global state. |
|
| 121 | + */ |
|
| 122 | + public function reset_autoloader() { |
|
| 123 | + $this->php_autoloader->unregister_autoloader(); |
|
| 124 | + $this->hook_manager->reset(); |
|
| 125 | + |
|
| 126 | + // Clear all of the autoloader globals so that older autoloaders don't do anything strange. |
|
| 127 | + global $jetpack_autoloader_latest_version; |
|
| 128 | + $jetpack_autoloader_latest_version = null; |
|
| 129 | + |
|
| 130 | + global $jetpack_packages_classmap; |
|
| 131 | + $jetpack_packages_classmap = array(); // Must be array to avoid exceptions in old autoloaders! |
|
| 132 | + |
|
| 133 | + global $jetpack_packages_psr4; |
|
| 134 | + $jetpack_packages_psr4 = array(); // Must be array to avoid exceptions in old autoloaders! |
|
| 135 | + |
|
| 136 | + global $jetpack_packages_filemap; |
|
| 137 | + $jetpack_packages_filemap = array(); // Must be array to avoid exceptions in old autoloaders! |
|
| 138 | + } |
|
| 139 | 139 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param Manifest_Reader $manifest_reader The Manifest_Reader instance. |
| 45 | 45 | * @param Version_Selector $version_selector The Version_Selector instance. |
| 46 | 46 | */ |
| 47 | - public function __construct( $php_autoloader, $hook_manager, $manifest_reader, $version_selector ) { |
|
| 47 | + public function __construct($php_autoloader, $hook_manager, $manifest_reader, $version_selector) { |
|
| 48 | 48 | $this->php_autoloader = $php_autoloader; |
| 49 | 49 | $this->hook_manager = $hook_manager; |
| 50 | 50 | $this->manifest_reader = $manifest_reader; |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | public function is_initializing() { |
| 60 | 60 | // If no version has been set it means that no autoloader has started initializing yet. |
| 61 | 61 | global $jetpack_autoloader_latest_version; |
| 62 | - if ( ! isset( $jetpack_autoloader_latest_version ) ) { |
|
| 62 | + if (!isset($jetpack_autoloader_latest_version)) { |
|
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // When the version is set but the classmap is not it ALWAYS means that this is the |
| 67 | 67 | // latest autoloader and is being included by an older one. |
| 68 | 68 | global $jetpack_packages_classmap; |
| 69 | - if ( empty( $jetpack_packages_classmap ) ) { |
|
| 69 | + if (empty($jetpack_packages_classmap)) { |
|
| 70 | 70 | return true; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | // the other global as well since it may also point at initialization. |
| 75 | 75 | // Note: We don't need to check for the class first because every autoloader that |
| 76 | 76 | // will set the latest version global requires this class in the classmap. |
| 77 | - $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version']; |
|
| 78 | - if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) { |
|
| 77 | + $replacing_version = $jetpack_packages_classmap[AutoloadGenerator::class]['version']; |
|
| 78 | + if ($this->version_selector->is_dev_version($replacing_version) || version_compare($replacing_version, '2.4.0.0', '>=')) { |
|
| 79 | 79 | global $jetpack_autoloader_loader; |
| 80 | - if ( ! isset( $jetpack_autoloader_loader ) ) { |
|
| 80 | + if (!isset($jetpack_autoloader_loader)) { |
|
| 81 | 81 | return true; |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @param string[] $plugins The plugins to initialize the autoloader for. |
| 92 | 92 | */ |
| 93 | - public function activate_autoloader( $plugins ) { |
|
| 93 | + public function activate_autoloader($plugins) { |
|
| 94 | 94 | global $jetpack_packages_psr4; |
| 95 | 95 | $jetpack_packages_psr4 = array(); |
| 96 | - $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 ); |
|
| 96 | + $this->manifest_reader->read_manifests($plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4); |
|
| 97 | 97 | |
| 98 | 98 | global $jetpack_packages_classmap; |
| 99 | 99 | $jetpack_packages_classmap = array(); |
| 100 | - $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap ); |
|
| 100 | + $this->manifest_reader->read_manifests($plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap); |
|
| 101 | 101 | |
| 102 | 102 | global $jetpack_packages_filemap; |
| 103 | 103 | $jetpack_packages_filemap = array(); |
| 104 | - $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap ); |
|
| 104 | + $this->manifest_reader->read_manifests($plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap); |
|
| 105 | 105 | |
| 106 | 106 | $loader = new Version_Loader( |
| 107 | 107 | $this->version_selector, |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $jetpack_packages_filemap |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | - $this->php_autoloader->register_autoloader( $loader ); |
|
| 113 | + $this->php_autoloader->register_autoloader($loader); |
|
| 114 | 114 | |
| 115 | 115 | // Now that the autoloader is active we can load the filemap. |
| 116 | 116 | $loader->load_filemap(); |
@@ -6,86 +6,86 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Manifest_Reader { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The Version_Selector object. |
|
| 11 | - * |
|
| 12 | - * @var Version_Selector |
|
| 13 | - */ |
|
| 14 | - private $version_selector; |
|
| 9 | + /** |
|
| 10 | + * The Version_Selector object. |
|
| 11 | + * |
|
| 12 | + * @var Version_Selector |
|
| 13 | + */ |
|
| 14 | + private $version_selector; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The constructor. |
|
| 18 | - * |
|
| 19 | - * @param Version_Selector $version_selector The Version_Selector object. |
|
| 20 | - */ |
|
| 21 | - public function __construct( $version_selector ) { |
|
| 22 | - $this->version_selector = $version_selector; |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * The constructor. |
|
| 18 | + * |
|
| 19 | + * @param Version_Selector $version_selector The Version_Selector object. |
|
| 20 | + */ |
|
| 21 | + public function __construct( $version_selector ) { |
|
| 22 | + $this->version_selector = $version_selector; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Reads all of the manifests in the given plugin paths. |
|
| 27 | - * |
|
| 28 | - * @param array $plugin_paths The paths to the plugins we're loading the manifest in. |
|
| 29 | - * @param string $manifest_path The path that we're loading the manifest from in each plugin. |
|
| 30 | - * @param array $path_map The path map to add the contents of the manifests to. |
|
| 31 | - * |
|
| 32 | - * @return array $path_map The path map we've built using the manifests in each plugin. |
|
| 33 | - */ |
|
| 34 | - public function read_manifests( $plugin_paths, $manifest_path, &$path_map ) { |
|
| 35 | - $file_paths = array_map( |
|
| 36 | - function ( $path ) use ( $manifest_path ) { |
|
| 37 | - return trailingslashit( $path ) . $manifest_path; |
|
| 38 | - }, |
|
| 39 | - $plugin_paths |
|
| 40 | - ); |
|
| 25 | + /** |
|
| 26 | + * Reads all of the manifests in the given plugin paths. |
|
| 27 | + * |
|
| 28 | + * @param array $plugin_paths The paths to the plugins we're loading the manifest in. |
|
| 29 | + * @param string $manifest_path The path that we're loading the manifest from in each plugin. |
|
| 30 | + * @param array $path_map The path map to add the contents of the manifests to. |
|
| 31 | + * |
|
| 32 | + * @return array $path_map The path map we've built using the manifests in each plugin. |
|
| 33 | + */ |
|
| 34 | + public function read_manifests( $plugin_paths, $manifest_path, &$path_map ) { |
|
| 35 | + $file_paths = array_map( |
|
| 36 | + function ( $path ) use ( $manifest_path ) { |
|
| 37 | + return trailingslashit( $path ) . $manifest_path; |
|
| 38 | + }, |
|
| 39 | + $plugin_paths |
|
| 40 | + ); |
|
| 41 | 41 | |
| 42 | - foreach ( $file_paths as $path ) { |
|
| 43 | - $this->register_manifest( $path, $path_map ); |
|
| 44 | - } |
|
| 42 | + foreach ( $file_paths as $path ) { |
|
| 43 | + $this->register_manifest( $path, $path_map ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return $path_map; |
|
| 47 | - } |
|
| 46 | + return $path_map; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Registers a plugin's manifest file with the path map. |
|
| 51 | - * |
|
| 52 | - * @param string $manifest_path The absolute path to the manifest that we're loading. |
|
| 53 | - * @param array $path_map The path map to add the contents of the manifest to. |
|
| 54 | - */ |
|
| 55 | - protected function register_manifest( $manifest_path, &$path_map ) { |
|
| 56 | - if ( ! is_readable( $manifest_path ) ) { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * Registers a plugin's manifest file with the path map. |
|
| 51 | + * |
|
| 52 | + * @param string $manifest_path The absolute path to the manifest that we're loading. |
|
| 53 | + * @param array $path_map The path map to add the contents of the manifest to. |
|
| 54 | + */ |
|
| 55 | + protected function register_manifest( $manifest_path, &$path_map ) { |
|
| 56 | + if ( ! is_readable( $manifest_path ) ) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $manifest = require $manifest_path; |
|
| 61 | - if ( ! is_array( $manifest ) ) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 60 | + $manifest = require $manifest_path; |
|
| 61 | + if ( ! is_array( $manifest ) ) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - foreach ( $manifest as $key => $data ) { |
|
| 66 | - $this->register_record( $key, $data, $path_map ); |
|
| 67 | - } |
|
| 68 | - } |
|
| 65 | + foreach ( $manifest as $key => $data ) { |
|
| 66 | + $this->register_record( $key, $data, $path_map ); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Registers an entry from the manifest in the path map. |
|
| 72 | - * |
|
| 73 | - * @param string $key The identifier for the entry we're registering. |
|
| 74 | - * @param array $data The data for the entry we're registering. |
|
| 75 | - * @param array $path_map The path map to add the contents of the manifest to. |
|
| 76 | - */ |
|
| 77 | - protected function register_record( $key, $data, &$path_map ) { |
|
| 78 | - if ( isset( $path_map[ $key ]['version'] ) ) { |
|
| 79 | - $selected_version = $path_map[ $key ]['version']; |
|
| 80 | - } else { |
|
| 81 | - $selected_version = null; |
|
| 82 | - } |
|
| 70 | + /** |
|
| 71 | + * Registers an entry from the manifest in the path map. |
|
| 72 | + * |
|
| 73 | + * @param string $key The identifier for the entry we're registering. |
|
| 74 | + * @param array $data The data for the entry we're registering. |
|
| 75 | + * @param array $path_map The path map to add the contents of the manifest to. |
|
| 76 | + */ |
|
| 77 | + protected function register_record( $key, $data, &$path_map ) { |
|
| 78 | + if ( isset( $path_map[ $key ]['version'] ) ) { |
|
| 79 | + $selected_version = $path_map[ $key ]['version']; |
|
| 80 | + } else { |
|
| 81 | + $selected_version = null; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if ( $this->version_selector->is_version_update_required( $selected_version, $data['version'] ) ) { |
|
| 85 | - $path_map[ $key ] = array( |
|
| 86 | - 'version' => $data['version'], |
|
| 87 | - 'path' => $data['path'], |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - } |
|
| 84 | + if ( $this->version_selector->is_version_update_required( $selected_version, $data['version'] ) ) { |
|
| 85 | + $path_map[ $key ] = array( |
|
| 86 | + 'version' => $data['version'], |
|
| 87 | + 'path' => $data['path'], |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param Version_Selector $version_selector The Version_Selector object. |
| 20 | 20 | */ |
| 21 | - public function __construct( $version_selector ) { |
|
| 21 | + public function __construct($version_selector) { |
|
| 22 | 22 | $this->version_selector = $version_selector; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return array $path_map The path map we've built using the manifests in each plugin. |
| 33 | 33 | */ |
| 34 | - public function read_manifests( $plugin_paths, $manifest_path, &$path_map ) { |
|
| 34 | + public function read_manifests($plugin_paths, $manifest_path, &$path_map) { |
|
| 35 | 35 | $file_paths = array_map( |
| 36 | - function ( $path ) use ( $manifest_path ) { |
|
| 37 | - return trailingslashit( $path ) . $manifest_path; |
|
| 36 | + function($path) use ($manifest_path) { |
|
| 37 | + return trailingslashit($path) . $manifest_path; |
|
| 38 | 38 | }, |
| 39 | 39 | $plugin_paths |
| 40 | 40 | ); |
| 41 | 41 | |
| 42 | - foreach ( $file_paths as $path ) { |
|
| 43 | - $this->register_manifest( $path, $path_map ); |
|
| 42 | + foreach ($file_paths as $path) { |
|
| 43 | + $this->register_manifest($path, $path_map); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | return $path_map; |
@@ -52,18 +52,18 @@ discard block |
||
| 52 | 52 | * @param string $manifest_path The absolute path to the manifest that we're loading. |
| 53 | 53 | * @param array $path_map The path map to add the contents of the manifest to. |
| 54 | 54 | */ |
| 55 | - protected function register_manifest( $manifest_path, &$path_map ) { |
|
| 56 | - if ( ! is_readable( $manifest_path ) ) { |
|
| 55 | + protected function register_manifest($manifest_path, &$path_map) { |
|
| 56 | + if (!is_readable($manifest_path)) { |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $manifest = require $manifest_path; |
| 61 | - if ( ! is_array( $manifest ) ) { |
|
| 61 | + if (!is_array($manifest)) { |
|
| 62 | 62 | return; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - foreach ( $manifest as $key => $data ) { |
|
| 66 | - $this->register_record( $key, $data, $path_map ); |
|
| 65 | + foreach ($manifest as $key => $data) { |
|
| 66 | + $this->register_record($key, $data, $path_map); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | * @param array $data The data for the entry we're registering. |
| 75 | 75 | * @param array $path_map The path map to add the contents of the manifest to. |
| 76 | 76 | */ |
| 77 | - protected function register_record( $key, $data, &$path_map ) { |
|
| 78 | - if ( isset( $path_map[ $key ]['version'] ) ) { |
|
| 79 | - $selected_version = $path_map[ $key ]['version']; |
|
| 77 | + protected function register_record($key, $data, &$path_map) { |
|
| 78 | + if (isset($path_map[$key]['version'])) { |
|
| 79 | + $selected_version = $path_map[$key]['version']; |
|
| 80 | 80 | } else { |
| 81 | 81 | $selected_version = null; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ( $this->version_selector->is_version_update_required( $selected_version, $data['version'] ) ) { |
|
| 85 | - $path_map[ $key ] = array( |
|
| 84 | + if ($this->version_selector->is_version_update_required($selected_version, $data['version'])) { |
|
| 85 | + $path_map[$key] = array( |
|
| 86 | 86 | 'version' => $data['version'], |
| 87 | 87 | 'path' => $data['path'], |
| 88 | 88 | ); |
@@ -6,77 +6,77 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Autoloader { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Checks to see whether or not the autoloader should be initialized and then initializes it if so. |
|
| 11 | - * |
|
| 12 | - * @param Container|null $container The container we want to use for autoloader initialization. If none is given |
|
| 13 | - * then a container will be created automatically. |
|
| 14 | - */ |
|
| 15 | - public static function init( $container = null ) { |
|
| 16 | - // The container holds and manages the lifecycle of our dependencies |
|
| 17 | - // to make them easier to work with and increase flexibility. |
|
| 18 | - if ( ! isset( $container ) ) { |
|
| 19 | - require_once __DIR__ . '/class-container.php'; |
|
| 20 | - $container = new Container(); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - // phpcs:disable Generic.Commenting.DocComment.MissingShort |
|
| 24 | - |
|
| 25 | - /** @var Autoloader_Handler $autoloader_handler */ |
|
| 26 | - $autoloader_handler = $container->get( Autoloader_Handler::class ); |
|
| 27 | - |
|
| 28 | - // If the autoloader is already initializing it means that it has included us as the latest. |
|
| 29 | - $was_included_by_autoloader = $autoloader_handler->is_initializing(); |
|
| 30 | - |
|
| 31 | - /** @var Plugin_Locator $plugin_locator */ |
|
| 32 | - $plugin_locator = $container->get( Plugin_Locator::class ); |
|
| 33 | - |
|
| 34 | - /** @var Plugins_Handler $plugins_handler */ |
|
| 35 | - $plugins_handler = $container->get( Plugins_Handler::class ); |
|
| 36 | - |
|
| 37 | - // The current plugin is the one that we are attempting to initialize here. |
|
| 38 | - $current_plugin = $plugin_locator->find_current_plugin(); |
|
| 39 | - |
|
| 40 | - // The active plugins are those that we were able to discover on the site. This list will not |
|
| 41 | - // include mu-plugins, those activated by code, or those who are hidden by filtering. We also |
|
| 42 | - // want to take care to not consider the current plugin unknown if it was included by an |
|
| 43 | - // autoloader. This avoids the case where a plugin will be marked "active" while deactivated |
|
| 44 | - // due to it having the latest autoloader. |
|
| 45 | - $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader ); |
|
| 46 | - |
|
| 47 | - // The cached plugins are all of those that were active or discovered by the autoloader during a previous request. |
|
| 48 | - // Note that it's possible this list will include plugins that have since been deactivated, but after a request |
|
| 49 | - // the cache should be updated and the deactivated plugins will be removed. |
|
| 50 | - $cached_plugins = $plugins_handler->get_cached_plugins(); |
|
| 51 | - |
|
| 52 | - // We combine the active list and cached list to preemptively load classes for plugins that are |
|
| 53 | - // presently unknown but will be loaded during the request. While this may result in us considering packages in |
|
| 54 | - // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient. |
|
| 55 | - $all_plugins = array_merge( $active_plugins, $cached_plugins ); |
|
| 56 | - |
|
| 57 | - // In particular we also include the current plugin to address the case where it is the latest autoloader |
|
| 58 | - // but also unknown (and not cached). We don't want it in the active list because we don't know that it |
|
| 59 | - // is active but we need it in the all plugins list so that it is considered by the autoloader. |
|
| 60 | - $all_plugins[] = $current_plugin; |
|
| 61 | - |
|
| 62 | - // We require uniqueness in the array to avoid processing the same plugin more than once. |
|
| 63 | - $all_plugins = array_values( array_unique( $all_plugins ) ); |
|
| 64 | - |
|
| 65 | - /** @var Latest_Autoloader_Guard $guard */ |
|
| 66 | - $guard = $container->get( Latest_Autoloader_Guard::class ); |
|
| 67 | - if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) { |
|
| 68 | - return; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Initialize the autoloader using the handler now that we're ready. |
|
| 72 | - $autoloader_handler->activate_autoloader( $all_plugins ); |
|
| 73 | - |
|
| 74 | - /** @var Hook_Manager $hook_manager */ |
|
| 75 | - $hook_manager = $container->get( Hook_Manager::class ); |
|
| 76 | - |
|
| 77 | - // Register a shutdown handler to clean up the autoloader. |
|
| 78 | - $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) ); |
|
| 79 | - |
|
| 80 | - // phpcs:enable Generic.Commenting.DocComment.MissingShort |
|
| 81 | - } |
|
| 9 | + /** |
|
| 10 | + * Checks to see whether or not the autoloader should be initialized and then initializes it if so. |
|
| 11 | + * |
|
| 12 | + * @param Container|null $container The container we want to use for autoloader initialization. If none is given |
|
| 13 | + * then a container will be created automatically. |
|
| 14 | + */ |
|
| 15 | + public static function init( $container = null ) { |
|
| 16 | + // The container holds and manages the lifecycle of our dependencies |
|
| 17 | + // to make them easier to work with and increase flexibility. |
|
| 18 | + if ( ! isset( $container ) ) { |
|
| 19 | + require_once __DIR__ . '/class-container.php'; |
|
| 20 | + $container = new Container(); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + // phpcs:disable Generic.Commenting.DocComment.MissingShort |
|
| 24 | + |
|
| 25 | + /** @var Autoloader_Handler $autoloader_handler */ |
|
| 26 | + $autoloader_handler = $container->get( Autoloader_Handler::class ); |
|
| 27 | + |
|
| 28 | + // If the autoloader is already initializing it means that it has included us as the latest. |
|
| 29 | + $was_included_by_autoloader = $autoloader_handler->is_initializing(); |
|
| 30 | + |
|
| 31 | + /** @var Plugin_Locator $plugin_locator */ |
|
| 32 | + $plugin_locator = $container->get( Plugin_Locator::class ); |
|
| 33 | + |
|
| 34 | + /** @var Plugins_Handler $plugins_handler */ |
|
| 35 | + $plugins_handler = $container->get( Plugins_Handler::class ); |
|
| 36 | + |
|
| 37 | + // The current plugin is the one that we are attempting to initialize here. |
|
| 38 | + $current_plugin = $plugin_locator->find_current_plugin(); |
|
| 39 | + |
|
| 40 | + // The active plugins are those that we were able to discover on the site. This list will not |
|
| 41 | + // include mu-plugins, those activated by code, or those who are hidden by filtering. We also |
|
| 42 | + // want to take care to not consider the current plugin unknown if it was included by an |
|
| 43 | + // autoloader. This avoids the case where a plugin will be marked "active" while deactivated |
|
| 44 | + // due to it having the latest autoloader. |
|
| 45 | + $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader ); |
|
| 46 | + |
|
| 47 | + // The cached plugins are all of those that were active or discovered by the autoloader during a previous request. |
|
| 48 | + // Note that it's possible this list will include plugins that have since been deactivated, but after a request |
|
| 49 | + // the cache should be updated and the deactivated plugins will be removed. |
|
| 50 | + $cached_plugins = $plugins_handler->get_cached_plugins(); |
|
| 51 | + |
|
| 52 | + // We combine the active list and cached list to preemptively load classes for plugins that are |
|
| 53 | + // presently unknown but will be loaded during the request. While this may result in us considering packages in |
|
| 54 | + // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient. |
|
| 55 | + $all_plugins = array_merge( $active_plugins, $cached_plugins ); |
|
| 56 | + |
|
| 57 | + // In particular we also include the current plugin to address the case where it is the latest autoloader |
|
| 58 | + // but also unknown (and not cached). We don't want it in the active list because we don't know that it |
|
| 59 | + // is active but we need it in the all plugins list so that it is considered by the autoloader. |
|
| 60 | + $all_plugins[] = $current_plugin; |
|
| 61 | + |
|
| 62 | + // We require uniqueness in the array to avoid processing the same plugin more than once. |
|
| 63 | + $all_plugins = array_values( array_unique( $all_plugins ) ); |
|
| 64 | + |
|
| 65 | + /** @var Latest_Autoloader_Guard $guard */ |
|
| 66 | + $guard = $container->get( Latest_Autoloader_Guard::class ); |
|
| 67 | + if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Initialize the autoloader using the handler now that we're ready. |
|
| 72 | + $autoloader_handler->activate_autoloader( $all_plugins ); |
|
| 73 | + |
|
| 74 | + /** @var Hook_Manager $hook_manager */ |
|
| 75 | + $hook_manager = $container->get( Hook_Manager::class ); |
|
| 76 | + |
|
| 77 | + // Register a shutdown handler to clean up the autoloader. |
|
| 78 | + $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) ); |
|
| 79 | + |
|
| 80 | + // phpcs:enable Generic.Commenting.DocComment.MissingShort |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | * @param Container|null $container The container we want to use for autoloader initialization. If none is given |
| 13 | 13 | * then a container will be created automatically. |
| 14 | 14 | */ |
| 15 | - public static function init( $container = null ) { |
|
| 15 | + public static function init($container = null) { |
|
| 16 | 16 | // The container holds and manages the lifecycle of our dependencies |
| 17 | 17 | // to make them easier to work with and increase flexibility. |
| 18 | - if ( ! isset( $container ) ) { |
|
| 18 | + if (!isset($container)) { |
|
| 19 | 19 | require_once __DIR__ . '/class-container.php'; |
| 20 | 20 | $container = new Container(); |
| 21 | 21 | } |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | // phpcs:disable Generic.Commenting.DocComment.MissingShort |
| 24 | 24 | |
| 25 | 25 | /** @var Autoloader_Handler $autoloader_handler */ |
| 26 | - $autoloader_handler = $container->get( Autoloader_Handler::class ); |
|
| 26 | + $autoloader_handler = $container->get(Autoloader_Handler::class); |
|
| 27 | 27 | |
| 28 | 28 | // If the autoloader is already initializing it means that it has included us as the latest. |
| 29 | 29 | $was_included_by_autoloader = $autoloader_handler->is_initializing(); |
| 30 | 30 | |
| 31 | 31 | /** @var Plugin_Locator $plugin_locator */ |
| 32 | - $plugin_locator = $container->get( Plugin_Locator::class ); |
|
| 32 | + $plugin_locator = $container->get(Plugin_Locator::class); |
|
| 33 | 33 | |
| 34 | 34 | /** @var Plugins_Handler $plugins_handler */ |
| 35 | - $plugins_handler = $container->get( Plugins_Handler::class ); |
|
| 35 | + $plugins_handler = $container->get(Plugins_Handler::class); |
|
| 36 | 36 | |
| 37 | 37 | // The current plugin is the one that we are attempting to initialize here. |
| 38 | 38 | $current_plugin = $plugin_locator->find_current_plugin(); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | // want to take care to not consider the current plugin unknown if it was included by an |
| 43 | 43 | // autoloader. This avoids the case where a plugin will be marked "active" while deactivated |
| 44 | 44 | // due to it having the latest autoloader. |
| 45 | - $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader ); |
|
| 45 | + $active_plugins = $plugins_handler->get_active_plugins(true, !$was_included_by_autoloader); |
|
| 46 | 46 | |
| 47 | 47 | // The cached plugins are all of those that were active or discovered by the autoloader during a previous request. |
| 48 | 48 | // Note that it's possible this list will include plugins that have since been deactivated, but after a request |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | // We combine the active list and cached list to preemptively load classes for plugins that are |
| 53 | 53 | // presently unknown but will be loaded during the request. While this may result in us considering packages in |
| 54 | 54 | // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient. |
| 55 | - $all_plugins = array_merge( $active_plugins, $cached_plugins ); |
|
| 55 | + $all_plugins = array_merge($active_plugins, $cached_plugins); |
|
| 56 | 56 | |
| 57 | 57 | // In particular we also include the current plugin to address the case where it is the latest autoloader |
| 58 | 58 | // but also unknown (and not cached). We don't want it in the active list because we don't know that it |
@@ -60,22 +60,22 @@ discard block |
||
| 60 | 60 | $all_plugins[] = $current_plugin; |
| 61 | 61 | |
| 62 | 62 | // We require uniqueness in the array to avoid processing the same plugin more than once. |
| 63 | - $all_plugins = array_values( array_unique( $all_plugins ) ); |
|
| 63 | + $all_plugins = array_values(array_unique($all_plugins)); |
|
| 64 | 64 | |
| 65 | 65 | /** @var Latest_Autoloader_Guard $guard */ |
| 66 | - $guard = $container->get( Latest_Autoloader_Guard::class ); |
|
| 67 | - if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) { |
|
| 66 | + $guard = $container->get(Latest_Autoloader_Guard::class); |
|
| 67 | + if ($guard->should_stop_init($current_plugin, $all_plugins, $was_included_by_autoloader)) { |
|
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Initialize the autoloader using the handler now that we're ready. |
| 72 | - $autoloader_handler->activate_autoloader( $all_plugins ); |
|
| 72 | + $autoloader_handler->activate_autoloader($all_plugins); |
|
| 73 | 73 | |
| 74 | 74 | /** @var Hook_Manager $hook_manager */ |
| 75 | - $hook_manager = $container->get( Hook_Manager::class ); |
|
| 75 | + $hook_manager = $container->get(Hook_Manager::class); |
|
| 76 | 76 | |
| 77 | 77 | // Register a shutdown handler to clean up the autoloader. |
| 78 | - $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) ); |
|
| 78 | + $hook_manager->add_action('shutdown', new Shutdown_Handler($plugins_handler, $cached_plugins, $was_included_by_autoloader)); |
|
| 79 | 79 | |
| 80 | 80 | // phpcs:enable Generic.Commenting.DocComment.MissingShort |
| 81 | 81 | } |
@@ -23,10 +23,10 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class AutoloadFileWriter { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The file comment to use. |
|
| 28 | - */ |
|
| 29 | - const COMMENT = <<<AUTOLOADER_COMMENT |
|
| 26 | + /** |
|
| 27 | + * The file comment to use. |
|
| 28 | + */ |
|
| 29 | + const COMMENT = <<<AUTOLOADER_COMMENT |
|
| 30 | 30 | /** |
| 31 | 31 | * This file was automatically generated by automattic/jetpack-autoloader. |
| 32 | 32 | * |
@@ -35,71 +35,71 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | AUTOLOADER_COMMENT; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Copies autoloader files and replaces any placeholders in them. |
|
| 40 | - * |
|
| 41 | - * @param IOInterface|null $io An IO for writing to. |
|
| 42 | - * @param string $outDir The directory to place the autoloader files in. |
|
| 43 | - * @param string $suffix The suffix to use in the autoloader's namespace. |
|
| 44 | - */ |
|
| 45 | - public static function copyAutoloaderFiles( $io, $outDir, $suffix ) { |
|
| 46 | - $renameList = array( |
|
| 47 | - 'autoload.php' => '../autoload_packages.php', |
|
| 48 | - ); |
|
| 49 | - $ignoreList = array( |
|
| 50 | - 'AutoloadGenerator.php', |
|
| 51 | - 'AutoloadProcessor.php', |
|
| 52 | - 'CustomAutoloaderPlugin.php', |
|
| 53 | - 'ManifestGenerator.php', |
|
| 54 | - 'AutoloadFileWriter.php', |
|
| 55 | - ); |
|
| 38 | + /** |
|
| 39 | + * Copies autoloader files and replaces any placeholders in them. |
|
| 40 | + * |
|
| 41 | + * @param IOInterface|null $io An IO for writing to. |
|
| 42 | + * @param string $outDir The directory to place the autoloader files in. |
|
| 43 | + * @param string $suffix The suffix to use in the autoloader's namespace. |
|
| 44 | + */ |
|
| 45 | + public static function copyAutoloaderFiles( $io, $outDir, $suffix ) { |
|
| 46 | + $renameList = array( |
|
| 47 | + 'autoload.php' => '../autoload_packages.php', |
|
| 48 | + ); |
|
| 49 | + $ignoreList = array( |
|
| 50 | + 'AutoloadGenerator.php', |
|
| 51 | + 'AutoloadProcessor.php', |
|
| 52 | + 'CustomAutoloaderPlugin.php', |
|
| 53 | + 'ManifestGenerator.php', |
|
| 54 | + 'AutoloadFileWriter.php', |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | - // Copy all of the autoloader files. |
|
| 58 | - $files = scandir( __DIR__ ); |
|
| 59 | - foreach ( $files as $file ) { |
|
| 60 | - // Only PHP files will be copied. |
|
| 61 | - if ( substr( $file, -4 ) !== '.php' ) { |
|
| 62 | - continue; |
|
| 63 | - } |
|
| 57 | + // Copy all of the autoloader files. |
|
| 58 | + $files = scandir( __DIR__ ); |
|
| 59 | + foreach ( $files as $file ) { |
|
| 60 | + // Only PHP files will be copied. |
|
| 61 | + if ( substr( $file, -4 ) !== '.php' ) { |
|
| 62 | + continue; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - if ( in_array( $file, $ignoreList, true ) ) { |
|
| 66 | - continue; |
|
| 67 | - } |
|
| 65 | + if ( in_array( $file, $ignoreList, true ) ) { |
|
| 66 | + continue; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $newFile = isset( $renameList[ $file ] ) ? $renameList[ $file ] : $file; |
|
| 70 | - $content = self::prepareAutoloaderFile( $file, $suffix ); |
|
| 69 | + $newFile = isset( $renameList[ $file ] ) ? $renameList[ $file ] : $file; |
|
| 70 | + $content = self::prepareAutoloaderFile( $file, $suffix ); |
|
| 71 | 71 | |
| 72 | - $written = file_put_contents( $outDir . '/' . $newFile, $content ); |
|
| 73 | - if ( $io ) { |
|
| 74 | - if ( $written ) { |
|
| 75 | - $io->writeError( " <info>Generated: $newFile</info>" ); |
|
| 76 | - } else { |
|
| 77 | - $io->writeError( " <error>Error: $newFile</error>" ); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } |
|
| 72 | + $written = file_put_contents( $outDir . '/' . $newFile, $content ); |
|
| 73 | + if ( $io ) { |
|
| 74 | + if ( $written ) { |
|
| 75 | + $io->writeError( " <info>Generated: $newFile</info>" ); |
|
| 76 | + } else { |
|
| 77 | + $io->writeError( " <error>Error: $newFile</error>" ); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Prepares an autoloader file to be written to the destination. |
|
| 85 | - * |
|
| 86 | - * @param String $filename a file to prepare. |
|
| 87 | - * @param String $suffix Unique suffix used in the namespace. |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - private static function prepareAutoloaderFile( $filename, $suffix ) { |
|
| 92 | - $header = self::COMMENT; |
|
| 93 | - $header .= PHP_EOL; |
|
| 94 | - $header .= 'namespace Automattic\Jetpack\Autoloader\jp' . $suffix . ';'; |
|
| 95 | - $header .= PHP_EOL . PHP_EOL; |
|
| 83 | + /** |
|
| 84 | + * Prepares an autoloader file to be written to the destination. |
|
| 85 | + * |
|
| 86 | + * @param String $filename a file to prepare. |
|
| 87 | + * @param String $suffix Unique suffix used in the namespace. |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + private static function prepareAutoloaderFile( $filename, $suffix ) { |
|
| 92 | + $header = self::COMMENT; |
|
| 93 | + $header .= PHP_EOL; |
|
| 94 | + $header .= 'namespace Automattic\Jetpack\Autoloader\jp' . $suffix . ';'; |
|
| 95 | + $header .= PHP_EOL . PHP_EOL; |
|
| 96 | 96 | |
| 97 | - $sourceLoader = fopen( __DIR__ . '/' . $filename, 'r' ); |
|
| 98 | - $file_contents = stream_get_contents( $sourceLoader ); |
|
| 99 | - return str_replace( |
|
| 100 | - '/* HEADER */', |
|
| 101 | - $header, |
|
| 102 | - $file_contents |
|
| 103 | - ); |
|
| 104 | - } |
|
| 97 | + $sourceLoader = fopen( __DIR__ . '/' . $filename, 'r' ); |
|
| 98 | + $file_contents = stream_get_contents( $sourceLoader ); |
|
| 99 | + return str_replace( |
|
| 100 | + '/* HEADER */', |
|
| 101 | + $header, |
|
| 102 | + $file_contents |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string $outDir The directory to place the autoloader files in. |
| 43 | 43 | * @param string $suffix The suffix to use in the autoloader's namespace. |
| 44 | 44 | */ |
| 45 | - public static function copyAutoloaderFiles( $io, $outDir, $suffix ) { |
|
| 45 | + public static function copyAutoloaderFiles($io, $outDir, $suffix) { |
|
| 46 | 46 | $renameList = array( |
| 47 | 47 | 'autoload.php' => '../autoload_packages.php', |
| 48 | 48 | ); |
@@ -55,26 +55,26 @@ discard block |
||
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | 57 | // Copy all of the autoloader files. |
| 58 | - $files = scandir( __DIR__ ); |
|
| 59 | - foreach ( $files as $file ) { |
|
| 58 | + $files = scandir(__DIR__); |
|
| 59 | + foreach ($files as $file) { |
|
| 60 | 60 | // Only PHP files will be copied. |
| 61 | - if ( substr( $file, -4 ) !== '.php' ) { |
|
| 61 | + if (substr($file, -4) !== '.php') { |
|
| 62 | 62 | continue; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ( in_array( $file, $ignoreList, true ) ) { |
|
| 65 | + if (in_array($file, $ignoreList, true)) { |
|
| 66 | 66 | continue; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $newFile = isset( $renameList[ $file ] ) ? $renameList[ $file ] : $file; |
|
| 70 | - $content = self::prepareAutoloaderFile( $file, $suffix ); |
|
| 69 | + $newFile = isset($renameList[$file]) ? $renameList[$file] : $file; |
|
| 70 | + $content = self::prepareAutoloaderFile($file, $suffix); |
|
| 71 | 71 | |
| 72 | - $written = file_put_contents( $outDir . '/' . $newFile, $content ); |
|
| 73 | - if ( $io ) { |
|
| 74 | - if ( $written ) { |
|
| 75 | - $io->writeError( " <info>Generated: $newFile</info>" ); |
|
| 72 | + $written = file_put_contents($outDir . '/' . $newFile, $content); |
|
| 73 | + if ($io) { |
|
| 74 | + if ($written) { |
|
| 75 | + $io->writeError(" <info>Generated: $newFile</info>"); |
|
| 76 | 76 | } else { |
| 77 | - $io->writeError( " <error>Error: $newFile</error>" ); |
|
| 77 | + $io->writeError(" <error>Error: $newFile</error>"); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - private static function prepareAutoloaderFile( $filename, $suffix ) { |
|
| 91 | + private static function prepareAutoloaderFile($filename, $suffix) { |
|
| 92 | 92 | $header = self::COMMENT; |
| 93 | 93 | $header .= PHP_EOL; |
| 94 | 94 | $header .= 'namespace Automattic\Jetpack\Autoloader\jp' . $suffix . ';'; |
| 95 | 95 | $header .= PHP_EOL . PHP_EOL; |
| 96 | 96 | |
| 97 | - $sourceLoader = fopen( __DIR__ . '/' . $filename, 'r' ); |
|
| 98 | - $file_contents = stream_get_contents( $sourceLoader ); |
|
| 97 | + $sourceLoader = fopen(__DIR__ . '/' . $filename, 'r'); |
|
| 98 | + $file_contents = stream_get_contents($sourceLoader); |
|
| 99 | 99 | return str_replace( |
| 100 | 100 | '/* HEADER */', |
| 101 | 101 | $header, |
@@ -5,152 +5,152 @@ |
||
| 5 | 5 | * This class handles locating and caching all of the active plugins. |
| 6 | 6 | */ |
| 7 | 7 | class Plugins_Handler { |
| 8 | - /** |
|
| 9 | - * The transient key for plugin paths. |
|
| 10 | - */ |
|
| 11 | - const TRANSIENT_KEY = 'jetpack_autoloader_plugin_paths'; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * The locator for finding plugins in different locations. |
|
| 15 | - * |
|
| 16 | - * @var Plugin_Locator |
|
| 17 | - */ |
|
| 18 | - private $plugin_locator; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The processor for transforming cached paths. |
|
| 22 | - * |
|
| 23 | - * @var Path_Processor |
|
| 24 | - */ |
|
| 25 | - private $path_processor; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * The constructor. |
|
| 29 | - * |
|
| 30 | - * @param Plugin_Locator $plugin_locator The locator for finding active plugins. |
|
| 31 | - * @param Path_Processor $path_processor The processor for transforming cached paths. |
|
| 32 | - */ |
|
| 33 | - public function __construct( $plugin_locator, $path_processor ) { |
|
| 34 | - $this->plugin_locator = $plugin_locator; |
|
| 35 | - $this->path_processor = $path_processor; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Gets all of the active plugins we can find. |
|
| 40 | - * |
|
| 41 | - * @param bool $include_deactivating When true, plugins deactivating this request will be considered active. |
|
| 42 | - * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown. |
|
| 43 | - * |
|
| 44 | - * @return string[] |
|
| 45 | - */ |
|
| 46 | - public function get_active_plugins( $include_deactivating, $record_unknown ) { |
|
| 47 | - global $jetpack_autoloader_activating_plugins_paths; |
|
| 48 | - |
|
| 49 | - // We're going to build a unique list of plugins from a few different sources |
|
| 50 | - // to find all of our "active" plugins. While we need to return an integer |
|
| 51 | - // array, we're going to use an associative array internally to reduce |
|
| 52 | - // the amount of time that we're going to spend checking uniqueness |
|
| 53 | - // and merging different arrays together to form the output. |
|
| 54 | - $active_plugins = array(); |
|
| 55 | - |
|
| 56 | - // Make sure that plugins which have activated this request are considered as "active" even though |
|
| 57 | - // they probably won't be present in any option. |
|
| 58 | - if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 59 | - foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
|
| 60 | - $active_plugins[ $path ] = $path; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // This option contains all of the plugins that have been activated. |
|
| 65 | - $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
|
| 66 | - foreach ( $plugins as $path ) { |
|
| 67 | - $active_plugins[ $path ] = $path; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // This option contains all of the multisite plugins that have been activated. |
|
| 71 | - if ( is_multisite() ) { |
|
| 72 | - $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
|
| 73 | - foreach ( $plugins as $path ) { |
|
| 74 | - $active_plugins[ $path ] = $path; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // These actions contain plugins that are being activated/deactivated during this request. |
|
| 79 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); |
|
| 80 | - foreach ( $plugins as $path ) { |
|
| 81 | - $active_plugins[ $path ] = $path; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // When the current plugin isn't considered "active" there's a problem. |
|
| 85 | - // Since we're here, the plugin is active and currently being loaded. |
|
| 86 | - // We can support this case (mu-plugins and non-standard activation) |
|
| 87 | - // by adding the current plugin to the active list and marking it |
|
| 88 | - // as an unknown (activating) plugin. This also has the benefit |
|
| 89 | - // of causing a reset because the active plugins list has |
|
| 90 | - // been changed since it was saved in the global. |
|
| 91 | - $current_plugin = $this->plugin_locator->find_current_plugin(); |
|
| 92 | - if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { |
|
| 93 | - $active_plugins[ $current_plugin ] = $current_plugin; |
|
| 94 | - $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // When deactivating plugins aren't desired we should entirely remove them from the active list. |
|
| 98 | - if ( ! $include_deactivating ) { |
|
| 99 | - // These actions contain plugins that are being deactivated during this request. |
|
| 100 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
|
| 101 | - foreach ( $plugins as $path ) { |
|
| 102 | - unset( $active_plugins[ $path ] ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
|
| 107 | - return array_values( $active_plugins ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Gets all of the cached plugins if there are any. |
|
| 112 | - * |
|
| 113 | - * @return string[] |
|
| 114 | - */ |
|
| 115 | - public function get_cached_plugins() { |
|
| 116 | - $cached = get_transient( self::TRANSIENT_KEY ); |
|
| 117 | - if ( ! is_array( $cached ) || empty( $cached ) ) { |
|
| 118 | - return array(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // We need to expand the tokens to an absolute path for this webserver. |
|
| 122 | - return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Saves the plugin list to the cache. |
|
| 127 | - * |
|
| 128 | - * @param array $plugins The plugin list to save to the cache. |
|
| 129 | - */ |
|
| 130 | - public function cache_plugins( $plugins ) { |
|
| 131 | - // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. |
|
| 132 | - $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); |
|
| 133 | - |
|
| 134 | - set_transient( self::TRANSIENT_KEY, $plugins ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Checks to see whether or not the plugin list given has changed when compared to the |
|
| 139 | - * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal |
|
| 140 | - * with cases where the active list may change due to filtering.. |
|
| 141 | - * |
|
| 142 | - * @param string[] $plugins The plugins list to check against the global cache. |
|
| 143 | - * |
|
| 144 | - * @return bool True if the plugins have changed, otherwise false. |
|
| 145 | - */ |
|
| 146 | - public function have_plugins_changed( $plugins ) { |
|
| 147 | - global $jetpack_autoloader_cached_plugin_paths; |
|
| 148 | - |
|
| 149 | - if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { |
|
| 150 | - $jetpack_autoloader_cached_plugin_paths = $plugins; |
|
| 151 | - return true; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 8 | + /** |
|
| 9 | + * The transient key for plugin paths. |
|
| 10 | + */ |
|
| 11 | + const TRANSIENT_KEY = 'jetpack_autoloader_plugin_paths'; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * The locator for finding plugins in different locations. |
|
| 15 | + * |
|
| 16 | + * @var Plugin_Locator |
|
| 17 | + */ |
|
| 18 | + private $plugin_locator; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The processor for transforming cached paths. |
|
| 22 | + * |
|
| 23 | + * @var Path_Processor |
|
| 24 | + */ |
|
| 25 | + private $path_processor; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * The constructor. |
|
| 29 | + * |
|
| 30 | + * @param Plugin_Locator $plugin_locator The locator for finding active plugins. |
|
| 31 | + * @param Path_Processor $path_processor The processor for transforming cached paths. |
|
| 32 | + */ |
|
| 33 | + public function __construct( $plugin_locator, $path_processor ) { |
|
| 34 | + $this->plugin_locator = $plugin_locator; |
|
| 35 | + $this->path_processor = $path_processor; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Gets all of the active plugins we can find. |
|
| 40 | + * |
|
| 41 | + * @param bool $include_deactivating When true, plugins deactivating this request will be considered active. |
|
| 42 | + * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown. |
|
| 43 | + * |
|
| 44 | + * @return string[] |
|
| 45 | + */ |
|
| 46 | + public function get_active_plugins( $include_deactivating, $record_unknown ) { |
|
| 47 | + global $jetpack_autoloader_activating_plugins_paths; |
|
| 48 | + |
|
| 49 | + // We're going to build a unique list of plugins from a few different sources |
|
| 50 | + // to find all of our "active" plugins. While we need to return an integer |
|
| 51 | + // array, we're going to use an associative array internally to reduce |
|
| 52 | + // the amount of time that we're going to spend checking uniqueness |
|
| 53 | + // and merging different arrays together to form the output. |
|
| 54 | + $active_plugins = array(); |
|
| 55 | + |
|
| 56 | + // Make sure that plugins which have activated this request are considered as "active" even though |
|
| 57 | + // they probably won't be present in any option. |
|
| 58 | + if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 59 | + foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
|
| 60 | + $active_plugins[ $path ] = $path; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // This option contains all of the plugins that have been activated. |
|
| 65 | + $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
|
| 66 | + foreach ( $plugins as $path ) { |
|
| 67 | + $active_plugins[ $path ] = $path; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // This option contains all of the multisite plugins that have been activated. |
|
| 71 | + if ( is_multisite() ) { |
|
| 72 | + $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
|
| 73 | + foreach ( $plugins as $path ) { |
|
| 74 | + $active_plugins[ $path ] = $path; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // These actions contain plugins that are being activated/deactivated during this request. |
|
| 79 | + $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); |
|
| 80 | + foreach ( $plugins as $path ) { |
|
| 81 | + $active_plugins[ $path ] = $path; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // When the current plugin isn't considered "active" there's a problem. |
|
| 85 | + // Since we're here, the plugin is active and currently being loaded. |
|
| 86 | + // We can support this case (mu-plugins and non-standard activation) |
|
| 87 | + // by adding the current plugin to the active list and marking it |
|
| 88 | + // as an unknown (activating) plugin. This also has the benefit |
|
| 89 | + // of causing a reset because the active plugins list has |
|
| 90 | + // been changed since it was saved in the global. |
|
| 91 | + $current_plugin = $this->plugin_locator->find_current_plugin(); |
|
| 92 | + if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { |
|
| 93 | + $active_plugins[ $current_plugin ] = $current_plugin; |
|
| 94 | + $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // When deactivating plugins aren't desired we should entirely remove them from the active list. |
|
| 98 | + if ( ! $include_deactivating ) { |
|
| 99 | + // These actions contain plugins that are being deactivated during this request. |
|
| 100 | + $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
|
| 101 | + foreach ( $plugins as $path ) { |
|
| 102 | + unset( $active_plugins[ $path ] ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
|
| 107 | + return array_values( $active_plugins ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Gets all of the cached plugins if there are any. |
|
| 112 | + * |
|
| 113 | + * @return string[] |
|
| 114 | + */ |
|
| 115 | + public function get_cached_plugins() { |
|
| 116 | + $cached = get_transient( self::TRANSIENT_KEY ); |
|
| 117 | + if ( ! is_array( $cached ) || empty( $cached ) ) { |
|
| 118 | + return array(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // We need to expand the tokens to an absolute path for this webserver. |
|
| 122 | + return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Saves the plugin list to the cache. |
|
| 127 | + * |
|
| 128 | + * @param array $plugins The plugin list to save to the cache. |
|
| 129 | + */ |
|
| 130 | + public function cache_plugins( $plugins ) { |
|
| 131 | + // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. |
|
| 132 | + $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); |
|
| 133 | + |
|
| 134 | + set_transient( self::TRANSIENT_KEY, $plugins ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Checks to see whether or not the plugin list given has changed when compared to the |
|
| 139 | + * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal |
|
| 140 | + * with cases where the active list may change due to filtering.. |
|
| 141 | + * |
|
| 142 | + * @param string[] $plugins The plugins list to check against the global cache. |
|
| 143 | + * |
|
| 144 | + * @return bool True if the plugins have changed, otherwise false. |
|
| 145 | + */ |
|
| 146 | + public function have_plugins_changed( $plugins ) { |
|
| 147 | + global $jetpack_autoloader_cached_plugin_paths; |
|
| 148 | + |
|
| 149 | + if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { |
|
| 150 | + $jetpack_autoloader_cached_plugin_paths = $plugins; |
|
| 151 | + return true; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param Plugin_Locator $plugin_locator The locator for finding active plugins. |
| 31 | 31 | * @param Path_Processor $path_processor The processor for transforming cached paths. |
| 32 | 32 | */ |
| 33 | - public function __construct( $plugin_locator, $path_processor ) { |
|
| 33 | + public function __construct($plugin_locator, $path_processor) { |
|
| 34 | 34 | $this->plugin_locator = $plugin_locator; |
| 35 | 35 | $this->path_processor = $path_processor; |
| 36 | 36 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string[] |
| 45 | 45 | */ |
| 46 | - public function get_active_plugins( $include_deactivating, $record_unknown ) { |
|
| 46 | + public function get_active_plugins($include_deactivating, $record_unknown) { |
|
| 47 | 47 | global $jetpack_autoloader_activating_plugins_paths; |
| 48 | 48 | |
| 49 | 49 | // We're going to build a unique list of plugins from a few different sources |
@@ -55,30 +55,30 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // Make sure that plugins which have activated this request are considered as "active" even though |
| 57 | 57 | // they probably won't be present in any option. |
| 58 | - if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 59 | - foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
|
| 60 | - $active_plugins[ $path ] = $path; |
|
| 58 | + if (is_array($jetpack_autoloader_activating_plugins_paths)) { |
|
| 59 | + foreach ($jetpack_autoloader_activating_plugins_paths as $path) { |
|
| 60 | + $active_plugins[$path] = $path; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // This option contains all of the plugins that have been activated. |
| 65 | - $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
|
| 66 | - foreach ( $plugins as $path ) { |
|
| 67 | - $active_plugins[ $path ] = $path; |
|
| 65 | + $plugins = $this->plugin_locator->find_using_option('active_plugins'); |
|
| 66 | + foreach ($plugins as $path) { |
|
| 67 | + $active_plugins[$path] = $path; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // This option contains all of the multisite plugins that have been activated. |
| 71 | - if ( is_multisite() ) { |
|
| 72 | - $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
|
| 73 | - foreach ( $plugins as $path ) { |
|
| 74 | - $active_plugins[ $path ] = $path; |
|
| 71 | + if (is_multisite()) { |
|
| 72 | + $plugins = $this->plugin_locator->find_using_option('active_sitewide_plugins', true); |
|
| 73 | + foreach ($plugins as $path) { |
|
| 74 | + $active_plugins[$path] = $path; |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // These actions contain plugins that are being activated/deactivated during this request. |
| 79 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); |
|
| 80 | - foreach ( $plugins as $path ) { |
|
| 81 | - $active_plugins[ $path ] = $path; |
|
| 79 | + $plugins = $this->plugin_locator->find_using_request_action(array('activate', 'activate-selected', 'deactivate', 'deactivate-selected')); |
|
| 80 | + foreach ($plugins as $path) { |
|
| 81 | + $active_plugins[$path] = $path; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // When the current plugin isn't considered "active" there's a problem. |
@@ -89,22 +89,22 @@ discard block |
||
| 89 | 89 | // of causing a reset because the active plugins list has |
| 90 | 90 | // been changed since it was saved in the global. |
| 91 | 91 | $current_plugin = $this->plugin_locator->find_current_plugin(); |
| 92 | - if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { |
|
| 93 | - $active_plugins[ $current_plugin ] = $current_plugin; |
|
| 92 | + if ($record_unknown && !in_array($current_plugin, $active_plugins, true)) { |
|
| 93 | + $active_plugins[$current_plugin] = $current_plugin; |
|
| 94 | 94 | $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // When deactivating plugins aren't desired we should entirely remove them from the active list. |
| 98 | - if ( ! $include_deactivating ) { |
|
| 98 | + if (!$include_deactivating) { |
|
| 99 | 99 | // These actions contain plugins that are being deactivated during this request. |
| 100 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
|
| 101 | - foreach ( $plugins as $path ) { |
|
| 102 | - unset( $active_plugins[ $path ] ); |
|
| 100 | + $plugins = $this->plugin_locator->find_using_request_action(array('deactivate', 'deactivate-selected')); |
|
| 101 | + foreach ($plugins as $path) { |
|
| 102 | + unset($active_plugins[$path]); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
| 107 | - return array_values( $active_plugins ); |
|
| 107 | + return array_values($active_plugins); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * @return string[] |
| 114 | 114 | */ |
| 115 | 115 | public function get_cached_plugins() { |
| 116 | - $cached = get_transient( self::TRANSIENT_KEY ); |
|
| 117 | - if ( ! is_array( $cached ) || empty( $cached ) ) { |
|
| 116 | + $cached = get_transient(self::TRANSIENT_KEY); |
|
| 117 | + if (!is_array($cached) || empty($cached)) { |
|
| 118 | 118 | return array(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // We need to expand the tokens to an absolute path for this webserver. |
| 122 | - return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); |
|
| 122 | + return array_map(array($this->path_processor, 'untokenize_path_constants'), $cached); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @param array $plugins The plugin list to save to the cache. |
| 129 | 129 | */ |
| 130 | - public function cache_plugins( $plugins ) { |
|
| 130 | + public function cache_plugins($plugins) { |
|
| 131 | 131 | // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. |
| 132 | - $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); |
|
| 132 | + $plugins = array_map(array($this->path_processor, 'tokenize_path_constants'), $plugins); |
|
| 133 | 133 | |
| 134 | - set_transient( self::TRANSIENT_KEY, $plugins ); |
|
| 134 | + set_transient(self::TRANSIENT_KEY, $plugins); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return bool True if the plugins have changed, otherwise false. |
| 145 | 145 | */ |
| 146 | - public function have_plugins_changed( $plugins ) { |
|
| 146 | + public function have_plugins_changed($plugins) { |
|
| 147 | 147 | global $jetpack_autoloader_cached_plugin_paths; |
| 148 | 148 | |
| 149 | - if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { |
|
| 149 | + if ($jetpack_autoloader_cached_plugin_paths !== $plugins) { |
|
| 150 | 150 | $jetpack_autoloader_cached_plugin_paths = $plugins; |
| 151 | 151 | return true; |
| 152 | 152 | } |
@@ -19,162 +19,162 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class AutoloadProcessor { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * A callable for scanning a directory for all of its classes. |
|
| 24 | - * |
|
| 25 | - * @var callable |
|
| 26 | - */ |
|
| 27 | - private $classmapScanner; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * A callable for transforming a path into one to be used in code. |
|
| 31 | - * |
|
| 32 | - * @var callable |
|
| 33 | - */ |
|
| 34 | - private $pathCodeTransformer; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The constructor. |
|
| 38 | - * |
|
| 39 | - * @param callable $classmapScanner A callable for scanning a directory for all of its classes. |
|
| 40 | - * @param callable $pathCodeTransformer A callable for transforming a path into one to be used in code. |
|
| 41 | - */ |
|
| 42 | - public function __construct( $classmapScanner, $pathCodeTransformer ) { |
|
| 43 | - $this->classmapScanner = $classmapScanner; |
|
| 44 | - $this->pathCodeTransformer = $pathCodeTransformer; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Processes the classmap autoloads into a relative path format including the version for each file. |
|
| 49 | - * |
|
| 50 | - * @param array $autoloads The autoloads we are processing. |
|
| 51 | - * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. |
|
| 52 | - * |
|
| 53 | - * @return array $processed |
|
| 54 | - */ |
|
| 55 | - public function processClassmap( $autoloads, $scanPsrPackages ) { |
|
| 56 | - // We can't scan PSR packages if we don't actually have any. |
|
| 57 | - if ( empty( $autoloads['psr-4'] ) ) { |
|
| 58 | - $scanPsrPackages = false; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if ( empty( $autoloads['classmap'] ) && ! $scanPsrPackages ) { |
|
| 62 | - return null; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $excludedClasses = null; |
|
| 66 | - if ( ! empty( $autoloads['exclude-from-classmap'] ) ) { |
|
| 67 | - $excludedClasses = '{(' . implode( '|', $autoloads['exclude-from-classmap'] ) . ')}'; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $processed = array(); |
|
| 71 | - |
|
| 72 | - if ( $scanPsrPackages ) { |
|
| 73 | - foreach ( $autoloads['psr-4'] as $namespace => $sources ) { |
|
| 74 | - $namespace = empty( $namespace ) ? null : $namespace; |
|
| 75 | - |
|
| 76 | - foreach ( $sources as $source ) { |
|
| 77 | - $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); |
|
| 78 | - |
|
| 79 | - foreach ( $classmap as $class => $path ) { |
|
| 80 | - $processed[ $class ] = array( |
|
| 81 | - 'version' => $source['version'], |
|
| 82 | - 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /* |
|
| 22 | + /** |
|
| 23 | + * A callable for scanning a directory for all of its classes. |
|
| 24 | + * |
|
| 25 | + * @var callable |
|
| 26 | + */ |
|
| 27 | + private $classmapScanner; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * A callable for transforming a path into one to be used in code. |
|
| 31 | + * |
|
| 32 | + * @var callable |
|
| 33 | + */ |
|
| 34 | + private $pathCodeTransformer; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The constructor. |
|
| 38 | + * |
|
| 39 | + * @param callable $classmapScanner A callable for scanning a directory for all of its classes. |
|
| 40 | + * @param callable $pathCodeTransformer A callable for transforming a path into one to be used in code. |
|
| 41 | + */ |
|
| 42 | + public function __construct( $classmapScanner, $pathCodeTransformer ) { |
|
| 43 | + $this->classmapScanner = $classmapScanner; |
|
| 44 | + $this->pathCodeTransformer = $pathCodeTransformer; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Processes the classmap autoloads into a relative path format including the version for each file. |
|
| 49 | + * |
|
| 50 | + * @param array $autoloads The autoloads we are processing. |
|
| 51 | + * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. |
|
| 52 | + * |
|
| 53 | + * @return array $processed |
|
| 54 | + */ |
|
| 55 | + public function processClassmap( $autoloads, $scanPsrPackages ) { |
|
| 56 | + // We can't scan PSR packages if we don't actually have any. |
|
| 57 | + if ( empty( $autoloads['psr-4'] ) ) { |
|
| 58 | + $scanPsrPackages = false; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if ( empty( $autoloads['classmap'] ) && ! $scanPsrPackages ) { |
|
| 62 | + return null; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $excludedClasses = null; |
|
| 66 | + if ( ! empty( $autoloads['exclude-from-classmap'] ) ) { |
|
| 67 | + $excludedClasses = '{(' . implode( '|', $autoloads['exclude-from-classmap'] ) . ')}'; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $processed = array(); |
|
| 71 | + |
|
| 72 | + if ( $scanPsrPackages ) { |
|
| 73 | + foreach ( $autoloads['psr-4'] as $namespace => $sources ) { |
|
| 74 | + $namespace = empty( $namespace ) ? null : $namespace; |
|
| 75 | + |
|
| 76 | + foreach ( $sources as $source ) { |
|
| 77 | + $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); |
|
| 78 | + |
|
| 79 | + foreach ( $classmap as $class => $path ) { |
|
| 80 | + $processed[ $class ] = array( |
|
| 81 | + 'version' => $source['version'], |
|
| 82 | + 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /* |
|
| 90 | 90 | * PSR-0 namespaces are converted to classmaps for both optimized and unoptimized autoloaders because any new |
| 91 | 91 | * development should use classmap or PSR-4 autoloading. |
| 92 | 92 | */ |
| 93 | - if ( ! empty( $autoloads['psr-0'] ) ) { |
|
| 94 | - foreach ( $autoloads['psr-0'] as $namespace => $sources ) { |
|
| 95 | - $namespace = empty( $namespace ) ? null : $namespace; |
|
| 96 | - |
|
| 97 | - foreach ( $sources as $source ) { |
|
| 98 | - $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); |
|
| 99 | - foreach ( $classmap as $class => $path ) { |
|
| 100 | - $processed[ $class ] = array( |
|
| 101 | - 'version' => $source['version'], |
|
| 102 | - 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ( ! empty( $autoloads['classmap'] ) ) { |
|
| 110 | - foreach ( $autoloads['classmap'] as $package ) { |
|
| 111 | - $classmap = call_user_func( $this->classmapScanner, $package['path'], $excludedClasses, null ); |
|
| 112 | - |
|
| 113 | - foreach ( $classmap as $class => $path ) { |
|
| 114 | - $processed[ $class ] = array( |
|
| 115 | - 'version' => $package['version'], |
|
| 116 | - 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $processed; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Processes the PSR-4 autoloads into a relative path format including the version for each file. |
|
| 127 | - * |
|
| 128 | - * @param array $autoloads The autoloads we are processing. |
|
| 129 | - * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. |
|
| 130 | - * |
|
| 131 | - * @return array $processed |
|
| 132 | - */ |
|
| 133 | - public function processPsr4Packages( $autoloads, $scanPsrPackages ) { |
|
| 134 | - if ( $scanPsrPackages || empty( $autoloads['psr-4'] ) ) { |
|
| 135 | - return null; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $processed = array(); |
|
| 139 | - |
|
| 140 | - foreach ( $autoloads['psr-4'] as $namespace => $packages ) { |
|
| 141 | - $namespace = empty( $namespace ) ? null : $namespace; |
|
| 142 | - $paths = array(); |
|
| 143 | - |
|
| 144 | - foreach ( $packages as $package ) { |
|
| 145 | - $paths[] = call_user_func( $this->pathCodeTransformer, $package['path'] ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $processed[ $namespace ] = array( |
|
| 149 | - 'version' => $package['version'], |
|
| 150 | - 'path' => $paths, |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $processed; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Processes the file autoloads into a relative format including the version for each file. |
|
| 159 | - * |
|
| 160 | - * @param array $autoloads The autoloads we are processing. |
|
| 161 | - * |
|
| 162 | - * @return array|null $processed |
|
| 163 | - */ |
|
| 164 | - public function processFiles( $autoloads ) { |
|
| 165 | - if ( empty( $autoloads['files'] ) ) { |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $processed = array(); |
|
| 170 | - |
|
| 171 | - foreach ( $autoloads['files'] as $file_id => $package ) { |
|
| 172 | - $processed[ $file_id ] = array( |
|
| 173 | - 'version' => $package['version'], |
|
| 174 | - 'path' => call_user_func( $this->pathCodeTransformer, $package['path'] ), |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $processed; |
|
| 179 | - } |
|
| 93 | + if ( ! empty( $autoloads['psr-0'] ) ) { |
|
| 94 | + foreach ( $autoloads['psr-0'] as $namespace => $sources ) { |
|
| 95 | + $namespace = empty( $namespace ) ? null : $namespace; |
|
| 96 | + |
|
| 97 | + foreach ( $sources as $source ) { |
|
| 98 | + $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); |
|
| 99 | + foreach ( $classmap as $class => $path ) { |
|
| 100 | + $processed[ $class ] = array( |
|
| 101 | + 'version' => $source['version'], |
|
| 102 | + 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ( ! empty( $autoloads['classmap'] ) ) { |
|
| 110 | + foreach ( $autoloads['classmap'] as $package ) { |
|
| 111 | + $classmap = call_user_func( $this->classmapScanner, $package['path'], $excludedClasses, null ); |
|
| 112 | + |
|
| 113 | + foreach ( $classmap as $class => $path ) { |
|
| 114 | + $processed[ $class ] = array( |
|
| 115 | + 'version' => $package['version'], |
|
| 116 | + 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $processed; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Processes the PSR-4 autoloads into a relative path format including the version for each file. |
|
| 127 | + * |
|
| 128 | + * @param array $autoloads The autoloads we are processing. |
|
| 129 | + * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. |
|
| 130 | + * |
|
| 131 | + * @return array $processed |
|
| 132 | + */ |
|
| 133 | + public function processPsr4Packages( $autoloads, $scanPsrPackages ) { |
|
| 134 | + if ( $scanPsrPackages || empty( $autoloads['psr-4'] ) ) { |
|
| 135 | + return null; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $processed = array(); |
|
| 139 | + |
|
| 140 | + foreach ( $autoloads['psr-4'] as $namespace => $packages ) { |
|
| 141 | + $namespace = empty( $namespace ) ? null : $namespace; |
|
| 142 | + $paths = array(); |
|
| 143 | + |
|
| 144 | + foreach ( $packages as $package ) { |
|
| 145 | + $paths[] = call_user_func( $this->pathCodeTransformer, $package['path'] ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $processed[ $namespace ] = array( |
|
| 149 | + 'version' => $package['version'], |
|
| 150 | + 'path' => $paths, |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $processed; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Processes the file autoloads into a relative format including the version for each file. |
|
| 159 | + * |
|
| 160 | + * @param array $autoloads The autoloads we are processing. |
|
| 161 | + * |
|
| 162 | + * @return array|null $processed |
|
| 163 | + */ |
|
| 164 | + public function processFiles( $autoloads ) { |
|
| 165 | + if ( empty( $autoloads['files'] ) ) { |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $processed = array(); |
|
| 170 | + |
|
| 171 | + foreach ( $autoloads['files'] as $file_id => $package ) { |
|
| 172 | + $processed[ $file_id ] = array( |
|
| 173 | + 'version' => $package['version'], |
|
| 174 | + 'path' => call_user_func( $this->pathCodeTransformer, $package['path'] ), |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $processed; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param callable $classmapScanner A callable for scanning a directory for all of its classes. |
| 40 | 40 | * @param callable $pathCodeTransformer A callable for transforming a path into one to be used in code. |
| 41 | 41 | */ |
| 42 | - public function __construct( $classmapScanner, $pathCodeTransformer ) { |
|
| 42 | + public function __construct($classmapScanner, $pathCodeTransformer) { |
|
| 43 | 43 | $this->classmapScanner = $classmapScanner; |
| 44 | 44 | $this->pathCodeTransformer = $pathCodeTransformer; |
| 45 | 45 | } |
@@ -52,34 +52,34 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return array $processed |
| 54 | 54 | */ |
| 55 | - public function processClassmap( $autoloads, $scanPsrPackages ) { |
|
| 55 | + public function processClassmap($autoloads, $scanPsrPackages) { |
|
| 56 | 56 | // We can't scan PSR packages if we don't actually have any. |
| 57 | - if ( empty( $autoloads['psr-4'] ) ) { |
|
| 57 | + if (empty($autoloads['psr-4'])) { |
|
| 58 | 58 | $scanPsrPackages = false; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if ( empty( $autoloads['classmap'] ) && ! $scanPsrPackages ) { |
|
| 61 | + if (empty($autoloads['classmap']) && !$scanPsrPackages) { |
|
| 62 | 62 | return null; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $excludedClasses = null; |
| 66 | - if ( ! empty( $autoloads['exclude-from-classmap'] ) ) { |
|
| 67 | - $excludedClasses = '{(' . implode( '|', $autoloads['exclude-from-classmap'] ) . ')}'; |
|
| 66 | + if (!empty($autoloads['exclude-from-classmap'])) { |
|
| 67 | + $excludedClasses = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}'; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $processed = array(); |
| 71 | 71 | |
| 72 | - if ( $scanPsrPackages ) { |
|
| 73 | - foreach ( $autoloads['psr-4'] as $namespace => $sources ) { |
|
| 74 | - $namespace = empty( $namespace ) ? null : $namespace; |
|
| 72 | + if ($scanPsrPackages) { |
|
| 73 | + foreach ($autoloads['psr-4'] as $namespace => $sources) { |
|
| 74 | + $namespace = empty($namespace) ? null : $namespace; |
|
| 75 | 75 | |
| 76 | - foreach ( $sources as $source ) { |
|
| 77 | - $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); |
|
| 76 | + foreach ($sources as $source) { |
|
| 77 | + $classmap = call_user_func($this->classmapScanner, $source['path'], $excludedClasses, $namespace); |
|
| 78 | 78 | |
| 79 | - foreach ( $classmap as $class => $path ) { |
|
| 80 | - $processed[ $class ] = array( |
|
| 79 | + foreach ($classmap as $class => $path) { |
|
| 80 | + $processed[$class] = array( |
|
| 81 | 81 | 'version' => $source['version'], |
| 82 | - 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 82 | + 'path' => call_user_func($this->pathCodeTransformer, $path), |
|
| 83 | 83 | ); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -90,30 +90,30 @@ discard block |
||
| 90 | 90 | * PSR-0 namespaces are converted to classmaps for both optimized and unoptimized autoloaders because any new |
| 91 | 91 | * development should use classmap or PSR-4 autoloading. |
| 92 | 92 | */ |
| 93 | - if ( ! empty( $autoloads['psr-0'] ) ) { |
|
| 94 | - foreach ( $autoloads['psr-0'] as $namespace => $sources ) { |
|
| 95 | - $namespace = empty( $namespace ) ? null : $namespace; |
|
| 96 | - |
|
| 97 | - foreach ( $sources as $source ) { |
|
| 98 | - $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); |
|
| 99 | - foreach ( $classmap as $class => $path ) { |
|
| 100 | - $processed[ $class ] = array( |
|
| 93 | + if (!empty($autoloads['psr-0'])) { |
|
| 94 | + foreach ($autoloads['psr-0'] as $namespace => $sources) { |
|
| 95 | + $namespace = empty($namespace) ? null : $namespace; |
|
| 96 | + |
|
| 97 | + foreach ($sources as $source) { |
|
| 98 | + $classmap = call_user_func($this->classmapScanner, $source['path'], $excludedClasses, $namespace); |
|
| 99 | + foreach ($classmap as $class => $path) { |
|
| 100 | + $processed[$class] = array( |
|
| 101 | 101 | 'version' => $source['version'], |
| 102 | - 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 102 | + 'path' => call_user_func($this->pathCodeTransformer, $path), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if ( ! empty( $autoloads['classmap'] ) ) { |
|
| 110 | - foreach ( $autoloads['classmap'] as $package ) { |
|
| 111 | - $classmap = call_user_func( $this->classmapScanner, $package['path'], $excludedClasses, null ); |
|
| 109 | + if (!empty($autoloads['classmap'])) { |
|
| 110 | + foreach ($autoloads['classmap'] as $package) { |
|
| 111 | + $classmap = call_user_func($this->classmapScanner, $package['path'], $excludedClasses, null); |
|
| 112 | 112 | |
| 113 | - foreach ( $classmap as $class => $path ) { |
|
| 114 | - $processed[ $class ] = array( |
|
| 113 | + foreach ($classmap as $class => $path) { |
|
| 114 | + $processed[$class] = array( |
|
| 115 | 115 | 'version' => $package['version'], |
| 116 | - 'path' => call_user_func( $this->pathCodeTransformer, $path ), |
|
| 116 | + 'path' => call_user_func($this->pathCodeTransformer, $path), |
|
| 117 | 117 | ); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return array $processed |
| 132 | 132 | */ |
| 133 | - public function processPsr4Packages( $autoloads, $scanPsrPackages ) { |
|
| 134 | - if ( $scanPsrPackages || empty( $autoloads['psr-4'] ) ) { |
|
| 133 | + public function processPsr4Packages($autoloads, $scanPsrPackages) { |
|
| 134 | + if ($scanPsrPackages || empty($autoloads['psr-4'])) { |
|
| 135 | 135 | return null; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $processed = array(); |
| 139 | 139 | |
| 140 | - foreach ( $autoloads['psr-4'] as $namespace => $packages ) { |
|
| 141 | - $namespace = empty( $namespace ) ? null : $namespace; |
|
| 140 | + foreach ($autoloads['psr-4'] as $namespace => $packages) { |
|
| 141 | + $namespace = empty($namespace) ? null : $namespace; |
|
| 142 | 142 | $paths = array(); |
| 143 | 143 | |
| 144 | - foreach ( $packages as $package ) { |
|
| 145 | - $paths[] = call_user_func( $this->pathCodeTransformer, $package['path'] ); |
|
| 144 | + foreach ($packages as $package) { |
|
| 145 | + $paths[] = call_user_func($this->pathCodeTransformer, $package['path']); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $processed[ $namespace ] = array( |
|
| 148 | + $processed[$namespace] = array( |
|
| 149 | 149 | 'version' => $package['version'], |
| 150 | 150 | 'path' => $paths, |
| 151 | 151 | ); |
@@ -161,17 +161,17 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @return array|null $processed |
| 163 | 163 | */ |
| 164 | - public function processFiles( $autoloads ) { |
|
| 165 | - if ( empty( $autoloads['files'] ) ) { |
|
| 164 | + public function processFiles($autoloads) { |
|
| 165 | + if (empty($autoloads['files'])) { |
|
| 166 | 166 | return null; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $processed = array(); |
| 170 | 170 | |
| 171 | - foreach ( $autoloads['files'] as $file_id => $package ) { |
|
| 172 | - $processed[ $file_id ] = array( |
|
| 171 | + foreach ($autoloads['files'] as $file_id => $package) { |
|
| 172 | + $processed[$file_id] = array( |
|
| 173 | 173 | 'version' => $package['version'], |
| 174 | - 'path' => call_user_func( $this->pathCodeTransformer, $package['path'] ), |
|
| 174 | + 'path' => call_user_func($this->pathCodeTransformer, $package['path']), |
|
| 175 | 175 | ); |
| 176 | 176 | } |
| 177 | 177 | |