phpactor / file-path-resolver
Resolve files paths for your application (e.g. cache, data, etc)
Installs: 46 219
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- dnoegel/php-xdg-base-dir: ^0.1.0
- webmozart/path-util: ^2.3
Requires (Dev)
- ergebnis/composer-normalize: ^2.0
- friendsofphp/php-cs-fixer: ^2.17
- phpbench/phpbench: dev-master
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ~0.12.0
- phpunit/phpunit: ^9.0
- psr/log: ^1.1
README
Resolves file paths by filtering and replacing tokens with values.
- Canonicalization support via
webmozart/path-util
- XDG directory expansion via
dnoegel/php-xdg-base-dir
This package can be used in, for example, a CLI application such as Phpactor to resolve application paths.
Usage
$pathResolver = new PathResolver([ new CanonicalizationFilter(), new TokenExpandingFilter([ new ValueExpander('%my_token%', 'my_value'), new XdgCacheExpander('%xdg_cache%'), new XdgConfigExpander('%xdg_conifg%'), new CallbackExpander('%callback%', function () { return 'hello from callback'; }); ]) ]); $pathResolver->resolve('/foo/../foo/%my_token%'); // foo/my_value $pathResolver->resolve('%xdg_home%/my_app'); // /home/user/.config/my_app $pathResolver->resolve('%callback%'); // hello from callback
Contributing
This package is open source and welcomes contributions! Feel free to open a pull request on this repository.
Support
- Create an issue on the main Phpactor repository.
- Join the
#phpactor
channel on the Slack Symfony Devs channel.