Skip to content

rhys-mcguckin/discovery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License

This code is released under the MIT and LGPL licences.

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.

This is an alternative to code annotations.

Usage

Using within PHP requires adding at least a source, with an optional cache.

$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.

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.

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.

Minimum required:

type: type-name
subtype: type-name

Example:

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

About

Alternative discovery of meta information for classes.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages