Perforce Chronicle 2012.2/486814
API Documentation

P4_Connection_Deferred Class Reference

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

Inheritance diagram for P4_Connection_Deferred:
P4_Connection_Interface

List of all members.

Public Member Functions

 __construct ($callback=null, $ignored1=null, $ignored2=null, $ignored3=null, $ignored4=null)
 Create a new deferred connection from the given callback.
 addDisconnectCallback ($callback, $persistent=false)
 Add a function to run when connection is closed.
 batchArgs (array $arguments, array $prefixArgs=null, array $suffixArgs=null, $groupSize=1)
 Return arguments split into chunks (batches) where each batch contains as many arguments as possible to not exceed ARG_MAX or OPTION_LIMIT.
 connect ()
 Connect to a Perforce server.
 disconnect ()
 Disconnect from a Perforce server.
 getAppName ()
 Get the application name being reported to the server.
 getArgMax ()
 Get the maximum allowable length of all command arguments.
 getCharset ()
 Retrieves the character set used by this connection.
 getClient ()
 Return the p4 user's client.
 getClientRoot ()
 Get the current client's root directory.
 getConnection ()
 Resolves the callback to a real connection.
 getConnectionIdentity ()
 Get the identity of this Connection implementation.
 getHost ()
 Retrieves the client host set for this connection.
 getInfo ()
 Return an array of connection information.
 getPassword ()
 Retrieves the password set for this perforce connection.
 getPort ()
 Return the p4 port.
 getSecurityLevel ()
 Get the server's security level.
 getTicket ()
 Retrieves the ticket set for this perforce connection.
 getUser ()
 Return the name of the p4 user.
 isCaseSensitive ()
 Check if the server we are connected to is case sensitive.
 isConnected ()
 Check connected state.
 isSuperUser ()
 Check if the user we are connected as has super user privileges.
 login ()
 Authenticate the user with 'p4 login'.
 run ($command, $params=array(), $input=null, $tagged=true)
 Executes the specified command and returns a perforce result object.
 setAppName ($name)
 Set the name of the application that is using this connection.
 setCallback ($callback)
 Set the callback to use to get the real connection to use.
 setCharset ($charset)
 Sets the character set to use for this perforce connection.
 setClient ($client)
 Set the p4 user's client.
 setHost ($host)
 Sets the client host name overriding the environment.
 setPassword ($password)
 Sets the password to use for this perforce connection.
 setPort ($port)
 Set the p4 port.
 setTicket ($ticket)
 Sets the ticket to use for this perforce connection.
 setUser ($user)
 Set the name of the p4 user.

Protected Attributes

 $_callback = null

Detailed Description

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

This is particularly useful if creating the connection will have notable expense you wish to avoid, or if you expect the connection 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

P4_Connection_Deferred::__construct ( callback = null,
ignored1 = null,
ignored2 = null,
ignored3 = null,
ignored4 = null 
)

Create a new deferred connection from the given callback.

A callback must be provided.

Parameters:
callable$callbackthe callback function to get the real connection.
string$ignored1unused argument required by interface.
string$ignored2unused argument required by interface.
string$ignored3unused argument required by interface.
string$ignored4unused argument required by interface.
Exceptions:
InvalidArgumentExceptionif the given callback is not callable.

Implements P4_Connection_Interface.

    {
        $this->setCallback($callback);
    }

Member Function Documentation

P4_Connection_Deferred::addDisconnectCallback ( callback,
persistent = false 
)

Add a function to run when connection is closed.

Callbacks are removed after they are executed unless persistent is set to true.

Parameters:
callable$callbackthe function to execute on disconnect (will be passed connection).
bool$persistentoptional - defaults to false - set to true to run callback on repeated disconnects.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

                                            { return $this->getConnection()->addDisconnectCallback($callback, $persistent); }
P4_Connection_Deferred::batchArgs ( array $  arguments,
array $  prefixArgs = null,
array $  suffixArgs = null,
groupSize = 1 
)

Return arguments split into chunks (batches) where each batch contains as many arguments as possible to not exceed ARG_MAX or OPTION_LIMIT.

ARG_MAX is a character limit that affects command line programs (p4). OPTION_LIMIT is a server-side limit on the number of flags (e.g. '-n').

Parameters:
array$argumentslist of arguments to split into chunks.
array | null$prefixArgsarguments to begin all batches with.
array | null$suffixArgsarguments to end all batches with.
int$groupSizekeep arguments together in groups of this size for example, when clearing attributes you want to keep pairs of -n and attr-name together.
Returns:
array list of batches of arguments where every batch contains as many arguments as possible and arg-max is not exceeded.
Exceptions:
P4_Exceptionif a argument (or set of arguments) exceed arg-max.

Implements P4_Connection_Interface.

                                            { return $this->getConnection()->batchArgs($arguments, $prefixArgs, $suffixArgs, $groupSize); }
P4_Connection_Deferred::connect ( )

Connect to a Perforce server.

Returns:
P4_Connection_Interface provides fluent interface.
Exceptions:
P4_Connection_ConnectExceptionif the connection fails.

Implements P4_Connection_Interface.

{ return $this->getConnection()->connect(); }
P4_Connection_Deferred::disconnect ( )

Disconnect from a Perforce server.

Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->disconnect(); }
P4_Connection_Deferred::getAppName ( )

Get the application name being reported to the server.

Returns:
string|null the app name reported to the server.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getAppName(); }
P4_Connection_Deferred::getArgMax ( )

Get the maximum allowable length of all command arguments.

Returns:
int the max length of combined arguments - zero for no limit

Implements P4_Connection_Interface.

