vonalbert/silext

Silex 框架的扩展

dev-master 2015-11-20 08:04 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:53:41 UTC


README

SilEXT 是 silex 微框架的扩展库。

安装

只需将 vonalbert/silext 添加到您的 composer.json 并注册所需的服务提供者

功能

模块化

要启用模块功能,您只需注册 Vonalbert\Silext\Provider\ModularityServiceProvider 服务提供者并使用 modules 服务来注册模块对象

$app->register(new \Vonalbert\Silext\Provider\ModulesServiceProvider);
$app['modules']->add(new ModuleA);
$app['modules']->addModules([
    new ModuleB('/route-prefix-b'),
    new ModuleB('/route-prefix-c'),
    // ...
]);

一个类要被识别为模块,必须扩展 Vonalbert\Silext\Module 抽象类,并实现抽象方法 setRoutesbootstrap

abstract protected function setRoutes(ControllerCollection $router);
abstract protected function bootstrap(Application $app);

setRoutes 在注册时被调用,并接受一个 Silex\ControllerCollection,允许注册路由。

bootstrap 在模块引导时被调用。一个模块只有在它的一个路由与当前请求匹配时才会被引导。