Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Adding /vendor directory to release
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasfoo committed Sep 22, 2021
1 parent 926ec9d commit 4a01bec
Show file tree
Hide file tree
Showing 151 changed files with 8,019 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit220e3e179ad5cd8a900d49578e4a3b07::getLoader();
13 changes: 13 additions & 0 deletions vendor/autoload_packages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* This file was automatically generated by automattic/jetpack-autoloader.
*
* @package automattic/jetpack-autoloader
*/

namespace Automattic\Jetpack\Autoloader\jp220e3e179ad5cd8a900d49578e4a3b07;

// phpcs:ignore

require_once __DIR__ . '/jetpack-autoloader/class-autoloader.php';
Autoloader::init();
76 changes: 76 additions & 0 deletions vendor/automattic/jetpack-autoloader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
A custom autoloader for Composer
=====================================

This is a custom autoloader generator that uses a classmap to always load the latest version of a class.

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.

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.

It diverges from the default Composer autoloader setup in the following ways:

* It creates `jetpack_autoload_classmap.php` and `jetpack_autoload_filemap.php` files in the `vendor/composer` directory.
* This file includes the version numbers from each package that is used.
* The autoloader will only load the latest version of the library no matter what plugin loads the library.


Usage
-----

In your project's `composer.json`, add the following lines:

```json
{
"require-dev": {
"automattic/jetpack-autoloader": "^1"
}
}
```

Your project must use the default composer vendor directory, `vendor`.

After the next update/install, you will have a `vendor/autoload_packages.php` file.
Load the file in your plugin via main plugin file.

In the main plugin you will also need to include the files like this.
```php
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php';
```

Working with Development Versions of Packages
-----

The autoloader will attempt to use the package with the latest semantic version.

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:
- `9999999-dev`
- Versions with a `dev-` prefix.


Autoloading Standards
----

All new Jetpack package development should use classmap autoloading, which allows the class and file names to comply with the WordPress Coding Standards.

### Optimized Autoloader

An optimized autoloader is generated when:
* `composer install` or `composer update` is called with `-o` or `--optimize-autoloader`
* `composer dump-autoload` is called with `-o` or `--optimize`

PSR-4 and PSR-0 namespaces are converted to classmaps.

### Unoptimized Autoloader

Supports PSR-4 autoloading. PSR-0 namespaces are converted to classmaps.


Autoloader Limitations
-----

Plugin Updates

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.

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.

39 changes: 39 additions & 0 deletions vendor/automattic/jetpack-autoloader/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "automattic/jetpack-autoloader",
"description": "Creates a custom autoloader for a plugin or theme.",
"type": "composer-plugin",
"license": "GPL-2.0-or-later",
"require": {
"composer-plugin-api": "^1.1 || ^2.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "0.2.0"
},
"autoload": {
"classmap": [
"src/AutoloadGenerator.php"
],
"psr-4": {
"Automattic\\Jetpack\\Autoloader\\": "src"
}
},
"scripts": {
"phpunit": [
"@composer install",
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"@composer install",
"phpdbg -d memory_limit=2048M -d max_execution_time=900 -qrr ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin",
"mirror-repo": "Automattic/jetpack-autoloader"
}
}
105 changes: 105 additions & 0 deletions vendor/automattic/jetpack-autoloader/src/AutoloadFileWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php // phpcs:ignore WordPress.Files.FileName
/**
* Autoloader file writer.
*
* @package automattic/jetpack-autoloader
*/

// phpcs:disable WordPress.Files.FileName.InvalidClassFileName
// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
// phpcs:disable WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
// phpcs:disable WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_export
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite

namespace Automattic\Jetpack\Autoloader;

/**
* Class AutoloadFileWriter.
*/
class AutoloadFileWriter {

/**
* The file comment to use.
*/
const COMMENT = <<<AUTOLOADER_COMMENT
/**
* This file was automatically generated by automattic/jetpack-autoloader.
*
* @package automattic/jetpack-autoloader
*/
AUTOLOADER_COMMENT;

/**
* Copies autoloader files and replaces any placeholders in them.
*
* @param IOInterface|null $io An IO for writing to.
* @param string $outDir The directory to place the autoloader files in.
* @param string $suffix The suffix to use in the autoloader's namespace.
*/
public static function copyAutoloaderFiles( $io, $outDir, $suffix ) {
$renameList = array(
'autoload.php' => '../autoload_packages.php',
);
$ignoreList = array(
'AutoloadGenerator.php',
'AutoloadProcessor.php',
'CustomAutoloaderPlugin.php',
'ManifestGenerator.php',
'AutoloadFileWriter.php',
);

// Copy all of the autoloader files.
$files = scandir( __DIR__ );
foreach ( $files as $file ) {
// Only PHP files will be copied.
if ( substr( $file, -4 ) !== '.php' ) {
continue;
}

if ( in_array( $file, $ignoreList, true ) ) {
continue;
}

$newFile = isset( $renameList[ $file ] ) ? $renameList[ $file ] : $file;
$content = self::prepareAutoloaderFile( $file, $suffix );

$written = file_put_contents( $outDir . '/' . $newFile, $content );
if ( $io ) {
if ( $written ) {
$io->writeError( " <info>Generated: $newFile</info>" );
} else {
$io->writeError( " <error>Error: $newFile</error>" );
}
}
}
}

/**
* Prepares an autoloader file to be written to the destination.
*
* @param String $filename a file to prepare.
* @param String $suffix Unique suffix used in the namespace.
*
* @return string
*/
private static function prepareAutoloaderFile( $filename, $suffix ) {
$header = self::COMMENT;
$header .= PHP_EOL;
$header .= 'namespace Automattic\Jetpack\Autoloader\jp' . $suffix . ';';
$header .= PHP_EOL . PHP_EOL;

$sourceLoader = fopen( __DIR__ . '/' . $filename, 'r' );
$file_contents = stream_get_contents( $sourceLoader );
return str_replace(
'/* HEADER */',
$header,
$file_contents
);
}
}
Loading

0 comments on commit 4a01bec

Please sign in to comment.