system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CConfiguration

system.collections
继承 class CConfiguration » CMap » CComponent
实现 Countable, ArrayAccess, Traversable, IteratorAggregate
可用自 1.0
源码 framework/collections/CConfiguration.php
CConfiguration represents an array-based configuration.

It can be used to initialize an object's properties.

The configuration data may be obtained from a PHP script. For example,
return array(
    'name'=>'My Application',
    'defaultController'=>'index',
);
Use the following code to load the above configuration data:
$config=new CConfiguration('path/to/config.php');


To apply the configuration to an object, call applyTo(). Each (key,value) pair in the configuration data is applied to the object like: $object->$key=$value.

Since CConfiguration extends from CMap, it can be used like an associative array. See CMap for more details.

公共属性

隐藏继承的属性

属性类型描述被定义在
count integer Returns the number of items in the map. CMap
iterator CMapIterator Returns an iterator for traversing the items in the list. CMap
keys array the key list CMap
readOnly boolean whether this map is read-only or not. CMap

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CConfiguration
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
add() Adds an item into the map. CMap
applyTo() Applies the configuration to an object. CConfiguration
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clear() Removes all items in the map. CMap
contains() CMap
copyFrom() Copies iterable data into the map. CMap
count() Returns the number of items in the map. CMap
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getCount() Returns the number of items in the map. CMap
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getIterator() Returns an iterator for traversing the items in the list. CMap
getKeys() Returns the key list CMap
getReadOnly() Returns whether this map is read-only or not. Defaults to false. CMap
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
itemAt() Returns the item with the specified key. CMap
loadFromFile() Loads configuration data from a file and merges it with the existing configuration. CConfiguration
mergeArray() Merges two or more arrays into one recursively. CMap
mergeWith() Merges iterable data into the map. CMap
offsetExists() Returns whether there is an element at the specified offset. CMap
offsetGet() Returns the element at the specified offset. CMap
offsetSet() Sets the element at the specified offset. CMap
offsetUnset() Unsets the element at the specified offset. CMap
raiseEvent() Raises an event. CComponent
remove() Removes an item from the map by its key. CMap
saveAsString() Saves the configuration into a string. CConfiguration
toArray() CMap

受保护的方法

隐藏继承的方法

方法描述被定义在
setReadOnly() Sets whether this list is read-only or not CMap

方法详情

__construct() 方法
public void __construct(mixed $data=NULL)
$data mixed if string, it represents a config file (a PHP script returning the configuration as an array); If array, it is config data.
源码: framework/collections/CConfiguration.php#47 (显示)
public function __construct($data=null)
{
    if(
is_string($data))
        
parent::__construct(require($data));
    else
        
parent::__construct($data);
}

Constructor.

applyTo() 方法
public void applyTo(object $object)
$object object object to be applied with this configuration
源码: framework/collections/CConfiguration.php#95 (显示)
public function applyTo($object)
{
    foreach(
$this->toArray() as $key=>$value)
        
$object->$key=$value;
}

Applies the configuration to an object. Each (key,value) pair in the configuration data is applied to the object like: $object->$key=$value.

loadFromFile() 方法
public void loadFromFile(string $configFile)
$configFile string configuration file path (if using relative path, be aware of what is the current path)
源码: framework/collections/CConfiguration.php#70 (显示)
public function loadFromFile($configFile)
{
    
$data=require($configFile);
    if(
$this->getCount()>0)
        
$this->mergeWith($data);
    else
        
$this->copyFrom($data);
}

Loads configuration data from a file and merges it with the existing configuration.

A config file must be a PHP script returning a configuration array (like the following)

return array
(
    'name'=>'My Application',
    'defaultController'=>'index',
);

参见

saveAsString() 方法
public string saveAsString()
{return} string the string representation of the configuration
源码: framework/collections/CConfiguration.php#84 (显示)
public function saveAsString()
{
    return 
str_replace("\r",'',var_export($this->toArray(),true));
}

Saves the configuration into a string. The string is a valid PHP expression representing the configuration data as an array.