承接 thapp/iocconf 相关项目开发

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

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

thapp/iocconf

Composer 安装命令:

composer require thapp/iocconf

包简介

ioc container configuration using xml

README 文档

README

Build Status

Synopsis

IoCConf provides a convenient way to handle dependecy injection using xml. E.g. it is possible to setup your controllers with either contructor or setter injection.

Installation

IocConf requires XmlConf to work.

Add thapp/iocconf ans thapp/xmlconf as a requirement to composer.json:

{
    "require": {
        "thapp/iocconf": "1.0.*",
        "thapp/xmlconf": "1.0.*"
    }
}

Then run composer update or composer install

Next step is to tell laravel to load the serviceprovider. In app/config/app.php add

  // ...
  'Thapp\IocConf\IocConfServiceProvider' 
  // ...

to the providers array.

Make sure XmlConf is installed properly, then tell XmlConf where to find the ioc configuration (app/config/packages/thapp/xmlconf/config.php)

return array(

    /*
    |--------------------------------------------------------------------------
    | Basedir relative to the install directory
    |--------------------------------------------------------------------------
     */
    'basedir' => array(
        'ioc'      => 'vendor/thapp/iocconf/src/Thapp/IocConf'
    ),

    /*
    |--------------------------------------------------------------------------
    | Reader dictionary
    |--------------------------------------------------------------------------
     */
    'namespaces' => array(
        'ioc'      => 'Thapp\\IocConf'
    ),
);

Example

Given you want to inject Laravel's view Object into a controller, the xml configuration would look something like this:

<?php

namespace Acme;

use \BaseController;

class FrontController extends BaseController
{

    // ... setter method on your controller
    public function setView(\Illuminate\View\Environment $view)
    {
        $this->view = $view;
    }

}   

The config xml would look like this

<container xmlns="http://getsymphony.com/schema/ioc">

  <entities>
    <entity class="Acme\FrontController" scope="prototype"/>
        <!-- the controller has a setter method for setting the view object -->
        <call method="setView">
    		<argument id="view"/>
    	</call>
    </entity>
  </entities>

</container>    

Usage

xml

Note: An entity node can have an id attribute but must have a class and a scope attribute, An agument node must either have an id or class attribute.

Possible entity scopes:

- prototype // see Container::bind();
- singleton // see Container::singleton();
- shared    // see Container::share();

<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://getsymphony.com/schema/ioc">

  <entities>

    <entity id="acme.frontcontroller" class="FrontController" scope="prototype"/>
    
    <entity id="acme.admincontroller" class="AdminController" scope="prototype">
    	<call method="setView">
    		<argument id="view"/>
    	</call>
    </entity>

    <entity class="ControllerRepository" scope="singleton">
      <argument id="acme.frontcontroller"/>
      <argument id="acme.admincontroller"/>
    </entity>

  </entities>

</container>    

php

$repo = App::make('ControllerRepository');

$repo2 = App::make('ControllerRepository');

$repo === $repo2 // true

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-04-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固