germania-kg / pathserviceprovider
1.0.5
2022-03-30 10:23 UTC
Requires
- php: ^5.6|^7.0
- pimple/pimple: ^3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7|^6.0|^7.0
Suggests
- germania-kg/pathprefixer: Callable that prefixes a paths array (or StdClass) with a base directory
This package is auto-updated.
Last update: 2024-10-29 04:47:48 UTC
README
Pimple Service Provider for working with directory path strings
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.
// 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.
$paths = $dic['Paths']; // array( // 'var', // 'templates' // )
Paths.Prefixer
Returns the prefixer callable
$prefixer = $dic['Paths.Prefixer'];
Paths.absolute
Returns the paths array with each element prefixed before:
$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:
$ composer test # or $ vendor/bin/phpunit