phpDocumentor base
[ class tree: base ] [ index: base ] [ all elements ]

Class: WindFactory

Source Location: /base/WindFactory.php

Class WindFactory

Class Overview

Implements interfaces:

工厂类

工厂类职责:加载组件配置并创建并管理组件对象作用域以及生命周期.通过组件工厂的方式创建组件对象,简化了组件的创建过程,统一了组件的管理接口并且具有很好的可扩展性. 组件配置方式

  1.  <component name='' path='' factory-method='' init-method=''
  2.  scope="application/singleton/prototype/" proxy='' destroy=''>
  3.  <property property-name='' ref/value/path=''>
  4.  <constructor-arg ref/value=''>
  5.  <config resource=''>
  6.  </component>
支持定义类对象的别名,路径,工厂方法,初始化方法,作用域,是否启动代理,析构方法,属性值,构造参数,以及配置解析等.

Located in /base/WindFactory.php [line 19]



		
				Author(s):
		
		
		
Information Tags:
Version:  $Id: WindFactory.php 3389 2012-03-12 15:44:22Z yishuo $
Copyright:  ©2003-2103 phpwind.com
License:  http://www.windframework.com

Properties

Methods

[ Top ]
Property Summary
mixed   $classDefinitions  
mixed   $destories  
mixed   $instances  
mixed   $prototype  
mixed   $proxyType  

[ Top ]
Method Summary
static void   createInstance()  
WindFactory   __construct()   初始化工厂类
void   addClassDefinitions()   动态添加组件定义
void   buildArgs()   解析组件对象构造方法参数信息,并返回参数列表
void   buildProperties()   构建类的属性信息
boolean   checkAlias()   组件定义检查
void   executeDestroyMethod()   执行组件定义的注销方法
mixed   executeInitMethod()   执行类的初始化方法
void   getInstance()  
void   loadClassDefinitions()   加载类定义
boolean   registInstance()   注册组件对象,如果已经存在则覆盖原有值
void   resolveConfig()   解析组件配置
WindClassProxy   setProxyForClass()   设置类代理对象,并返回代理类对象
boolean   setScope()   组件对象的作用域解析

[ Top ]
Properties
mixed   $classDefinitions = array() [line 21]
API Tags:
Access:  protected


[ Top ]
mixed   $destories = array() [line 24]
API Tags:
Access:  protected


[ Top ]
mixed   $instances = array() [line 22]
API Tags:
Access:  protected


[ Top ]
mixed   $prototype = array() [line 23]
API Tags:
Access:  protected


[ Top ]
mixed   $proxyType = 'WIND:factory.WindClassProxy' [line 20]
API Tags:
Access:  protected


[ Top ]
Methods
static method createInstance  [line 67]

  static void createInstance( $className, [ $args = array()]  )

Parameters:
   $className: 
   $args: 

API Tags:
Access:  public


Implementation of:
IWindFactory::createInstance()
创建并返回类对象

[ Top ]
Constructor __construct  [line 31]

  WindFactory __construct( [array $classDefinitions = array()]  )

初始化工厂类

Parameters:
array   $classDefinitions:  组件定义 默认值为空数组

API Tags:
Access:  public


[ Top ]
addClassDefinitions  [line 103]

  void addClassDefinitions( string $alias, array $classDefinition  )

动态添加组件定义

Parameters:
string   $alias: 
array   $classDefinition: 

API Tags:
Access:  public

Information Tags:
Throws:  WindException

[ Top ]
buildArgs  [line 173]

  void buildArgs( array $constructors, &$args, array $args  )

解析组件对象构造方法参数信息,并返回参数列表

该方法解析组件对象构造方法的参数信息,相关的组件配置

  1. <constructor-args>
  2.  <constructor-arg name='0' value='DATA:log' />
  3.  <constructor-arg name='1' value='2' />
  4.  </constructor-args>
相关定义同properties相同.'name'为参数位置,生成的参数列表按照'name'一次排序.

Parameters:
array   $constructors: 
array   $args: 
   &$args: 

API Tags:
Access:  protected


[ Top ]
buildProperties  [line 285]

  void buildProperties( string $properties, WindModule $instance  )

构建类的属性信息