{ return $this->getConnection()->getArgMax(); }
P4_Connection_Deferred::getCharset ( )

Retrieves the character set used by this connection.

Returns:
string charset used for this connection.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getCharset(); }
P4_Connection_Deferred::getClient ( )

Return the p4 user's client.

Returns:
string the client.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getClient(); }
P4_Connection_Deferred::getClientRoot ( )

Get the current client's root directory.

Returns:
string the full path to the current client's root.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getClientRoot(); }
P4_Connection_Deferred::getConnection ( )

Resolves the callback to a real connection.

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

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

        return $adapter;
    }
P4_Connection_Deferred::getConnectionIdentity ( )

Get the identity of this Connection implementation.

Returns:
array an array of client Connection information containing the name, platform, version, build and date of the client library.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getConnectionIdentity(); }
P4_Connection_Deferred::getHost ( )

Retrieves the client host set for this connection.

Returns:
string charset used for this connection.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getHost(); }
P4_Connection_Deferred::getInfo ( )

Return an array of connection information.

Returns:
array the connection information ('p4 info').

Implements P4_Connection_Interface.

{ return $this->getConnection()->getInfo(); }
P4_Connection_Deferred::getPassword ( )

Retrieves the password set for this perforce connection.

Returns:
string password used to authenticate against perforce server.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getPassword(); }
P4_Connection_Deferred::getPort ( )

Return the p4 port.

Returns:
string the port.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getPort(); }
P4_Connection_Deferred::getSecurityLevel ( )

Get the server's security level.

Returns:
int the security level of the server (e.g. 0, 1, 2, 3)

Implements P4_Connection_Interface.

{ return $this->getConnection()->getSecurityLevel(); }
P4_Connection_Deferred::getTicket ( )

Retrieves the ticket set for this perforce connection.

Returns:
string ticket as generated by perforce server.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getTicket(); }
P4_Connection_Deferred::getUser ( )

Return the name of the p4 user.

Returns:
string the user.

Implements P4_Connection_Interface.

{ return $this->getConnection()->getUser(); }
P4_Connection_Deferred::isCaseSensitive ( )

Check if the server we are connected to is case sensitive.

Returns:
bool true if the server is case sensitive, false otherwise.

Implements P4_Connection_Interface.

{ return $this->getConnection()->isCaseSensitive(); }
P4_Connection_Deferred::isConnected ( )

Check connected state.

Returns:
bool true if connected, false otherwise.

Implements P4_Connection_Interface.

{ return $this->getConnection()->isConnected(); }
P4_Connection_Deferred::isSuperUser ( )

Check if the user we are connected as has super user privileges.

Returns:
bool true if the user has super, false otherwise.

Implements P4_Connection_Interface.

{ return $this->getConnection()->isSuperUser(); }
P4_Connection_Deferred::login ( )

Authenticate the user with 'p4 login'.

Returns:
string|null the ticket issued by the server or null if no ticket issued (user has no password).
Exceptions:
P4_Connection_LoginExceptionif login fails.

Implements P4_Connection_Interface.

{ return $this->getConnection()->login(); }
P4_Connection_Deferred::run ( command,
params = array(),
input = null,
tagged = true 
)

Executes the specified command and returns a perforce result object.

No need to call connect() first. Run will connect automatically.

Parameters:
string$commandthe command to run.
array | string$paramsoptional - one or more arguments.
array | string$inputoptional - input for the command - should be provided in array form when writing perforce spec records.
boolean$taggedoptional - true/false to enable/disable tagged output. defaults to true.
Returns:
P4_Result the perforce result object.
Exceptions:
P4_Connection_CommandExceptionif the command fails.

Implements P4_Connection_Interface.

                                            { return $this->getConnection()->run($command, $params, $input, $tagged); }
P4_Connection_Deferred::setAppName ( name)

Set the name of the application that is using this connection.

The application name will be reported to the server and might be necessary to satisfy certain licensing restrictions.

Parameters:
string | null$namethe app name to report to the server.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setAppName($name); }
P4_Connection_Deferred::setCallback ( callback)

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

Parameters:
callable$callbackthe callback function to get the real connection. the callback will be called with no arguments and must return a connection instance.
Returns:
P4_Connection_Deferred 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;
    }
P4_Connection_Deferred::setCharset ( charset)

Sets the character set to use for this perforce connection.

You should only set a character set when connecting to a 'unicode enabled' server.

Parameters:
string$charsetthe charset to use (e.g. 'utf8').
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setCharset($charset); }
P4_Connection_Deferred::setClient ( client)

Set the p4 user's client.

Parameters:
string$clientthe name of the client workspace to use.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setClient($client); }
P4_Connection_Deferred::setHost ( host)

Sets the client host name overriding the environment.

Parameters:
string | null$hostthe host name to use.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setHost($host); }
P4_Connection_Deferred::setPassword ( password)

Sets the password to use for this perforce connection.

Parameters:
string$passwordthe password to use as authentication.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setPassword($password); }
P4_Connection_Deferred::setPort ( port)

Set the p4 port.

Parameters:
string$portthe port to connect to.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setPort($port); }
P4_Connection_Deferred::setTicket ( ticket)

Sets the ticket to use for this perforce connection.

Parameters:
string$ticketthe ticket to use as authentication.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setTicket($ticket); }
P4_Connection_Deferred::setUser ( user)

Set the name of the p4 user.

Parameters:
string$userthe user to connect as.
Returns:
P4_Connection_Interface provides fluent interface.

Implements P4_Connection_Interface.

{ return $this->getConnection()->setUser($user); }

Member Data Documentation

P4_Connection_Deferred::$_callback = null [protected]

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