Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Record_Config Class Reference

Provides consistent storage of configuration information. More...

Inheritance diagram for P4Cms_Record_Config:
P4Cms_Record P4Cms_Record_Connected P4Cms_Model P4Cms_ModelInterface P4Cms_Menu P4Cms_Widget

List of all members.

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.

Detailed Description

Provides consistent storage of configuration information.

Configuration is serialized to JSON for storage.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

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.

Parameters:
string$keyOptional key to retrieve from the config
string$defaultOptional default value if the $key value is null.
Returns:
Zend_Config the configuration object.
    {
        $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.

Returns:
array the configuration in array form.
    {
        return $this->getConfig()->toArray();
    }
P4Cms_Record_Config::save ( description = null)

Save this record.

Extends parent to convert Zend_Config to an array.

Parameters:
string$descriptionoptional - a description of the change.
Returns:
P4Cms_Record provides a fluent interface

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.

Parameters:
Zend_Config | array | null$configthe config object or null to clear.
Returns:
P4Cms_Record_Config provides fluent interface.
Exceptions:
InvalidArgumentExceptionif 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.

Parameters:
array$configthe configuration to set in array form.
Returns:
P4Cms_Record_Config provides fluent interface.
Exceptions:
InvalidArgumentExceptionif 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));
    }

Member Data Documentation

P4Cms_Record_Config::$_fields [static, protected]
Initial value:
 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.


The documentation for this class was generated from the following file: