2017 © Pedro Peláez
 

library regex-dependency

image

sieg/regex-dependency

  • Sunday, January 14, 2018
  • by sieg
  • Repository
  • 0 Watchers
  • 1 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

RegEx Dependency Container

Quality Gate Status Coverage Technical Debt Packagist, (*1)

Small, configurable service locator/DI container with possibility to describe keys as regular expressions. The component can be used as a Router too., (*2)

The package is:, (*3)

  • compliant to PSR-11.
  • follow the PSR-4 and PSR-12
  • works on PHP 7.2+.

Simple case

$configuration = new Collection(
    new Item('key', 'value'),
);

$container = new Container($configuration);
$value = $container->get('key');

var_dump:
  string(5) "value"

Pattern case

$configuration = new Collection(
    new Pattern('examplePattern', '/Example\/.*?$/i', 'SomeValue'),
);

$container = new Container($configuration);
$value = $container->get('Example/Something');

var_dump:
  string(9) "SomeValue"

Value as callback

$configuration = new Collection(
    new Pattern('examplePattern', '/Example\/(?P<special>.*?)$/i', function ($dependency, $match) {
        return $match;
    }),
);

$container = new Container($configuration);
$keyValue = $container->get('Example/Something');

var_dump:
  array(3) {
    [0] => string(17) "Example/Something"
    'special' => string(9) "Something"
    [1] => string(9) "Something"
  }

Two arguments is sent to callbacks:, (*4)

  • Container $dependency - current instance of container
  • array $match - array with match results: the match response is provided: ['Controller/SomeName', 'SomeName']

Service registry

Objects returned by callbacks are not cached by default, but they can be, if wrapped as a Service., (*5)

$configuration = new Collection(
    new Item('someKey', function (Container $dependency) {
        return new Service(new \stdClass());
    })
);

The Versions

14/01 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Development Requires

by Anton Fedurtsya

14/01 2018

v0.2.1

0.2.1.0

  Sources   Download

MIT

The Development Requires

by Anton Fedurtsya

31/12 2017

v0.2.0

0.2.0.0

  Sources   Download

MIT

The Development Requires

by Anton Fedurtsya

03/06 2017

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Development Requires

by Anton Fedurtsya