License
This code is released under the MIT and LGPL licences., (*1)
Purpose
The purpose of this repository is to provide a simplified method of discovering the usage of classes, along with the metadata required to identify the instances of classes., (*2)
This is an alternative to code annotations., (*3)
Usage
Using within PHP requires adding at least a source, with an optional cache., (*4)
$discovery = new Discovery\Discovery();
// Adds a Psr-0 source list.
$discovery->addSource(new Psr(__DIR__ . '/lib'))
// Adds a Psr-4 source list.
$discovery->addSource(new Psr(__DIR__ . '/src', 'Example\\Psr4'))
// Adds a composer source list.
$discovery->addSource(new Composer(__DIR__))
// Sets the meta class that is by default generated by getMeta().
$discovery->setCache(new Cache());
// Get the meta information based on the key 'machine'.
$meta = $discovery->getMeta('type', 'subtype');
// Get a list of all types defined by the meta information.
$types = $discovery->getTypes();
// Get a list of all subtypes defined by the meta information.
$types = $discovery->getSubtype('test');
The YAML files are placed in the same folder or directory as the class for which it is providing meta-information., (*5)
The structure of the YAML file aside from the 'type', 'subtype', 'meta' and 'arguments' keys, is left up to the developer with respect to the class., (*6)
The predefined keys:
* 'type'
This represents the general type of class this is meant to represent.
* 'subtype'
This represents the more specific type of class.
* 'meta'
This is the meta class used to generate meta-information regarding the class.
* 'arguments'
These are arguments that are specifically passed when instantiating the referring class., (*7)
Minimum required:, (*8)
type: type-name
subtype: type-name
Example:, (*9)
type: type-name
subtype: type-name
meta: "Alternative\\Meta\\Class"
arguments: ['arg1', {'option1': 'value'}]
settings:
option1: 1
option2:
- Option 2 Value 1
- Option 2 Value 2