opxcore / pathset
OpxCore path set component.
1.0.5
2020-06-23 13:41 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.1.5
This package is not auto-updated.
Last update: 2024-11-21 06:44:19 UTC
README
Path set is an abstraction level for defining sets of path collections, e.g. search paths.
Each Path
is associated with primary path and alternates. In the PathSet
each path is associated with name. Getting
set for some name will return array of registered paths for this name in backward order without duplicates.
The '*'
name is a global path set and will be included in all other sets.
Installing
composer require opxcore/pathset
Examples
Simple usage:
$pathSet = new PathSet;
$pathSet->add('name', 'primary', ['alternate_1', 'alternate_2']);
$set = $pathSet->get('name');
// $set = [
// 'alternate_2',
// 'alternate_1',
// 'primary'
// ]
Defining with a constructor:
$pathSet = new PathSet(['name', ['primary', 'alternate_1', 'alternate_2']]);
$set = $pathSet->get('name');
// $set = [
// 'alternate_2',
// 'alternate_1',
// 'primary'
// ]
Usage with a global name:
$pathSet = new PathSet;
$pathSet->add('*', 'global_primary', ['global_alternate_1', 'global_alternate_2']);
$pathSet->add('name', 'primary', ['alternate_1', 'alternate_2']);
$set = $pathSet->get('name');
// $set = [
// 'alternate_2',
// 'alternate_1',
// 'primary',
// 'global_alternate_2',
// 'global_alternate_1',
// 'global_primary'
// ]
Adding alternates:
$pathSet = new PathSet(['name', ['primary', 'alternate_1']]);
...
$pathSet['name']->addAlternates(['alternate_2']);
...
$set = $pathSet->get('name');
// $set = [
// 'alternate_2',
// 'alternate_1',
// 'primary'
// ]