|
Perforce Chronicle 2012.2/486814
API Documentation
|
Perforce connection factory. More...
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 |
Perforce connection factory.
A Factory used to create a Perforce Connection instance. This class is responsible for deciding the specific implementation to use.
| 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.
| string | $port | optional - the port to connect to. |
| string | $user | optional - the user to connect as. |
| string | $client | optional - the client spec to use. |
| string | $password | optional - the password to use. |
| string | $ticket | optional - a ticket to use. |
| string | $type | optional - a specific client implementation to use. |
| P4_Exception | if 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.
{
return static::$_appName;
}
| static P4_Connection::getConnectionIdentity | ( | ) | [static] |
Get the identity of the current default Connection implementation.
{
$p4 = self::factory();
return $p4->getConnectionIdentity();
}
| static P4_Connection::getDefaultConnection | ( | ) | [static] |
Get the default connection for the environment.
| P4_Exception | if 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.
{
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.
| string | $type | the Connection implementation class to use. |
{
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.
| string | null | $name | app 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.
| P4_Connection_Interface | $connection | the default connection to use. |
| P4_Exception | if the given connection is not a valid Connection instance. |
{
self::$_defaultConnection = $connection;
}
P4_Connection::$_appName [static, protected] |
P4_Connection::$_defaultConnection [static, protected] |