fudge/silex-container-aware 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固