xwp/wp-autoload

There is no license information available for the latest version (1.0.0) of this package.

1.0.0 2023-11-27 14:41 UTC

This package is auto-updated.

Last update: 2024-10-27 16:29:11 UTC


README

PHP autoloader for projects with file naming conventions from WordPress coding standards.

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:

$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