Perforce Chronicle 2012.2/486814
API Documentation

P4_ConnectedAbstract Class Reference

Base class for all Perforce models. More...

Inheritance diagram for P4_ConnectedAbstract:
P4_ConnectedInterface P4_Counter P4_ModelAbstract P4_Spec_Definition P4_File P4_SpecAbstract P4_Protections P4_Spec_PluralAbstract P4_Triggers P4_Typemap P4_Branch P4_Change P4_Client P4_Depot P4_Group P4_Job P4_Label P4_Stream P4_User

List of all members.

Public Member Functions

 __construct (P4_Connection_Interface $connection=null)
 Instantiate the model and set the connection to use.
 __sleep ()
 We need a custom sleep to exclude the connection property.
 clearConnection ()
 Clear this model's connection.
 getConnection ()
 Get the Perforce connection used by this model.
 hasConnection ()
 Determine if this model has a connection to Perforce.
 setConnection (P4_Connection_Interface $connection)
 Set the Perforce connection to use when issuing Perforce commands for this instance.

Static Public Member Functions

static getDefaultConnection ()
 Get the default Perforce connection to use.

Protected Attributes

 $_connection = null

Detailed Description

Base class for all Perforce models.

Provides get/set Perforce connection capabilities. This allows a specific perforce connection to be set on a per-object basis.

To set the perforce connection to use for a particular instance, pass a connection to the constructor or call setConnection() on the object if it already exists.

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

P4_ConnectedAbstract::__construct ( P4_Connection_Interface connection = null)

Instantiate the model and set the connection to use.

Parameters:
P4_Connection_Interface$connectionoptional - a connection to use for this instance.

Implements P4_ConnectedInterface.

    {
        if ($connection) {
            $this->setConnection($connection);
        } else if (P4_Connection::hasDefaultConnection()) {
            $this->setConnection(P4_Connection::getDefaultConnection());
        }
    }

Member Function Documentation

P4_ConnectedAbstract::__sleep ( )

We need a custom sleep to exclude the connection property.

Connection objects cannot be serialized.

Returns:
array list of properties to serialize
    {
        return array_diff(
            array_keys(get_object_vars($this)),
            array('_connection')
        );
    }
P4_ConnectedAbstract::clearConnection ( )

Clear this model's connection.

This is primarily for testing purposes.

Implements P4_ConnectedInterface.

    {
        $this->_connection = null;
    }
P4_ConnectedAbstract::getConnection ( )

Get the Perforce connection used by this model.

Returns:
P4_Connection_Interface the connection instance used by this model.

Implements P4_ConnectedInterface.

    {
        if ($this->_connection instanceof P4_Connection_Interface) {
            return $this->_connection;
        }

        throw new P4_Exception("Cannot get connection. No connection is set.");
    }
static P4_ConnectedAbstract::getDefaultConnection ( ) [static]

Get the default Perforce connection to use.

Returns:
P4_Connection_Interface the default connection.

Implements P4_ConnectedInterface.

P4_ConnectedAbstract::hasConnection ( )

Determine if this model has a connection to Perforce.

Returns:
bool true if the model has a connection to Perforce.

Implements P4_ConnectedInterface.

    {
        try {
            $this->getConnection();
            return true;
        } catch (P4_Exception $e) {
            return false;
        }
    }
P4_ConnectedAbstract::setConnection ( P4_Connection_Interface connection)

Set the Perforce connection to use when issuing Perforce commands for this instance.

Parameters:
P4_Connection_Interface$connectionthe connection to use for this instance.
Returns:
P4_ModelAbstract provides fluent interface.

Implements P4_ConnectedInterface.

    {
        $this->_connection = $connection;

        return $this;
    }

Member Data Documentation

P4_ConnectedAbstract::$_connection = null [protected]

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