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

Commit d8fdcb4

Browse files
committed
Adding /vendor directory to release
1 parent 06c1af6 commit d8fdcb4

File tree

126 files changed

+6274
-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.

126 files changed

+6274
-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 ComposerAutoloaderInit46acee30c6d9a1217b2d09f2476e01bd::getLoader();

vendor/autoload_functions.php

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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\jp4160396d828d4e7f7fc92237940a5691;
9+
10+
// phpcs:ignore
11+
12+
global $jetpack_packages_classmap;
13+
global $jetpack_packages_filemap;
14+
global $jetpack_autoloader_activating_plugins_paths;
15+
16+
if ( ! is_array( $jetpack_packages_classmap ) ) {
17+
$jetpack_packages_classmap = array();
18+
}
19+
20+
if ( ! is_array( $jetpack_packages_filemap ) ) {
21+
$jetpack_packages_filemap = array();
22+
}
23+
24+
if ( ! is_array( $jetpack_autoloader_activating_plugins_paths ) ) {
25+
$jetpack_autoloader_activating_plugins_paths = array();
26+
}
27+
28+
/**
29+
* Used for autoloading jetpack packages.
30+
*
31+
* @param string $class_name Class Name to load.
32+
*
33+
* @return Boolean Whether the class_name was found in the classmap.
34+
*/
35+
function autoloader( $class_name ) {
36+
global $jetpack_packages_classmap;
37+
38+
if ( isset( $jetpack_packages_classmap[ $class_name ] ) ) {
39+
require_once $jetpack_packages_classmap[ $class_name ]['path'];
40+
return true;
41+
}
42+
43+
return false;
44+
}
45+
46+
/**
47+
* Used for running the code that initializes class and file maps.
48+
*
49+
* @param Plugins_Handler $plugins_handler The Plugins_Handler object.
50+
* @param Version_Selector $version_selector The Version_Selector object.
51+
*/
52+
function enqueue_files( $plugins_handler, $version_selector ) {
53+
require_once __DIR__ . '/class-classes-handler.php';
54+
require_once __DIR__ . '/class-files-handler.php';
55+
56+
$classes_handler = new Classes_Handler( $plugins_handler, $version_selector );
57+
$classes_handler->set_class_paths();
58+
59+
$files_handler = new Files_Handler( $plugins_handler, $version_selector );
60+
$files_handler->set_file_paths();
61+
62+
$files_handler->file_loader();
63+
}
64+
65+
/**
66+
* Finds the latest installed autoloader. If this is the latest autoloader, sets
67+
* up the classmap and filemap.
68+
*/
69+
function set_up_autoloader() {
70+
global $jetpack_autoloader_latest_version;
71+
global $jetpack_packages_classmap;
72+
73+
require_once __DIR__ . '/class-plugins-handler.php';
74+
require_once __DIR__ . '/class-version-selector.php';
75+
require_once __DIR__ . '/class-autoloader-handler.php';
76+
77+
$plugins_handler = new Plugins_Handler();
78+
$version_selector = new Version_Selector();
79+
$autoloader_handler = new Autoloader_Handler( $plugins_handler, $version_selector );
80+
81+
if ( $plugins_handler->should_autoloader_reset() ) {
82+
/*
83+
* The autoloader must be reset when an activating plugin that was
84+
* previously unknown is detected.
85+
*/
86+
$jetpack_autoloader_latest_version = null;
87+
$jetpack_packages_classmap = array();
88+
}
89+
90+
// Find the latest autoloader.
91+
if ( ! $jetpack_autoloader_latest_version ) {
92+
$autoloader_handler->find_latest_autoloader();
93+
}
94+
95+
$current_autoloader_version = $autoloader_handler->get_current_autoloader_version();
96+
97+
// This is the latest autoloader, so generate the classmap and filemap and register the autoloader function.
98+
if ( empty( $jetpack_packages_classmap ) && $current_autoloader_version === $jetpack_autoloader_latest_version ) {
99+
enqueue_files( $plugins_handler, $version_selector );
100+
$autoloader_handler->update_autoloader_chain();
101+
add_filter( 'upgrader_post_install', __NAMESPACE__ . '\reset_maps_after_update', 0, 3 );
102+
}
103+
}
104+
105+
/**
106+
* Resets the autoloader after a plugin update.
107+
*
108+
* @param bool $response Installation response.
109+
* @param array $hook_extra Extra arguments passed to hooked filters.
110+
* @param array $result Installation result data.
111+
*
112+
* @return bool The passed in $response param.
113+
*/
114+
function reset_maps_after_update( $response, $hook_extra, $result ) {
115+
global $jetpack_autoloader_latest_version;
116+
global $jetpack_packages_classmap;
117+
118+
if ( isset( $hook_extra['plugin'] ) ) {
119+
/*
120+
* $hook_extra['plugin'] is the path to the plugin file relative to the plugins directory:
121+
* https://core.trac.wordpress.org/browser/tags/5.4/src/wp-admin/includes/class-wp-upgrader.php#L701
122+
*/
123+
$plugin = $hook_extra['plugin'];
124+
125+
if ( false === strpos( $plugin, '/', 1 ) ) {
126+
// Single-file plugins don't use packages, so bail.
127+
return $response;
128+
}
129+
130+
if ( ! is_plugin_active( $plugin ) ) {
131+
// The updated plugin isn't active, so bail.
132+
return $response;
133+
}
134+
135+
/*
136+
* $plugin is the path to the plugin file relative to the plugins directory.
137+
* What if this plugin is not in the plugins directory, for example an mu plugin?
138+
*/
139+
$plugin_path = trailingslashit( WP_PLUGIN_DIR ) . trailingslashit( explode( '/', $plugin )[0] );
140+
141+
if ( is_readable( $plugin_path . 'vendor/autoload_functions.php' ) ) {
142+
// The plugin has a v2.x autoloader, so reset it.
143+
$jetpack_autoloader_latest_version = null;
144+
$jetpack_packages_classmap = array();
145+
146+
set_up_autoloader();
147+
}
148+
}
149+
150+
return $response;
151+
}
152+

