Perforce Chronicle 2012.2/486814
API Documentation

P4_Connection Class Reference

Perforce connection factory. More...

List of all members.

Static Public Member Functions

static clearDefaultConnection ()
 Unset the default connection.
static factory ($port=null, $user=null, $client=null, $password=null, $ticket=null, $type=null)
 Factory method that creates and returns a single instance of a Perforce Connection implementation.
static getAppName ()
 Get the application name that will be set on any new connections.
static getConnectionIdentity ()
 Get the identity of the current default Connection implementation.
static getDefaultConnection ()
 Get the default connection for the environment.
static hasDefaultConnection ()
 Check if a default connection has been set.
static isValidType ($type)
 Determine if the given Connection type is valid.
static setAppName ($name)
 Provide a application name to set on any new connections.
static setDefaultConnection (P4_Connection_Interface $connection)
 Set a default connection for the environment.

Static Protected Attributes

static $_appName
static $_defaultConnection

Detailed Description

Perforce connection factory.

A Factory used to create a Perforce Connection instance. This class is responsible for deciding the specific implementation to use.

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

static P4_Connection::clearDefaultConnection ( ) [static]

Unset the default connection.

    {
        self::$_defaultConnection = null;
    }
static P4_Connection::factory ( port = null,
user = null,
client = null,
password = null,
ticket = null,
type = null 
) [static]

Factory method that creates and returns a single instance of a Perforce Connection implementation.

The caller should not need to worry about the specific implemenation used, only that it implements P4_Connection_Interface.

Parameters:
string$portoptional - the port to connect to.
string$useroptional - the user to connect as.
string$clientoptional - the client spec to use.
string$passwordoptional - the password to use.
string$ticketoptional - a ticket to use.
string$typeoptional - a specific client implementation to use.
Returns:
P4_Connection_Interface a perforce client implementation.
Exceptions:
P4_Exceptionif an invalid API type is given.
    {
        // use the type parameter if it was provided.
        // throw an exception if it specifies an invalid type.
        if ($type) {
            if (!self::isValidType($type)) {
                throw new P4_Exception("Invalid Perforce Connection Type: " . $type);
            }
        } else {
            if (extension_loaded("perforce")) {
                $type = "P4_Connection_Extension";
            } else {
                $type = "P4_Connection_CommandLine";
            }
        }

        // create instance of desired type.
        $connection = new $type(
            $port,
            $user,
            $client,
            $password,
            $ticket
        );

        // if we have an app name, set it.
        if (static::$_appName) {
            $connection->setAppName(static::$_appName);
        }

        // if no default connection has been set, use this one.
        if (!self::hasDefaultConnection()) {
            self::setDefaultConnection($connection);
        }

        return $connection;
    }
static P4_Connection::getAppName ( ) [static]

Get the application name that will be set on any new connections.

Returns:
string|null app name to be set on new connections.
    {
        return static::$_appName;
    }
static P4_Connection::getConnectionIdentity ( ) [static]

Get the identity of the current default Connection implementation.

Returns:
array an array of client Connection information containing the name, platform, version, build and date of the client library.
    {
        $p4 = self::factory();
        return $p4->getConnectionIdentity();
    }
static P4_Connection::getDefaultConnection ( ) [static]

Get the default connection for the environment.

Returns:
P4_Connection_Interface the default connection.
Exceptions:
P4_Exceptionif no default connection has been set.
    {
        if (!self::$_defaultConnection instanceof P4_Connection_Interface) {
            throw new P4_Exception(
                "Failed to get connection. A default connection has not been set.");
        }

        return self::$_defaultConnection;
    }
static P4_Connection::hasDefaultConnection ( ) [static]

Check if a default connection has been set.

Returns:
bool true if a default connection is set.
    {
        try {
            self::getDefaultConnection();
            return true;
        } catch (P4_Exception $e) {
            return false;
        }
    }
static P4_Connection::isValidType ( type) [static]

Determine if the given Connection type is valid.

Parameters:
string$typethe Connection implementation class to use.
Returns:
bool true if the given Connection class exists and is valid.
    {
        if (!class_exists($type)) {
            return false;
        }
        if (!in_array('P4_Connection_Interface', class_implements($type))) {
            return false;
        }
        return true;
    }
static P4_Connection::setAppName ( name) [static]

Provide a application name to set on any new connections.

Parameters:
string | null$nameapp name to report to the server
    {
        static::$_appName = is_null($name) ? $name : (string) $name;
    }
static P4_Connection::setDefaultConnection ( P4_Connection_Interface connection) [static]

Set a default connection for the environment.

Parameters:
P4_Connection_Interface$connectionthe default connection to use.
Exceptions:
P4_Exceptionif the given connection is not a valid Connection instance.
    {
        self::$_defaultConnection = $connection;
    }

Member Data Documentation

P4_Connection::$_appName [static, protected]
P4_Connection::$_defaultConnection [static, protected]

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