Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit a2b1c66

Browse files
committed
Adding /vendor directory to release
1 parent f95b80b commit a2b1c66

File tree

145 files changed

+7809
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+7809
-0
lines changed

vendor/autoload.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInitba36834ec8b2e5e5ddc80d04c557a736::getLoader();

vendor/autoload_packages.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* This file was automatically generated by automattic/jetpack-autoloader.
4+
*
5+
* @package automattic/jetpack-autoloader
6+
*/
7+
8+
namespace Automattic\Jetpack\Autoloader\jpba36834ec8b2e5e5ddc80d04c557a736;
9+
10+
// phpcs:ignore
11+
12+
require_once __DIR__ . '/jetpack-autoloader/class-autoloader.php';
13+
Autoloader::init();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
A custom autoloader for Composer
2+
=====================================
3+
4+
This is a custom autoloader generator that uses a classmap to always load the latest version of a class.
5+
6+
The problem this autoloader is trying to solve is conflicts that arise when two or more plugins use the same package, but one of the plugins uses an older version of said package.
7+
8+
This is solved by keeping an in memory map of all the different classes that can be loaded, and updating the map with the path to the latest version of the package for the autoloader to find when we instantiate the class.
9+
10+
It diverges from the default Composer autoloader setup in the following ways:
11+
12+
* It creates `jetpack_autoload_classmap.php` and `jetpack_autoload_filemap.php` files in the `vendor/composer` directory.
13+
* This file includes the version numbers from each package that is used.
14+
* The autoloader will only load the latest version of the library no matter what plugin loads the library.
15+
16+
17+
Usage
18+
-----
19+
20+
In your project's `composer.json`, add the following lines:
21+
22+
```json
23+
{
24+
"require-dev": {
25+
"automattic/jetpack-autoloader": "^1"
26+
}
27+
}
28+
```
29+
30+
Your project must use the default composer vendor directory, `vendor`.
31+
32+
After the next update/install, you will have a `vendor/autoload_packages.php` file.
33+
Load the file in your plugin via main plugin file.
34+
35+
In the main plugin you will also need to include the files like this.
36+
```php
37+
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php';
38+
```
39+
40+
Working with Development Versions of Packages
41+
-----
42+
43+
The autoloader will attempt to use the package with the latest semantic version.
44+
45+
During development, you can force the autoloader to use development package versions by setting the `JETPACK_AUTOLOAD_DEV` constant to true. When `JETPACK_AUTOLOAD_DEV` is true, the autoloader will prefer the following versions over semantic versions:
46+
- `9999999-dev`
47+
- Versions with a `dev-` prefix.
48+
49+
50+
Autoloading Standards
51+
----
52+
53+
All new Jetpack package development should use classmap autoloading, which allows the class and file names to comply with the WordPress Coding Standards.
54+
55+
### Optimized Autoloader
56+
57+
An optimized autoloader is generated when:
58+
* `composer install` or `composer update` is called with `-o` or `--optimize-autoloader`
59+
* `composer dump-autoload` is called with `-o` or `--optimize`
60+
61+
PSR-4 and PSR-0 namespaces are converted to classmaps.
62+
63+
### Unoptimized Autoloader
64+
65+
Supports PSR-4 autoloading. PSR-0 namespaces are converted to classmaps.
66+
67+
68+
Autoloader Limitations
69+
-----
70+
71+
Plugin Updates
72+
73+
When moving a package class file, renaming a package class file, or changing a package class namespace, make sure that the class will not be loaded after a plugin update.
74+
75+
The autoloader builds the in memory classmap as soon as the autoloader is loaded. The package class file paths in the map are not updated after a plugin update. If a plugins's package class files are moved during a plugin update and a moved file is autoloaded after the update, an error will occur.
76+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "automattic/jetpack-autoloader",
3+
"description": "Creates a custom autoloader for a plugin or theme.",
4+
"type": "composer-plugin",
5+
"license": "GPL-2.0-or-later",
6+
"require": {
7+
"composer-plugin-api": "^1.1 || ^2.0"
8+
},
9+
"require-dev": {
10+
"yoast/phpunit-polyfills": "0.2.0"
11+
},
12+
"autoload": {
13+
"classmap": [
14+
"src/AutoloadGenerator.php"
15+
],
16+
"psr-4": {
17+
"Automattic\\Jetpack\\Autoloader\\": "src"
18+
}
19+
},
20+
"extra": {
21+
"class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin"
22+
},
23+
"scripts": {
24+
"phpunit": [
25+
"@composer install",
26+
"./vendor/phpunit/phpunit/phpunit --colors=always"
27+
]
28+
},
29+
"minimum-stability": "dev",
30+
"prefer-stable": true
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php // phpcs:ignore WordPress.Files.FileName
2+
/**
3+
* Autoloader file writer.
4+
*
5+
* @package automattic/jetpack-autoloader
6+
*/
7+
8+
// phpcs:disable WordPress.Files.FileName.InvalidClassFileName
9+
// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
10+
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
11+
// phpcs:disable WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase
12+
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
13+
// phpcs:disable WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase
14+
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_export
15+
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
16+
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen
17+
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite
18+
19+
namespace Automattic\Jetpack\Autoloader;
20+
21+
/**
22+
* Class AutoloadFileWriter.
23+
*/
24+
class AutoloadFileWriter {
25+
26+
/**
27+
* The file comment to use.
28+
*/
29+
const COMMENT = <<<AUTOLOADER_COMMENT
30+
/**
31+
* This file was automatically generated by automattic/jetpack-autoloader.
32+
*
33+
* @package automattic/jetpack-autoloader
34+
*/
35+
36+
AUTOLOADER_COMMENT;
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+
);
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+
}
64+
65+
if ( in_array( $file, $ignoreList, true ) ) {
66+
continue;
67+
}
68+
69+
$newFile = isset( $renameList[ $file ] ) ? $renameList[ $file ] : $file;
70+
$content = self::prepareAutoloaderFile( $file, $suffix );
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+
}
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;
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+
}
105+
}

0 commit comments

Comments
 (0)