Perforce Chronicle 2012.2/486814
API Documentation
|
Provides consistent storage of configuration information. More...
Public Member Functions | |
getConfig ($key=null, $default=null) | |
Get the configuration object for this record. | |
getConfigAsArray () | |
Get the configuration object as an array. | |
save ($description=null) | |
Save this record. | |
setConfig ($config) | |
Set the configuration object for this record. | |
setConfigFromArray ($config) | |
Set the configuration from an array. | |
Static Protected Attributes | |
static | $_fields |
Specifies the array of fields that the current Record class wishes to use. | |
static | $_fileContentField = 'config' |
Specifies the name of the record field which will be persisted in the file used to store the records. |
Provides consistent storage of configuration information.
Configuration is serialized to JSON for storage.
P4Cms_Record_Config::getConfig | ( | $ | key = null , |
$ | default = null |
||
) |
Get the configuration object for this record.
This returns a Zend_Config object which can contain any configuration information the user of the record chooses to store.
string | $key | Optional key to retrieve from the config |
string | $default | Optional default value if the $key value is null. |
{ $config = $this->_getValue('config'); // convert config to zend_config if necessary. if (!$config instanceof Zend_Config) { $config = is_array($config) ? $config : array(); $config = new Zend_Config($config, true); $this->_setValue('config', $config); } // if user requests a specific config option, return it. if (isset($key)) { return $config->get($key) ? $config->get($key) : $default; } return $config; }
P4Cms_Record_Config::getConfigAsArray | ( | ) |
Get the configuration object as an array.
{ return $this->getConfig()->toArray(); }
P4Cms_Record_Config::save | ( | $ | description = null | ) |
Save this record.
Extends parent to convert Zend_Config to an array.
string | $description | optional - a description of the change. |
Reimplemented in P4Cms_Menu, and P4Cms_Widget.
{ // ensure config is in array form. $config = $this->_getValue('config'); if ($config instanceof Zend_Config) { $this->_setValue('config', $config->toArray()); } // let parent do the rest. parent::save($description); return $this; }
P4Cms_Record_Config::setConfig | ( | $ | config | ) |
Set the configuration object for this record.
This does not save the configuration. You must call save() to store the configuration persistently.
Zend_Config | array | null | $config | the config object or null to clear. |
InvalidArgumentException | if the config object is invalid. |
{ if (is_array($config)) { $config = new Zend_Config($config); } if (!$config instanceof Zend_Config && $config !== null) { throw new InvalidArgumentException( "Cannot set configuration. Configuration is not a valid Zend_Config object." ); } $this->_setValue('config', $config); return $this; }
P4Cms_Record_Config::setConfigFromArray | ( | $ | config | ) |
Set the configuration from an array.
array | $config | the configuration to set in array form. |
InvalidArgumentException | if the config argument is not an array. |
{ if (!is_array($config)) { throw new InvalidArgumentException( "Cannot set configuration. Configuration is not an array." ); } return $this->setConfig(new Zend_Config($config)); }
P4Cms_Record_Config::$_fields [static, protected] |
array( 'config' => array( 'accessor' => 'getConfig', 'mutator' => 'setConfig' ) )
Specifies the array of fields that the current Record class wishes to use.
The implementing class MUST set this property.
Reimplemented from P4Cms_Record.
Reimplemented in P4Cms_Menu, and P4Cms_Widget.
P4Cms_Record_Config::$_fileContentField = 'config' [static, protected] |
Specifies the name of the record field which will be persisted in the file used to store the records.
If desired, the implementing class needs to set this property to match an entry defined in the $_fields array. If left null, all fields will persist as file attributes.
Reimplemented from P4Cms_Record.