Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Record_DeferredAdapter Class Reference

A mechanism for providing an adapter that will be loaded on-demand. More...

Inheritance diagram for P4Cms_Record_DeferredAdapter:
P4Cms_Record_Adapter

List of all members.

Public Member Functions

 __construct ($callback)
 Create a new deferred adapter from the given callback.
 beginBatch ($description)
 Start a batch.
 commitBatch ($description=null, $options=null)
 Commit the batch.
 getAdapter ()
 Resolves the callback to a real adapter.
 getBasePath ()
 Get the base path in Perforce under which records should be read from and written to.
 getBatchId ()
 Get the id of the current batch.
 getConnection ()
 Override every method in the base class to call through to the real adapter.
 getProperties ()
 Get all properties of this adapter.
 getProperty ($name)
 Get a particular property value of this adapter.
 hasProperty ($name)
 Check if adapter has a particular property.
 inBatch ()
 Determine if we are currently in a batch on this storage adapter.
 revertBatch ()
 Reverts all files in the pending change corresponding to the batch id.
 setBasePath ($path)
 Set the base path in Perforce under which records should be read from and written to.
 setBatchDescription ($description)
 Change the description of the current batch.
 setCallback ($callback)
 Set the callback to use to get the real adapter to use.
 setConnection ($p4)
 Set the Perforce connection to use to communicate with the Perforce backend.
 setProperties (array $properties)
 Set adapter properties.
 setProperty ($name, $value)
 Set a particular property of this adapter.

Protected Attributes

 $_callback = null

Detailed Description

A mechanism for providing an adapter that will be loaded on-demand.

This is particularly useful if creating the adapter will have notable expense you wish to avoid, or if you expect the adapter may change.

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_DeferredAdapter::__construct ( callback)

Create a new deferred adapter from the given callback.

A callback must be provided.

Parameters:
callable$callbackthe callback function to get the real adapter.
Exceptions:
InvalidArgumentExceptionif the given callback is not callable.
    {
        $this->setCallback($callback);
    }

Member Function Documentation

P4Cms_Record_DeferredAdapter::beginBatch ( description)

Start a batch.

Changes made to records will be placed in a numbered pending change and will not be submitted until the batch is committed.

Batches cannot be nested. Attempting to begin a batch while in a batch will result in an exception.

Parameters:
string$descriptionrequired - a description of the batch.
Returns:
P4Cms_Record_Adapter provides fluent interface.
Exceptions:
P4Cms_Record_Exceptionif already in a batch.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->beginBatch($description); }
P4Cms_Record_DeferredAdapter::commitBatch ( description = null,
options = null 
)

Commit the batch.

Submits the pending change corresponding to the batch id.

Parameters:
string$descriptionoptional - a final description of the batch.
null | string | array$optionsoptional - passing the SAVE_THROW_CONFLICTS flag will cause exceptions on conflict; default behaviour is to crush any conflicts.
Returns:
P4Cms_Record_Adapter provides fluent interface.
Exceptions:
P4Cms_Record_Exceptionif not in a batch.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->commitBatch($description, $options); }
P4Cms_Record_DeferredAdapter::getAdapter ( )

Resolves the callback to a real adapter.

Returns:
P4Cms_Record_Adapter the real adapter to use.
Exceptions:
P4Cms_Record_Exceptionif callback fails to return a proper adapter.
    {
        $adapter = call_user_func($this->_callback);

        if (!$adapter instanceof P4Cms_Record_Adapter) {
            throw new P4Cms_Record_Exception(
                "Cannot resolve deferred adapter. Callback failed to return a proper adapter."
            );
        }

        return $adapter;
    }
P4Cms_Record_DeferredAdapter::getBasePath ( )

Get the base path in Perforce under which records should be read from and written to.

Returns:
string the record storage base path.
Exceptions:
P4Cms_Record_Exceptionif no base path is set.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->getBasePath(); }
P4Cms_Record_DeferredAdapter::getBatchId ( )

Get the id of the current batch.

The batch id corresponds to a pending changelist in Perforce.

Returns:
int the batch id (pending change number).
Exceptions:
P4Cms_Record_Exceptionif not in a batch.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->getBatchId(); }
P4Cms_Record_DeferredAdapter::getConnection ( )

Override every method in the base class to call through to the real adapter.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->getConnection(); }
P4Cms_Record_DeferredAdapter::getProperties ( )

Get all properties of this adapter.

Returns:
array all properties set to this adapter

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->getProperties(); }
P4Cms_Record_DeferredAdapter::getProperty ( name)

Get a particular property value of this adapter.

Parameters:
string$namename of the property to get the value of
Returns:
mixed the value of the property name
Exceptions:
P4Cms_Record_Exceptionif the property name does not exist

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->getProperty($name); }
P4Cms_Record_DeferredAdapter::hasProperty ( name)

Check if adapter has a particular property.

Parameters:
string$namethe property name to check for the existence of
Returns:
boolean true if the adapter has the named property, false otherwise.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->hasProperty($name); }
P4Cms_Record_DeferredAdapter::inBatch ( )

Determine if we are currently in a batch on this storage adapter.

Returns:
bool true if we are in a batch.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->inBatch(); }
P4Cms_Record_DeferredAdapter::revertBatch ( )

Reverts all files in the pending change corresponding to the batch id.

Returns:
P4Cms_Record_Adapter provides fluent interface.
Exceptions:
P4Cms_Record_Exceptionif not in a batch.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->revertBatch(); }
P4Cms_Record_DeferredAdapter::setBasePath ( path)

Set the base path in Perforce under which records should be read from and written to.

Parameters:
string$paththe record storage base path.
Returns:
P4Cms_Record_Adapter provides fluent interface.
Exceptions:
P4Cms_Record_Exceptionif the base path is not a valid string.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->setBasePath($path); }
P4Cms_Record_DeferredAdapter::setBatchDescription ( description)

Change the description of the current batch.

Parameters:
string$descriptionthe description of the current batch.
Returns:
P4Cms_Record_Adapter provides fluent interface.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->setBatchDescription($description); }
P4Cms_Record_DeferredAdapter::setCallback ( callback)

Set the callback to use to get the real adapter to use.

Parameters:
callable$callbackthe callback function to get the real adapter. the callback will be called with no arguments and must return an adapter instance
Returns:
P4Cms_Record_DeferredAdapter provides fluent interface.
Exceptions:
InvalidArgumentExceptionif the given callback is not callable.
    {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException(
                "Cannot set callback. Given callback is not callable."
            );
        }

        $this->_callback = $callback;

        return $this;
    }
P4Cms_Record_DeferredAdapter::setConnection ( p4)

Set the Perforce connection to use to communicate with the Perforce backend.

Parameters:
P4_Connection_Abstract$p4the p4 connection to use.
Returns:
P4Cms_Record_Adapter provides fluent interface.
Exceptions:
P4Cms_Record_Exceptionif the connection object is invalid.

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->setConnection($p4); }
P4Cms_Record_DeferredAdapter::setProperties ( array $  properties)

Set adapter properties.

Parameters:
array$propertiesarray with properties to set
Returns:
P4Cms_Record_Adapter provides fluent interface

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->setProperties($properties); }
P4Cms_Record_DeferredAdapter::setProperty ( name,
value 
)

Set a particular property of this adapter.

Parameters:
string$namename of the property to set the value of
mixed$valuevalue to set
Returns:
P4Cms_Record_Adapter provides a fluent interface

Reimplemented from P4Cms_Record_Adapter.

{ return $this->getAdapter()->setProperty($name, $value); }

Member Data Documentation

P4Cms_Record_DeferredAdapter::$_callback = null [protected]

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