承接 meta-tech/silex-controller-service 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

meta-tech/silex-controller-service

Composer 安装命令:

composer require meta-tech/silex-controller-service

包简介

Controller service provider for Silex2.

README 文档

README

A service provider for Silex for managing DI and mounting on controllers.

Requirements

PHP 7.0

Install

The package can be installed using Composer .

composer require meta-tech/silex-controller-service

Or add the package to your composer.json.

"require": {
    "meta-tech/silex-controller-service" : "~1.0"
}

Usage

The provider will create a service relative to a Controller instance builded with its dependencies.
If the controller implements the Silex\Api\ControllerProviderInterface the provider will also mount the controller 's routes to the defined routing entry point

Example

Admit you have a controller Test with dependencies on instanciation :

class Test implements ControllerProviderInterface
{
    public function __construct(Application $app, string $foo)
    {
        // do stuff
    }

You can use the ControllerServiceProvider to create a service to manage your controller class instanciation :

use MetaTech\Silex\Provider\ControllerServiceProvider;
use Acme\Ctrl\Test;
...

$app->register(new ControllerServiceProvider(Test::class, [$app, 'foo'], '/test', 'ctrl.'));

first parameter is your controller class
second parameter is an array of your controller dependencies (default [])
third parameter define your controller routing entry point (default null : disabling mounting controller's routes)
fourth parameter define your service 's namespace to access your controller (default 'ctrl.')

The name of the registering service is the given namespace followed by your controller class shortname

With the previous example $app['ctrl.Test'] is now available and return your controller instance.

the connect method of your controller can now benefits of this service to define appropriate routes, like that :

class Test implements ControllerProviderInterface
{
    ...

    public function connect(Application $app)
    {
        $collection = $app['controllers_factory'];
        $_          = 'ctrl.Test';

        $collection->match('/'    , "$_:index");
        $collection->match('/test', "$_:test");

        return $collection;
    }
}

Controller 's routes are mount on the defined routing entry point (third parameter);

see source code of MetaTech\Silex\Ws\Controller in meta-tech\silex-core for an advance controller architecture.

License

The project is released under the MIT license, see the LICENSE file.

统计信息

  • 总下载量: 76
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固