This package is deprecated.
- Install package using composer.
composer require railt/discovery
- Add discovering event into your
composer.json
.
{
"scripts": {
"post-autoload-dump": [
"Railt\\Discovery\\Manifest::discover"
]
}
}
Discovery provides the ability to implement a cross-package
configuration using composer.json
.
In order to access the configuration group, you must specify the key
name in the extra
section:
{
"extra": {
"discovery": ["your-key"]
}
}
Any group that is listed inside the {"extra": {"discovery": ...}}
section
will be available, exported and readable.
{
"extra": {
"discovery": ["example-2"],
"example-1": "value", // This section will be IGNORED
"example-2": "value" // Only this section will be exported
}
}
After updating the composer dependencies, an object with the specified configs
will be formed. In order to further read this data - you need to use the
Discovery
class.
{
"extra": {
"discovery": ["config"],
"config": {
"commands": [
"ExampleCommand1",
"ExampleCommand2"
]
}
}
}
<?php
$discovery = new Railt\Discovery\Discovery(__DIR__ . '/vendor');
$discovery->get('config.commands');
// array(2) { "ExampleCommand1", "ExampleCommand2" }
You can try to create a Discovery instance using automatic logic to determine the paths to the vendor directory.
<?php
$discovery = Railt\Discovery\Discovery::auto();
You can create a new Discovery instance from the Composer ClassLoader.
<?php
// Composer ClassLoader
$loader = require __DIR__ . '/vendor/autoload.php';
$discovery = Railt\Discovery\Discovery::fromClassLoader($loader);
You can create instances of Discovery from Composer plugins using the appropriate static constructor.
<?php
use Composer\Composer;
use Railt\Discovery\Discovery;
class ComposerPlugin
{
public function __construct(Composer $composer)
{
$discovery = Discovery::fromComposer($composer);
}
}
In order to exclude any value from the export data - you need to
register the necessary paths in the section except:discovery
.
Please note that this rule is valid only in the root package composer.json
.
{
"extra": {
"discovery:except": [
"example-1",
"example-2:child-1:a",
"example-2:test:value-2"
],
"example-1": { // This value should be skipped by rule "example-1"
"key": "value"
},
"example-2": {
"child-1": {
"a": 1, // This value should be skipped by rule "example-2:child-1:a"
"b": 2
},
"test": [
"value-1",
"value-2" // This value should be skipped by rule "example-2:test:value-2"
]
}
}
}