https://github.com/xwp/io-php-wp-autoload
[READ ONLY]
https://github.com/xwp/io-php-wp-autoload
Last synced: 5 months ago
JSON representation
[READ ONLY]
- Host: GitHub
- URL: https://github.com/xwp/io-php-wp-autoload
- Owner: xwp
- Created: 2022-05-17T12:53:25.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-27T14:42:13.000Z (over 2 years ago)
- Last Synced: 2025-07-19T04:55:50.586Z (12 months ago)
- Language: PHP
- Homepage: https://github.com/xwp/io
- Size: 3.91 KB
- Stars: 2
- Watchers: 29
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## WP Autoload
PHP autoloader for projects with [file naming conventions from WordPress coding standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions).
Attempts to resolve classes, interfaces and traits.
## Usage
Add this library as a dependency for your project:
composer require xwp/wp-autoload
Register the namespace mapping to folders containing your code:
```php
$autoload = new XWP\IO\WP_Autoload\Autoload();
$autoload->add(
__DIR__ . '/php',
'YourVendor\Project'
);
$autoload->add(
__DIR__ . '/lib/rest-api',
'Another_Vendor\Rest_Api'
);
// Now instantiate the class without any includes.
$api = new YourVendor\Project\Module_One\Api();
```
For example, a request for `YourVendor\Project\Module_One\Api` will attempt to include the following files:
- `.../php/module-one/class-api.php`
- `.../php/module-one/interface-api.php`
- `.../php/module-one/trait-api.php`