Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Record_Connected Class Reference

Extends P4Cms_Model class and provides in-memory storage of a record adapter and records default adapter. More...

Inheritance diagram for P4Cms_Record_Connected:
P4Cms_Model P4Cms_ModelInterface P4Cms_Acl_Role P4Cms_Record P4Cms_Record_Volatile P4Cms_User Comment_Model_Comment Cron_Model_Cron P4Cms_Categorization_CategoryAbstract P4Cms_Content_Type P4Cms_Record_Config P4Cms_Record_PubSubRecord Url_Model_Url Workflow_Model_Workflow P4Cms_Content_Opened Cron_Model_User

List of all members.

Public Member Functions

 __construct ($values=null, P4Cms_Record_Adapter $adapter=null)
 Create a new model instance and (optionally) set the field values.
 __sleep ()
 We need a custom sleep to exclude the adapter property.
 clearAdapter ()
 Clear this record's storage adapter.
 getAdapter ()
 Get the storage adapter used by this instance when accessing records.
 hasAdapter ()
 Determine if a record adapter has been set.
 setAdapter (P4Cms_Record_Adapter $adapter)
 Set the storage adapter to use when accessing records.

Static Public Member Functions

static clearDefaultAdapter ()
 Clear the default record storage adapter.
static getDefaultAdapter ()
 Get the default storage adapter to use when accessing records.
static hasDefaultAdapter ()
 Determine if a default storage adapter has been set.
static setDefaultAdapter (P4Cms_Record_Adapter $adapter)
 Set the default storage adapter to use when accessing records.

Protected Attributes

 $_adapter = null

Static Protected Attributes

static $_defaultAdapter = null

Detailed Description

Extends P4Cms_Model class and provides in-memory storage of a record adapter and records default adapter.

It only provides methods to retrieve, store, check-for and clear a record adapter and/or records default adapter; it doesn't provide any functionality for permanent storage of P4Cms_Model objects.

Constructor will set an adapter for the new instance if the caller provides one or there is a default record adapter available.

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

Constructor & Destructor Documentation

P4Cms_Record_Connected::__construct ( values = null,
P4Cms_Record_Adapter adapter = null 
)

Create a new model instance and (optionally) set the field values.

Extends parent to set the default adapter in the instance.

Parameters:
array$valuesarray of key/values to load into the model.
P4Cms_Record_Adapter$adapteroptional - storage adapter to use.
    {
        // if no adapter given, use the default adapter.
        if (!$adapter && static::hasDefaultAdapter()) {
            $adapter = static::getDefaultAdapter();
        }

        // set the adapter if we have one.
        if ($adapter) {
            $this->setAdapter($adapter);
        }

        parent::__construct($values);
    }

Member Function Documentation

P4Cms_Record_Connected::__sleep ( )

We need a custom sleep to exclude the adapter property.

Adapter connection objects cannot be serialized.

Returns:
array list of properties to serialize
    {
        return array_diff(
            array_keys(get_object_vars($this)),
            array('_adapter')
        );
    }
P4Cms_Record_Connected::clearAdapter ( )

Clear this record's storage adapter.

This is primarily for testing purposes.

    {
        $this->_adapter = null;
    }
static P4Cms_Record_Connected::clearDefaultAdapter ( ) [static]

Clear the default record storage adapter.

This is primarily for testing purposes.

    {
        static::$_defaultAdapter = null;
    }
P4Cms_Record_Connected::getAdapter ( )

Get the storage adapter used by this instance when accessing records.

Returns:
P4Cms_Record_Adapter the adapter used by this instance.
Exceptions:
P4Cms_Record_Exceptionif the adapter was not set.
    {
        if ($this->_adapter instanceof P4Cms_Record_Adapter) {
            return $this->_adapter;
        }

        throw new P4Cms_Record_Exception(
            "Cannot get storage adapter. Adapter has not been set."
        );
    }
static P4Cms_Record_Connected::getDefaultAdapter ( ) [static]

Get the default storage adapter to use when accessing records.

Returns:
P4Cms_Record_Adapter the default storage adapter.
    {
        if (static::$_defaultAdapter instanceof P4Cms_Record_Adapter) {
            return static::$_defaultAdapter;
        }

        throw new P4Cms_Record_Exception(
            "Cannot get default storage adapter. Adapter has not been set."
        );
    }
P4Cms_Record_Connected::hasAdapter ( )

Determine if a record adapter has been set.

Returns:
bool true if a record adapter has been set, false otherwise.
    {
        try {
            $this->getAdapter();
            return true;
        } catch (P4Cms_Record_Exception $e) {
            return false;
        }
    }
static P4Cms_Record_Connected::hasDefaultAdapter ( ) [static]

Determine if a default storage adapter has been set.

Returns:
bool true if a default storage adapter has been set.
    {
        try {
            static::getDefaultAdapter();
            return true;
        } catch (P4Cms_Record_Exception $e) {
            return false;
        }
    }
P4Cms_Record_Connected::setAdapter ( P4Cms_Record_Adapter adapter)

Set the storage adapter to use when accessing records.

Parameters:
P4Cms_Record_Adapter$adapterthe adapter to use for this instance.
Returns:
P4Cms_Record_Connected provides fluent interface.

Reimplemented in P4Cms_Record, and P4Cms_User.

    {
        $this->_adapter = $adapter;

        return $this;
    }
static P4Cms_Record_Connected::setDefaultAdapter ( P4Cms_Record_Adapter adapter) [static]

Set the default storage adapter to use when accessing records.

Parameters:
P4Cms_Record_Adapter$adapterthe adapter to use by default.
    {
        static::$_defaultAdapter = $adapter;
    }

Member Data Documentation

P4Cms_Record_Connected::$_adapter = null [protected]
P4Cms_Record_Connected::$_defaultAdapter = null [static, protected]

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