类的属性信息对应的组件配置为

  1. <properties delay=''><property property-name='' ref/value/path='' />
  2.  </properties>
他支持的标签为'delay','property-name','ref','value','path'. 当'delay'设置为true时该属性延迟加载.'property-name'设置了属性名称.'ref','value','path'是定义属性值的三种方式,'ref'指向另外的组件定义名称, 'value'直接输入属性的值,'path'定义一个属性对象的路径,系统会自动创建该属性的对象.

Parameters:
string   $properties:  属性定义
WindModule   $instance:  类对象

API Tags:
Access:  protected


[ Top ]
checkAlias  [line 137]

  boolean checkAlias( string $alias  )

组件定义检查

检查类定义是否已经存在,或者是否已经被创建.避免重复注册组件定义

Parameters:
string   $alias: 

API Tags:
Access:  public


[ Top ]
executeDestroyMethod  [line 153]

  void executeDestroyMethod( )

执行组件定义的注销方法

调用全部组件的注销方法,按照组件的定义顺序依次调用,相关组件的定义方法

  1. <component destroy=''>...</component>
该方法在应用结束时统一被调用.


API Tags:
Access:  public

Information Tags:
Throws:  WindException

[ Top ]
executeInitMethod  [line 244]

  mixed executeInitMethod( string $initMethod, object $instance  )

执行类的初始化方法

类的初始化方法的组件定义

  1. <component init-method=''>...</component>

Parameters:
string   $initMethod: 
object   $instance: 

API Tags:
Access:  protected

Information Tags:
Throws:  WindException

[ Top ]
getInstance  [line 38]

  void getInstance( $alias, [ $args = array()]  )

Parameters:
   $alias: 
   $args: 

API Tags:
Access:  public


Implementation of:
IWindFactory::getInstance()
创建并返回类的实例对象

[ Top ]
loadClassDefinitions  [line 119]

  void loadClassDefinitions( array $classDefinitions, [boolean $merge = true]  )

加载类定义

调用该方法加载组件定义,如果merge为true,则覆盖原有配置信息.

Parameters:
array   $classDefinitions: 
boolean   $merge:  是否进行merge操作,默认为true

API Tags:
Access:  public


[ Top ]
registInstance  [line 90]

  boolean registInstance( object $instance, string $alias, [string $scope = 'singleton']  )

注册组件对象,如果已经存在则覆盖原有值

Parameters:
object   $instance: 
string   $alias: 
string   $scope:  对象作用域 默认为'singleton'

API Tags:
Access:  public


[ Top ]
resolveConfig  [line 226]

  void resolveConfig( array|string $config, string $alias, WindModule $instance  )

解析组件配置

解析组件配置并将配置信息设置进组件,默认调用windCache组件对进行配置缓存处理,可以通过配置'isCache'开启或关闭系统缓存. 组件配置定义

  1. <component ...><config resource=''>...</config></component>
, 可以通过配置'resource'引入外部配置(支持命名空间方式定义路径地址),也可以直接将配置定义到config标签下.

Parameters:
array|string   $config: 
string   $alias: 
WindModule   $instance: 

API Tags:
Access:  protected


[ Top ]
setProxyForClass  [line 264]

  WindClassProxy setProxyForClass( string $proxy, WindModule $instance  )

设置类代理对象,并返回代理类对象

代理类同当前类拥有同样的职责和功能,可以通过访问代理类对象访问当前类. 类的代理信息对应的组件配置为

  1. <component proxy=''>...</component>
当'proxy'设置为false时返回该类的代理类型, 类默认的代理类型为WindClassProxy,不可以通过配置进行修改.

Parameters:
string   $proxy: 
WindModule   $instance: 

API Tags:
Access:  protected


[ Top ]
setScope  [line 198]

  boolean setScope( string $alias, string $scope, WindModule $instance  )

组件对象的作用域解析

组件对象的作用域解析,目前支持的属性作用于为'prototype','application','singleton',默认为'application'. 相关组件定义方式

  1. <component scope=''>...</component>

Parameters:
string   $alias: 
string   $scope: 
WindModule   $instance: 

API Tags:
Access:  protected


[ Top ]

Documentation generated on Fri, 30 Mar 2012 11:43:32 +0800 by phpDocumentor 1.4.4