Perforce Chronicle 2012.2/486814
API Documentation
|
P4PHP Perforce connection implementation. More...
Public Member Functions | |
__construct ($port=null, $user=null, $client=null, $password=null, $ticket=null) | |
Constructs a P4 connection object. | |
disconnect () | |
Disconnect from the Perforce Server. | |
getConnectionIdentity () | |
Get the identity of this Connection implementation. | |
isConnected () | |
Check connected state. | |
login () | |
Extends parent to set our instance's password to the returned ticket value if login succeeds. | |
setAppName ($name) | |
Extended to set app name in p4-php. | |
setCharset ($charset) | |
Extended to set charset in p4-php. | |
setClient ($client) | |
Extend set client to update p4-php. | |
setHost ($host) | |
Extended to set host name in p4-php. | |
setPassword ($password) | |
Extend set password to update p4-php. | |
setPort ($port) | |
Extend set port to update p4-php. | |
setTicket ($ticket) | |
Extend set ticket to update p4-php. | |
setUser ($user) | |
Extend set user to update p4-php. | |
Protected Member Functions | |
_connect () | |
Does real work of establishing connection. | |
_prepareInput ($input, $command) | |
Prepare input for passing to the p4 extension. | |
_run ($command, $params=array(), $input=null, $tagged=true) | |
Actually issues a command. | |
Protected Attributes | |
$_instance |
P4PHP Perforce connection implementation.
This client implementation provides access to the P4PHP extension in a way that conforms to P4_Connection_Interface. This allows the P4PHP extension and the Perforce Command-Line Client wrapper to be used interchangeably.
P4_Connection_Extension::__construct | ( | $ | port = null , |
$ | user = null , |
||
$ | client = null , |
||
$ | password = null , |
||
$ | ticket = null |
||
) |
Constructs a P4 connection object.
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. |
Reimplemented from P4_Connection_Abstract.
{ // ensure that p4-php is installed. if (!extension_loaded('perforce')) { throw new P4_Exception( 'Cannot create P4 API extension instance. Perforce extension not loaded.'); } // create an instance of p4-php. $this->_instance = new P4; // disable automatic sequence expansion (call expandSequences on result object if desired) $this->_instance->expand_sequences = false; // prevent command exceptions from being thrown by P4. // we throw our own so that we can attach the result. $this->_instance->exception_level = 0; parent::__construct($port, $user, $client, $password, $ticket); }
P4_Connection_Extension::_connect | ( | ) | [protected] |
Does real work of establishing connection.
Called by connect().
P4_Connection_ConnectException | if the connection fails. |
Reimplemented from P4_Connection_Abstract.
{ // temporarily enable exceptions to catch connection failure. $this->_instance->exception_level = 1; try { $this->_instance->connect(); $this->_instance->exception_level = 0; } catch (P4_Exception $e) { $this->_instance->exception_level = 0; throw new P4_Connection_ConnectException( "Connect failed: " . $e->getMessage() ); } }
P4_Connection_Extension::_prepareInput | ( | $ | input, |
$ | command | ||
) | [protected] |
Prepare input for passing to the p4 extension.
Ensure input is either a string or an array of strings.
string | array | $input | the input to prepare for p4. |
string | $command | the command to prepare input for. |
Reimplemented from P4_Connection_Abstract.
{ // if input is not an array, cast to string and return. if (!is_array($input)) { return (string) $input; } // ensure each element of array is a string. $stringify = function(&$input) { $input = (string) $input; }; array_walk_recursive($input, $stringify); return $input; }
P4_Connection_Extension::_run | ( | $ | command, |
$ | params = array() , |
||
$ | input = null , |
||
$ | tagged = true |
||
) | [protected] |
Actually issues a command.
Called by run() to perform the dirty work.
string | $command | the command to run. |
array | $params | optional - arguments. |
array | string | $input | optional - input for the command - should be provided in array form when writing perforce spec records. |
boolean | $tagged | optional - true/false to enable/disable tagged output. defaults to true. |
Reimplemented from P4_Connection_Abstract.
{ // push command to front of parameters array array_unshift($params, $command); // set input for the command. if ($input !== null) { $this->_instance->input = $input; } // toggle tagged output. $this->_instance->tagged = (bool) $tagged; // establish connection to perforce server. if (!$this->isConnected()) { $this->connect(); } // run command. $data = call_user_func_array(array($this->_instance, "run"), $params); // collect data in result object and ensure output is in array form. $result = new P4_Result($command, $data, $tagged); $result->setErrors($this->_instance->errors); $result->setWarnings($this->_instance->warnings); return $result; }
P4_Connection_Extension::disconnect | ( | ) |
Disconnect from the Perforce Server.
Reimplemented from P4_Connection_Abstract.
{ // call parent to run disconnect callbacks. parent::disconnect(); if ($this->isConnected()) { $this->_instance->disconnect(); } return $this; }
P4_Connection_Extension::getConnectionIdentity | ( | ) |
Get the identity of this Connection implementation.
Resulting array will contain:
P4_Exception | if the returned version string is invalid |
Implements P4_Connection_Interface.
{ // obtain the extension's identification $output = $this->_instance->identify(); // extract the version string and split into components preg_match('/\nRev. (.*)\.$/', $output, $matches); $parts = isset($matches[1]) ? preg_split('/\/| \(| API\) \(|\)/', $matches[1]) : null; if (count($parts) < 8) { $message = 'p4php returned an invalid version string'; throw new P4_Exception($message); } // build identity array of version components, including original string $identity = array( 'name' => $parts[0], 'platform' => $parts[1], 'version' => $parts[2], 'build' => $parts[3], 'apiversion' => $parts[4], 'apibuild' => $parts[5], 'date' => $parts[6] . '/' . $parts[7] . '/' . $parts[8], 'original' => $matches[1] ); return $identity; }
P4_Connection_Extension::isConnected | ( | ) |
Check connected state.
Implements P4_Connection_Interface.
{
return $this->_instance->connected();
}
P4_Connection_Extension::login | ( | ) |
Extends parent to set our instance's password to the returned ticket value if login succeeds.
P4_Connection_LoginException | if login fails. |
Reimplemented from P4_Connection_Abstract.
{ $ticket = parent::login(); if ($ticket) { $this->_instance->password = $ticket; } return $ticket; }
P4_Connection_Extension::setAppName | ( | $ | name | ) |
Extended to set app name in p4-php.
Set the name of the application that is using this connection.
string | null | $name | the app name to report to the server. |
Reimplemented from P4_Connection_Abstract.
{ $this->_instance->set_protocol('app', (string) $name); return parent::setAppName($name); }
P4_Connection_Extension::setCharset | ( | $ | charset | ) |
Extended to set charset in p4-php.
Sets the character set to use for this perforce connection.
You should only set a character set when connecting to a 'unicode enabled' server, or when setting the special value of 'none'.
string | $charset | the charset to use (e.g. 'utf8'). |
Reimplemented from P4_Connection_Abstract.
{ $this->_instance->charset = $charset; return parent::setCharset($charset); }
P4_Connection_Extension::setClient | ( | $ | client | ) |
Extend set client to update p4-php.
string | $client | the name of the client workspace to use. |
Reimplemented from P4_Connection_Abstract.
{ parent::setClient($client); // if no client is specified, normally the host name is used. // this can collide with an existing depot or client name, so // we use a temp id to avoid errors. $this->_instance->client = $this->getClient() ?: P4_Client::makeTempId(); return $this; }
P4_Connection_Extension::setHost | ( | $ | host | ) |
Extended to set host name in p4-php.
Sets the client host name overriding the environment.
string | null | $host | the host name to use. |
Reimplemented from P4_Connection_Abstract.
{ $this->_instance->host = $host; return parent::setHost($host); }
P4_Connection_Extension::setPassword | ( | $ | password | ) |
Extend set password to update p4-php.
string | $password | the password to use as authentication. |
Reimplemented from P4_Connection_Abstract.
{ parent::setPassword($password); $this->_instance->password = $this->getPassword(); return $this; }
P4_Connection_Extension::setPort | ( | $ | port | ) |
Extend set port to update p4-php.
string | $port | the port to connect to. |
Reimplemented from P4_Connection_Abstract.
{ parent::setPort($port); $this->_instance->port = $this->getPort(); return $this; }
P4_Connection_Extension::setTicket | ( | $ | ticket | ) |
Extend set ticket to update p4-php.
Note: the ticket is stored in the password field in p4-php.
string | $ticket | the ticket to use as authentication. |
Reimplemented from P4_Connection_Abstract.
{ parent::setTicket($ticket); if ($ticket) { $this->_instance->password = $this->getTicket(); } return $this; }
P4_Connection_Extension::setUser | ( | $ | user | ) |
Extend set user to update p4-php.
string | $user | the user to connect as. |
Reimplemented from P4_Connection_Abstract.
{ parent::setUser($user); $this->_instance->user = $this->getUser(); return $this; }
P4_Connection_Extension::$_instance [protected] |