CConfiguration
包 | system.collections |
---|---|
继承 | class CConfiguration » CMap » CComponent |
实现 | Countable, ArrayAccess, Traversable, IteratorAggregate |
可用自 | 1.0 |
版本 | $Id$ |
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,
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.
It can be used to initialize an object's properties.
The configuration data may be obtained from a PHP script. For example,
<?php 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 | 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 |
createObject() | Creates an object and initializes it based on the given configuration. | CConfiguration |
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 |
getCount() | 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() | CMap | |
getReadOnly() | 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 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 |
方法详情
__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. |
Constructor.
applyTo()
方法
public void applyTo(object $object)
| ||
$object | object | object to be applied with this configuration |
Applies the configuration to an object. Each (key,value) pair in the configuration data is applied to the object like: $object->$key=$value.
createObject()
方法
public static mixed createObject(mixed $config)
| ||
$config | mixed | the configuration. It can be either a string or an array. |
{return} | mixed | the created object |
Creates an object and initializes it based on the given configuration.
NOTE: this method has been deprecated since version 1.0.1.
Please use Yii::createComponent, instead.
loadFromFile()
方法
public void loadFromFile(string $configFile)
| ||
$configFile | string | configuration file path (if using relative path, be aware of what is the current path) |
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 |
Saves the configuration into a string. The string is a valid PHP expression representing the configuration data as an array.