fudge/silex-container-aware
Composer 安装命令:
composer require fudge/silex-container-aware
包简介
Provides Symfony2 Container Aware controllers within Silex
README 文档
README
Provides Symfony2 Container Aware controllers within Silex.
This may seem redudant as you are given the Application instance per method call, but this allows you to keep your code DRY as reusable methods can be implemented involving external services, such as redirects and rendering.
Rest assured that this package is covered 100% by Unit Tests, and does follow Semantic Versioning (unlike others!).
Examples below.
Requirements
- PHP 5.4+
- Silex ~1 (Obviously!)
Examples
This is a very naive example, showing the accessibility of the Container within a ContainerAware Controller
Silex - index.php
<?php require __DIR__.'/vendor/autoload.php'; use Silex\Application; use Silex\Provider\ServiceControllerServiceProvider; use Fudge\SilexComponents\ContainerAware\ContainerAwareServiceProvider; $app = new Application; $app->register(new ContainerAwareServiceProvider); $app->register(new ServiceControllerServiceProvider); $app->get("/", "IndexController::hello");
IndexController.php
<?php class IndexController extends \Fudge\SilexComponents\ContainerAware\Controller { public function hello() { return $this->render("foo.html.twig"); } protected function render($templateName) { return $this->get("twig")->render($templateName); } protected function get($service) { return $this->getContainer()[$service]; } }
Roadmap
- Implement more features to the ContainerAware Controller
- Potentially extend the functionality of the Silex\Application to allow automatic dependency injection, similar to Laravel
统计信息
- 总下载量: 154
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-18