PHPackages                             pfaciana/composer-autoloader-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pfaciana/composer-autoloader-plugin

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

pfaciana/composer-autoloader-plugin
===================================

Composer plugin that scans for #\[Autoload\] attributes and generates bootstrap code

0.4.3(2w ago)024↑25%GPL-2.0-onlyPHPPHP ^8.2CI passing

Since May 17Pushed 2w agoCompare

[ Source](https://github.com/pfaciana/composer-autoloader-plugin)[ Packagist](https://packagist.org/packages/pfaciana/composer-autoloader-plugin)[ Docs](https://renderdev.com/)[ RSS](/packages/pfaciana-composer-autoloader-plugin/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (8)Dependencies (4)Versions (9)Used By (0)

Composer Autoloader Plugin
==========================

[](#composer-autoloader-plugin)

Generate Composer bootstrap files from PHP attributes or directory patterns.

This package is a Composer plugin. It runs during `composer dump-autoload`, writes generated bootstrap files into `vendor/composer` by default, and registers those files with Composer's `autoload.files` list.

Install
-------

[](#install)

```
composer require pfaciana/composer-autoloader-plugin
composer config allow-plugins.pfaciana/composer-autoloader-plugin true
```

After changing config, adding or removing autoload attributes, or changing matched files, regenerate Composer autoload files:

```
composer dump-autoload
```

Understanding Patterns
----------------------

[](#understanding-patterns)

A major feature of this plugin is that it can scan files by patterns. These patterns mirror the patterns used by .gitignore files. If you already know how to use a .gitignore file, then you know how to use patterns here. The only difference is this plugins uses "include" patterns instead of "ignore" patterns. So your patterns will likely be inverted from your .gitignore file.

This done using the `pfaciana/includefile` package, which is an inverted wrapper around `automattic/ignorefile`.

Both `autoload-by-attr.patterns` and `autoload-by-dir.patterns` use `pfaciana/includefile`.

Example patterns:

```
**/*.php
!vendor
!node_modules
!src/Excluded

```

---

Attribute Autoloading
---------------------

[](#attribute-autoloading)

Attribute autoloading scans PHP files for functions or public static methods marked with an attribute, then generates a bootstrap file that calls them.

By default, it looks for `#[AutoRun]`.

```
{
	"extra": {
		"autoload-by-attr": {
			"patterns": [
				"src"
			]
		}
	}
}
```

```
