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-08-29 04:25:43 UTC
README
用于处理目录路径字符串的 Pimple 服务提供者
安装
$ composer require germania-kg/pathserviceprovider
设置
<?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 );
使用自定义前缀调用函数。还有这个包,可以尝试 germania-kg/pathprefixer。
// C. Pass optional callable $sp = new PathServiceProvider( $paths, function( $path ) { return '/path/to/project/' . $path; }); $dic->register( $sp );
服务
路径
返回构造函数中传递的路径数组。
$paths = $dic['Paths']; // array( // 'var', // 'templates' // )
Paths.Prefixer
返回前缀调用函数
$prefixer = $dic['Paths.Prefixer'];
Paths.absolute
返回带有每个元素前缀的路径数组
$absolute_paths = $dic['Paths.absolute'];
开发
$ git clone https://github.com/GermaniaKG/PathServiceProvider.git
$ cd PathServiceProvider
$ composer install
单元测试
可以复制 phpunit.xml.dist
到 phpunit.xml
并根据您的需求进行适配,或者保持不变。运行 PhpUnit 测试或 composer 脚本如下
$ composer test # or $ vendor/bin/phpunit