-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48ef676
Showing
13 changed files
with
533 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.php] | ||
ident_size = 4 | ||
|
||
[*.md] | ||
ident_size = 2 | ||
trim_trailing_whitespace = false | ||
|
||
[*.json] | ||
ident_size = 2 | ||
|
||
[{.gitignore,.gitkeep,.editorconfig}] | ||
ident_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
vendor/ | ||
composer.lock | ||
.phpcs.xml | ||
phpcs.xml | ||
.vscode | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changelog | ||
|
||
All notable changes to `alleyinteractive/composer-wordpress-autoloader` will be | ||
documented in this file. | ||
|
||
## [Unreleased] | ||
|
||
## 0.1.0 | ||
|
||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Composer WordPress Autoloader | ||
|
||
[![Latest Version on Packagist](https://img.shields.io/packagist/v/alleyinteractive/composer-wordpress-autoloader.svg?style=flat-square)](https://packagist.org/packages/alleyinteractive/composer-wordpress-autoloader) | ||
[![Tests](https://github.com/alleyinteractive/composer-wordpress-autoloader/actions/workflows/tests.yml/badge.svg)](https://github.com/alleyinteractive/composer-wordpress-autoloader/actions/workflows/tests.yml) | ||
|
||
Autoload WordPress files configured via Composer that support the [Wordpress | ||
Coding | ||
Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/) | ||
using | ||
[alleyinteractive/wordpress-autoloader](https://github.com/alleyinteractive/wordpress-autoloader). | ||
|
||
## Installation | ||
|
||
You can install the package via composer: | ||
|
||
```bash | ||
composer require alleyinteractive/composer-wordpress-autoloader | ||
``` | ||
|
||
## Usage | ||
|
||
```json | ||
{ | ||
"autoload": { | ||
"wordpress": { | ||
"My_Plugin_Namespace\\": "src/", | ||
} | ||
}, | ||
"autoload-dev": { | ||
"wordpress": { | ||
"My_Plugin_Namespace\\Tests\\": "tests/", | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Once added a `vendor/wordpress-autoload.php` file will be created. You can load | ||
that in place of `vendor/autoload.php` (it will load that for you) to load you | ||
WordPress and Composer dependencies. | ||
|
||
|
||
### Automatically Injecting WordPress Autoloader | ||
|
||
Composer WordPress Autoloader can also automatically inject the WordPress | ||
autoloader into your `vendor/autoload.php` file you're already loading. This is | ||
disabled by default. | ||
|
||
```json | ||
{ | ||
"extra": { | ||
"wordpress-autoloader": { | ||
"inject": true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Once enabled, you can load `vendor/autoload.php` like you do normally and have | ||
your WordPress files automatically loaded. | ||
|
||
## Testing | ||
|
||
```bash | ||
composer test | ||
``` | ||
|
||
## Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "alleyinteractive/composer-wordpress-autoloader", | ||
"type": "composer-plugin", | ||
"description": "Autoload files using WordPress File Conventions", | ||
"license": "GPL-2.0-or-later", | ||
"authors": [ | ||
{ | ||
"name": "Alley Interactive", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Sean Fisher", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.4", | ||
"alleyinteractive/wordpress-autoloader": "^0.1", | ||
"composer-plugin-api": "^2.0", | ||
"squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" | ||
}, | ||
"require-dev": { | ||
"composer/composer": "^2.0", | ||
"phpunit/phpunit": "^8.5.8 || ^9.3.3" | ||
}, | ||
"extra": { | ||
"class": "ComposerWordPressAutoloader\\Plugin" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"ComposerWordPressAutoloader\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"lint": "@phpcs", | ||
"lint:fix": "@phpcbf", | ||
"phpcbf": "phpcbf --standard=./phpcs.xml.dist .", | ||
"phpcs": "phpcs --standard=./phpcs.xml.dist .", | ||
"phpunit": "vendor/bin/phpunit", | ||
"test": "@phpunit" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="phpcodesniffer-composer-installer"> | ||
<description>Coding standards for Composer WordPress Autoload Plugin</description> | ||
|
||
<arg name="extensions" value="php" /> | ||
<!-- Show sniff codes in all reports, and progress when running --> | ||
<arg value="sp" /> | ||
<!-- Strip the filepaths down to the relevant bit. --> | ||
<arg name="basepath" value="." /> | ||
|
||
<file>.</file> | ||
<exclude-pattern>*/.github/*</exclude-pattern> | ||
<exclude-pattern>*/vendor/*</exclude-pattern> | ||
<exclude-pattern>tests/includes/*</exclude-pattern> | ||
|
||
<rule ref="PSR12"> | ||
<!-- Constant visibility can not be declared (yet) as the minimum supported PHP version is 5.3 | ||
and constant visibility was only introduced in PHP 7.1. --> | ||
<exclude name="PSR12.Properties.ConstantVisibility.NotFound" /> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<phpunit | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
> | ||
<testsuites> | ||
<testsuite name="alleyinteractive/composer-wordpress-autoload"> | ||
<file>tests/AutoloaderTest.php</file> | ||
<!-- <directory>tests</directory> --> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace ComposerWordPressAutoloader; | ||
|
||
use Alley_Interactive\Autoloader\Autoloader; | ||
|
||
class AutoloadFactory | ||
{ | ||
/** | ||
* Generate an autoloader from a set of rules. | ||
* | ||
* @param array<string, array<string>> $rules Array of rules. | ||
* @return array<Autoloader> | ||
*/ | ||
public static function generateFromRules(array $rules, string $baseDir) | ||
{ | ||
$loaders = []; | ||
|
||
foreach ($rules as $namespace => $paths) { | ||
$loaders = array_merge( | ||
$loaders, | ||
array_map( | ||
fn ($path) => Autoloader::generate($namespace, $baseDir . '/' . $path), | ||
$paths, | ||
), | ||
); | ||
} | ||
|
||
return $loaders; | ||
} | ||
|
||
/** | ||
* Register autoloaders from rules. | ||
* | ||
* @param array<string, string> $rules Array of rules. | ||
* @return void | ||
*/ | ||
public static function registerFromRules(array $rules, string $baseDir) | ||
{ | ||
foreach (static::generateFromRules($rules, $baseDir) as $autoloader) { | ||
$autoloader->register(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace ComposerWordPressAutoloader; | ||
|
||
use Composer\Autoload\AutoloadGenerator as ComposerAutoloadGenerator; | ||
use Composer\Package\PackageInterface; | ||
|
||
/** | ||
* Composer Autoload Generator | ||
*/ | ||
class AutoloadGenerator extends ComposerAutoloadGenerator | ||
{ | ||
/** | ||
* Compiles an ordered list of namespace => path mappings | ||
* | ||
* @param array $packageMap | ||
* @param PackageInterface $rootPackage | ||
* @param boolean $filteredDevPackages | ||
* @return array | ||
*/ | ||
public function parseAutoloads(array $packageMap, PackageInterface $rootPackage, $filteredDevPackages = false) | ||
{ | ||
if ($filteredDevPackages) { | ||
$packageMap = $this->filterPackageMap($packageMap, $rootPackage); | ||
} | ||
|
||
return [ | ||
'wordpress' => $this->parseAutoloadsType($packageMap, 'wordpress', $rootPackage), | ||
]; | ||
} | ||
} |
Oops, something went wrong.