2017 © Pedro Pelรกez
 

library file-router

Library for mapping files in a directory to routes

image

pklink/file-router

Library for mapping files in a directory to routes

  • Sunday, January 3, 2016
  • by pklink
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

FileRouter

Build Status Dependency Status, (*1)

A library for mapping files in a directory to routes like hello/world, (*2)

Usage

Router for including PHP files

We have the following file structure:, (*3)

.
โ”œโ”€โ”€ example.php
โ””โ”€โ”€ includes
    โ”œโ”€โ”€ hello
    โ”‚ย ย  โ””โ”€โ”€ world.php
    โ””โ”€โ”€ hello.php

And here is our example.php, (*4)

// 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, (*5)

$router->handleRoute('hello'); // include includes/hello.php
$router->handleRoute('hello/world'); // include includes/hello/world.php

Or like this:, (*6)

$router->handleRoute($_GET['r']);

Router for printing txt-files

We have the following file structure:, (*7)

.
โ”œโ”€โ”€ example.php
โ””โ”€โ”€ docs
    โ”œโ”€โ”€ hello
    โ”‚ย ย  โ””โ”€โ”€ world.txt
    โ””โ”€โ”€ hello.txt

And here is our example.php, (*8)

// 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, (*9)

$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(), (*10)

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., (*11)

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., (*12)

The Versions

03/01 2016

dev-master

9999999-dev https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

file filesystem routing

03/01 2016

1.0.0

1.0.0.0 https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

file filesystem routing

30/11 2014

0.3.0

0.3.0.0 https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file filesystem routing

21/02 2013

0.2.1

0.2.1.0 https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file filesystem routing

21/02 2013

0.2

0.2.0.0 https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file filesystem routing

20/02 2013

0.1.2

0.1.2.0 https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file filesystem routing

19/02 2013

0.1

0.1.0.0 https://github.com/pklink/file-router

Library for mapping files in a directory to routes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file filesystem routing