Germania KG · PathServiceProvider
Pimple Service Provider for working with directory path strings, (*1)
, (*2)
Installation
$ composer require germania-kg/pathserviceprovider
Setup
<?php
use Germania\PathServiceProvider\PathServiceProvider;
// A. Use with Slim or Pimple
$app = new \Slim\App;
$dic = $app->getContainer();
$dic = new Pimple\Container;
// B. Register Service Provider. Paths array is optional.
$sp = new PathServiceProvider;
$sp = new PathServiceProvider( [
'var',
'templates'
]);
$dic->register( $sp );
Using a custom prefixer callable. There's also a package for this, try germania-kg/pathprefixer., (*3)
// C. Pass optional callable
$sp = new PathServiceProvider( $paths, function( $path ) {
return '/path/to/project/' . $path;
});
$dic->register( $sp );
Services
Paths
Returns the paths array passed to constructor., (*4)
$paths = $dic['Paths'];
// array(
// 'var',
// 'templates'
// )
Paths.Prefixer
Returns the prefixer callable, (*5)
$prefixer = $dic['Paths.Prefixer'];
Paths.absolute
Returns the paths array with each element prefixed before:, (*6)
$absolute_paths = $dic['Paths.absolute'];
Development
$ git clone https://github.com/GermaniaKG/PathServiceProvider.git
$ cd PathServiceProvider
$ composer install
Unit tests
Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:, (*7)
$ composer test
# or
$ vendor/bin/phpunit