vendor/autoload_packages.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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\jp4160396d828d4e7f7fc92237940a5691;
9+
10+
// phpcs:ignore
11+
12+
require_once trailingslashit( dirname( __FILE__ ) ) . '/autoload_functions.php';
13+
14+
set_up_autoloader();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
This only works if we instantiate the class after all the plugins have loaded. That is why the class produces an error if the plugin calls a class but has not loaded all the plugins yet.
10+
11+
It diverges from the default Composer autoloader setup in the following ways:
12+
13+
* It creates an `autoload_classmap_package.php` file in the `vendor/composer` directory.
14+
* This file includes the version numbers from each package that is used.
15+
* The autoloader will only load the latest version of the library no matter what plugin loads the library.
16+
* Only call the library classes after all the plugins have loaded and the `plugins_loaded` action has fired.
17+
18+
19+
Usage
20+
-----
21+
22+
In your project's `composer.json`, add the following lines:
23+
24+
```json
25+
{
26+
"require-dev": {
27+
"automattic/jetpack-autoloader": "^1"
28+
}
29+
}
30+
```
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+
41+
Current Limitations
42+
-----
43+
44+
We currently only support packages that autoload via psr-4 definition in their package.
45+
46+
Your project must use the default composer vendor directory, `vendor`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"Automattic\\Jetpack\\Autoloader\\": "src"
15+
}
16+
},
17+
"extra": {
18+
"class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin"
19+
},
20+
"scripts": {
21+
"phpunit": [
22+
"@composer install",
23+
"./vendor/phpunit/phpunit/phpunit --colors=always"
24+
]
25+
},
26+
"minimum-stability": "dev",
27+
"prefer-stable": true
28+
}

0 commit comments

Comments
 (0)