n0wada/chert

It is a simple routing library using annotations and caching.

1.1 2017-04-01 09:07 UTC

This package is not auto-updated.

Last update: 2024-04-27 18:04:25 UTC


README

It's an alternative to ControllerProvider for Silex application, using annotations and caching. Chert is inspired by Orlex

Install

Chert uses Composer to install:

  "require": {
      "n0wada/chert": "dev-master"
  }

Parameters

chert.cache_dir

The cache directory. This library save RouteCollection Object there.
If you use FilesystemCache(default), This Parameter is required.

chert.cache_lifetime

The lifetime in number of seconds for this cache entry. default lifetime is 0.

chert.controller_dirs

It is an array of pairs of namespace and directory.

chert.cache

If you want to use ApcCache, MemCached, Redis etc., you can set Cache Object here.
You need to implements Doctrine\Common\Cache\Cache Interface.

Usage

Resister Provider in your Silex application.

$app = new \Silex\Application();
 
$app->register(new \Chert\RouteCompileServiceProvider(),[
    'chert.cache_dir' => __DIR__ . '/cache,
    'chert.controller_dirs' => ['Controller' => __DIR__ . '/controllers]
]);
 
$app->run();

Set up Routing in your Controller.

namespace Test\Controller;
 
use Chert\Annotation\Route;
use Chert\Annotation\Value;
use Symfony\Component\HttpFoundation\JsonResponse;
 
/**
 * @Route(path="/test")
 */
class TestController
{
    /**
     * @Route(path="/index/{id}",methods={"GET"}, name="test.index")
     * @Value(variable="id",default="1")
     */
    function index($id)
    {
        return new JsonResponse($id);
    }
}

License

MIT