P4PHP Classes

The P4 module consists of several public classes:

The following tables provide more details about each public class.

P4

Helix Core Server client class. Handles connection and interaction with the Helix Core Server. There is one instance of each connection.

The following table lists properties of the class P4 in P4PHP. The properties are readable and writable unless indicated otherwise. The properties can be strings, arrays, or integers.

Property Description

api_level

API compatibility level. (Lock server output to a specified server level.)

charset

Charset for Unicode servers.

client

P4CLIENT, the name of the client workspace to use.

cwd

Current working directory.

errors

A read-only array containing the error messages received during execution of the last command.

exception_level

The exception level of the P4 instance. Values can be:

  • 0 : no exceptions are raised
  • 1 : only errors are raised as exceptions
  • 2 : warnings are also raised as exceptions

The default value is 2.

expand_sequences

Control whether keys with trailing numbers are expanded into arrays; by default, true, for backward-compatibility.

handler

An output handler.

host

P4HOST, the name of the host used.

input

Input for the next command. Can be a string, or an array.

maxlocktime

MaxLockTime used for all following commands.

maxresults

MaxResults used for all following commands.

maxscanrows

MaxScanRows used for all following commands.

p4config_file

The location of the configuration file used (P4CONFIG). This property is read-only.

password

P4PASSWD, the password used.

port

P4PORT, the port used for the connection

prog

The name of the script.

server_level

Returns the current Helix Core Server level. This property is read only.

streams

Enable or disable support for streams.

tagged

To disable tagged output for the following commands, set the value to 0 or False. By default, tagged output is enabled.

ticket_file

P4TICKETS, the ticket file location used.

user

P4USER, the user under which the connection is run.

version

The version of the script.

warnings

A read-only array containing the warning messages received during execution of the last command.

The following table lists all public methods of the class P4.

Method Description

connect()

Connects to the Helix Core Server.

connected()

Returns True if connected and the connection is alive, otherwise False.

delete_<spectype>()

Deletes the spec <spectype>. Equivalent to the command:

P4::run( "<spectype>", "-d" );

disconnect()

Disconnects from the Helix Core Server.

env()

Get the value of a Helix Core Server environment variable, taking into account P4CONFIG files and (on Windows or macOS) the registry or user preferences.

identify()

Returns a string identifying the P4PHP module. (This method is static.)

fetch_<spectype>()

Fetches the spec <spectype>. Equivalent to the command:

P4::run( "<spectype>", "-o" );

format_<spectype>()

Converts the spec <spectype> into a string.

parse_<spectype>()

Parses a string representation of the spec <spectype> and returns an array.

run()

Runs a command on the server. Needs to be connected, or an exception is raised.

run_cmd()

Runs the command cmd. Equivalent to:

P4::run( "cmd" );

run_filelog()

This command returns an array of P4_DepotFile objects. Specialization for the run() command.

run_login()

Logs in using the specified password or ticket.

run_password()

Convenience method: updates the password. Takes two arguments: oldpassword, newpassword.

run_resolve()

Interface to p4 resolve.

run_submit()

Convenience method for submitting changelists. When invoked with a change spec, it submits the spec. Equivalent to:

p4::input = myspec;
p4::run( "submit", "-i" );

save_<spectype>()

Saves the spec <spectype>. Equivalent to the command:

P4::run( "<spectype>", "-i" );

P4_Exception

Exception class. Instances of this class are raised when errors and/or (depending on the exception_level setting) warnings are returned by the server. The exception contains the errors in the form of a string. P4_Exception extends the standard PHP Exception class.

P4_DepotFile

Container class returned by P4::run_filelog(). Contains the name of the depot file and an array of P4_Revision objects.

Property Description

depotFile

Name of the depot file

revisions

Array of Revision objects.

P4_Revision

Container class containing one revision of a P4_DepotFile object.

Property Description

action

Action that created the revision.

change

Changelist number.

client

Client workspace used to create this revision.

desc

Short changelist description.

depotFile

The name of the file in the depot.

digest

MD5 digest of the revision.

fileSize

File size of this revision.

integrations

Array of P4_Integration objects.

rev

Revision.

time

Timestamp.

type

File type.

user

User that created this revision.

P4_Integration

Container class containing one integration for a P4_Revision object.

Property Description

how

Integration method (merge/branch/copy/ignored).

file

Integrated file.

srev

Start revision.

erev

End revision.

P4_Map

A class that allows users to create and work with Helix Core Server mappings without requiring a connection to the Helix Core Server.

Method Description

__construct()

Construct a new Map object.

join()

Joins two maps to create a third (static method).

clear()

Empties a map.

count()

Returns the number of entries in a map.

is_empty()

Tests whether or not a map object is empty.

insert()

Inserts an entry into the map.

translate()

Translate a string through a map.

includes()

Tests whether a path is mapped.

reverse()

Returns a new mapping with the left and right sides reversed.

lhs()

Returns the left side as an array.

rhs()

Returns the right side as an array.

as_array()

Returns the map as an array.

P4_MergeData

Class encapsulating the context of an individual merge during execution of a p4 resolve command. Passed to P4::run_resolve().

Property Description

your_name

Returns the name of "your" file in the merge. (file in workspace)

their_name

Returns the name of "their" file in the merge. (file in the depot)

base_name

Returns the name of "base" file in the merge. (file in the depot)

your_path

Returns the path of "your" file in the merge. (file in workspace)

their_path

Returns the path of "their" file in the merge. (temporary file on workstation into which their_name has been loaded)

base_path

Returns the path of the base file in the merge. (temporary file on workstation into which base_name has been loaded)

result_path

Returns the path to the merge result. (temporary file on workstation into which the automatic merge performed by the server has been loaded.)

merge_hint

Returns hint from server as to how user might best resolve merge.

P4_OutputHandlerAbstract

Handler class that provides access to streaming output from the server; set $p4->handler to an instance of a subclass of P4_OutputHandlerAbstract to enable callbacks:

Method Description

outputBinary()

Process binary data.

outputInfo()

Process tabular data.

outputMessage()

Process information or errors.

outputStat()

Process tagged output.

outputText()

Process text data.

P4_Resolver

Abstract class for handling resolves in Perforce. This class must be subclassed in order to be used.

Method Description

resolve()

Perform a resolve and return the resolve decision as a string.