pklink/file-router
最新稳定版本:1.0.0
Composer 安装命令:
composer require pklink/file-router
包简介
Library for mapping files in a directory to routes
关键字:
README 文档
README
A library for mapping files in a directory to routes like hello/world
Usage
Router for including PHP files
We have the following file structure:
.
├── example.php
└── includes
├── hello
│ └── world.php
└── hello.php
And here is our example.php
// the source path for including files $sourcePath = new SplFileInfo(__DIR__ . '/includes'); // create router $router = new \FileRouter\Router\IncludeRouter($sourcePath);
Now you can load/include files in the includes-directory
$router->handleRoute('hello'); // include includes/hello.php $router->handleRoute('hello/world'); // include includes/hello/world.php
Or like this:
$router->handleRoute($_GET['r']);
Router for printing txt-files
We have the following file structure:
.
├── example.php
└── docs
├── hello
│ └── world.txt
└── hello.txt
And here is our example.php
// the source path for including files $sourcePath = new SplFileInfo(__DIR__ . '/docs'); // create router $router = new \FileRouter\Router\OutputTxtRouter($sourcePath);
Now you can print/output files in the docs-directory
$router->handleRoute('hello'); // print includes/hello.txt $router->handleRoute('hello/world'); // print includes/hello/world.txt
Advanced Usage
Write your own Router
It is no problem to write and add your own router. Implement the interface \FileRouter\Router or use the abtract implementation of \FileRouter\Router\AbstractImpl, so you only need to implement Router::handleRoute()
class CustomRouter extends \FileRouter\Router\AbstractRouter { public function handleRoute($router) { /* @var \SplFileInfo $routingFile */ $routingFile = $this->getFileByRoute($route); // do something } }
Run Tests
You can use PHPUnit from the vendor-folder.
php composer.phar install --dev php vendor/bin/phpunit tests/
License
This package is licensed under the MIT License. See the LICENSE file for details.
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-19