xylemical/composer-discovery

Provides a composer plugin for discovery of items within packages.

dev-master 2022-06-30 05:52 UTC

This package is auto-updated.

Last update: 2024-04-29 04:41:21 UTC


README

Provides composer with a way to perform discovery processes.

Install

The recommended way to install this library is through composer.

composer require xylemical/composer-discovery

Usage

Once a discovery process has been defined in a package, any package or project that requires the package will have the discovery applied.

Adding a discovery is as simple as defining the discovery class in the extra key of the composer.json file:

{
  "extra": {
    "discovery": [
      "My\\Discovery"
    ]
  }
}

An example discovery that prints out all the package readme files is as follows:

namespace My;

use Xylemical\Composer\Discovery\ComposerDiscoveryBase;

/**
 * Performs output of README.md for any package that defines it.
 */
class Discovery extends ComposerDiscoveryBase {

  /**
   * {@inheritdoc}
   */
  public function getName(): string {
    return 'My Discovery';
  }

  /**
   * {@inheritdoc}
   */
  public function discover(Package $package): void {
    $path = $package->getPath() . '/README.md';
    if (file_exists($path)) {
      $this->io->write(file_get_contents($path));
    }
  }

}

License

MIT, see LICENSE.