Publish and discover assets in your PHP projects.
This package is designed for framework developers and package developers. It helps you find "static" assets in your Composer packages.
For your project, you are looking to search through all the installed packages for some kind of resource. It could be:
We offer a simple solution to solve this problem:
discovery.json
file at the root of the package. This file contains the list of published assets.thecodingmachine/discovery
in your projectTheCodingMachine\Discovery
class to explore the available assetsDiscovery should be of great use to framework developers.
Look at the way most frameworks handle the installation of bundles/modules:
composer.json
This second step is completely useless. If a developer adds a Composer dependency, it is almost always to use it. It would be great if the framework could easily explore composer packages and find modules/bundles or service providers by itself.
Discovery allows this:
use TheCodingMachine\Discovery;
$assets = Discovery::getInstance()->get('my_framework_modules');
// This would scan all discovery.json files and returns an array of class names.
In the example above, my_framework_modules
is the "asset type". It represents a kind of static assets (in this case, the class name of a framework module).
In packages publishing assets, put a discovery.json
with the following format:
{
"my_framework_modules": [
"My\\Module\\ClassName",
"My\\OtherModule\\ClassName"
]
}
Want to view the full syntax of discovery.json
? Check out the discovery.json schema document
Also, an asset type can be really anything, it does not have to be a class name. For instance, you could decide to publish some translation files:
{
"translations": [
"translations/translation.po"
]
}
Simply run:
composer require thecodingmachine/discovery
Found a typo? Something is wrong in this documentation? Just fork and edit it!