n0wada / chert
这是一个使用注解和缓存的简单路由库。
1.1
2017-04-01 09:07 UTC
Requires
- doctrine/annotations: ~1.0
- doctrine/cache: ~1.0
- symfony/finder: ~2.8|^3.0
Requires (Dev)
- silex/silex: ~2.0
- symfony/browser-kit: ~2.8|^3.0
This package is not auto-updated.
Last update: 2024-09-28 20:20:08 UTC
README
它是Silex应用的ControllerProvider的替代方案,使用注解和缓存。Chert受到Orlex的启发
安装
Chert使用Composer进行安装
"require": {
"n0wada/chert": "dev-master"
}
参数
chert.cache_dir
缓存目录。此库将RouteCollection对象保存到此处。
如果您使用FilesystemCache(默认),则需要此参数。
chert.cache_lifetime
此缓存条目的生命周期(以秒为单位)。默认生命周期为0。
chert.controller_dirs
它是一个命名空间和目录的数组对。
chert.cache
如果您想使用ApcCache、MemCached、Redis等,您可以将缓存对象设置在此处。
您需要实现Doctrine\Common\Cache\Cache接口。
用法
在您的Silex应用程序中注册Provider。
$app = new \Silex\Application(); $app->register(new \Chert\RouteCompileServiceProvider(),[ 'chert.cache_dir' => __DIR__ . '/cache, 'chert.controller_dirs' => ['Controller' => __DIR__ . '/controllers] ]); $app->run();
在您的控制器中设置路由。
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); } }