Previous Table of Contents Next
Perforce 2009.2: APIs for Scripting



Chapter 4
Introduction
P4PHP, the PHP interface to the Perforce API, enables you to write PHP code that interacts with a Perforce Server. P4PHP enables your PHP scripts to:
System Requirements
P4PHP is supported on Windows, Linux, FreeBSD, and OS X.
To build P4PHP from source, your development machine must also have:
(If you get "unresolved symbol" errors when building or running P4PHP, you probably used the wrong compiler or the wrong Perforce API build. )
Installing P4PHP
Download P4PHP from the Perforce web site downloads page. You must build the interface from source, as described in the release notes packaged with P4PHP.
Programming with P4PHP
The following example illustrates the basic structure of a P4PHP script. The example establishes a connection, issues a command, and tests for errors resulting from the command.
$p4 = new P4();
$p4->port = "1666";
$p4->user = "fred";
$p4->client = "fred-ws";
try {
     $p4->connect();
     $info = $p4->run("info");
     foreach ($info[0] as $key => $val) {
          print "$key = $val\n";
     }
     $p4->run("edit", "file.txt");
     $p4->disconnect();
} catch (P4_Exception $e) {
     print $e->getMessage() . "\n";
     foreach ($p4->errors as $error) {
          print "Error: $error\n";
     }
}
This example creates a client workspace from a template and syncs it:
$template = "my-client-template";
$client_root = "/home/user/work/my-root";
$p4 = new P4();
try {
     $p4->connect();
     // Convert client spec into an array
     $client = $p4->fetch_client("-t", $template);
     $client['Root'] = $client_root;
     $p4->save_client($client);
     $p4->run_sync();
} catch (P4_Exception $e) {
     // If any errors occur, we'll jump in here. Just log them
     // and raise the exception up to the higher level
}
Submitting a Changelist
This example creates a changelist, modifies it and then submits it:.
$p4 = new P4();
$p4->connect();
// Files were opened elsewhere and we want to
// submit a subset that we already know about.
$myfiles = array(
     '//depot/some/path/file1.c',
     '//depot/some/path/file1.h'
);
Logging into Perforce using ticket-based authentication
On some servers, users might need to log in to Perforce before issuing commands. The following example illustrates login using Perforce tickets.
$p4 = new P4();
$p4->user = "Sven";
$p4->password = "my_password";
$p4->connect();
$p4->run_login();
Changing your password
You can use P4PHP to change your password, as shown in the following example:
$p4 = new P4();
$p4->user = "Sven";
$p4->password = "MyOldPassword";
$p4->connect();
P4PHP Classes
The P4 module consists of several public classes:
The following tables provide more details about each public class.
P4
Perforce client class. Handles connection and interaction with the Perforce 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.
P4CLIENT, the name of the client workspace to use.
P4HOST, the name of the host used
The location of the configuration file used (P4CONFIG). This property is read-only.
P4PASSWD, the password used.
P4PORT, the port used for the connection
To disable tagged output for the following commands, set the value to 0 or False. By default, tagged output is enabled.
P4TICKETS, the ticket file location used
P4USER, the user under which the connection is run
The following table lists all public methods of the class P4.
delete_spectype()
Deletes the spec spectype. Equivalent to the command P4::run("spectype", "-d").
Get the value of a Perforce environment variable, taking into account P4CONFIG files and (on Windows) the registry.
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_command()
Runs the command command. Equivalent to P4::run("command").
This command returns an array of DepotFile objects. Specialization for the run() command.
Convenience method: updates the password. Takes two arguments: oldpassword, newpassword
Interface to p4 resolve.
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.
P4_Revision
Container class containing one revision of a DepotFile object.
Array of P4_Integration objects
P4_Integration
Container class containing one integration for a Revision object
P4_Map
A class that allows users to create and work with Perforce mappings without requiring a connection to the Perforce Server.
P4_MergeData
Class encapsulating the context of an individual merge during execution of a p4 resolve command. Passed to P4::run_resolve.
Returns the path of "their" file in the merge. (temporary file on workstation into which their_name has been loaded)
Returns the path of the base file in the merge. (temporary file on workstation into which base_name has been loaded)
Returns the path to the merge result. (temporary file on workstation into which the automatic merge performed by the server has been loaded)
P4_Resolver
Abstract class for handling resolves in Perforce. This class must be subclassed in order to be used.
Class P4
Description
Main interface to the PHP client API.
This module provides an object-oriented interface to the Perforce SCM system. Data is returned in arrays and input can also be supplied in these formats.
Each P4 object represents a connection to the Perforce Server, and multiple commands may be executed (serially) over a single connection (which of itself can result in substantially improved performance if executing long sequences of Perforce commands).
1.
2.
3.
4.
5.
6.
Properties
P4::api_level -> int
Contains the API compatibility level desired. This is useful when writing scripts using Perforce commands that do not yet support tagged output. In these cases, upgrading to a later server that supports tagged output for the commands in question can break your script. Using this method allows you to lock your script to the output format of an older Perforce release and facilitate seamless upgrades. Must be called before calling P4::connect().
$p4 = new P4();
$p4->api_level = 57; # Lock to 2005.1 format
$p4->connect();
For the API integer levels that correspond to each Perforce release, see:
http://kb.perforce.com/?article=512
P4::charset -> string
Contains the character set to use when connect to a Unicode enabled server. Do not use when working with non-Unicode-enabled servers. By default, the character set is the value of the P4CHARSET environment variable. If the character set is invalid, this method raises a P4_Exception.
$p4 = new P4();
$p4->client = "www";
$p4->charset = "iso8859-1";
$p4->connect();
$p4->run_sync();
$p4->disconnect();
P4::client -> string
Contains the name of your client workspace. By default, this is the value of the P4CLIENT taken from any P4CONFIG file present, or from the environment according to the normal Perforce conventions.
P4::cwd -> string
Contains the current working directly. Can be called prior to executing any Perforce command. Sometimes necessary if your script executes a chdir() as part of its processing.
$p4 = new P4();
$p4->cwd = "/home/sven"
P4::errors -> array (read-only)
Returns an array containing the error messages received during execution of the last command.
$p4 = new P4();
$p4->connect();
$p4->exception_level = 1;
$p4->connect();  # P4_Exception on failure
$p4->run_sync(); # File(s) up-to-date is a warning - no exception raised
$err = $p4->errors;
print_r($err);
P4::exception_level -> int
Configures the events which give rise to exceptions. The following three levels are supported:
0 disables all exception handling and makes the interface completely procedural; you are responsible for checking the P4::errors and P4::warnings arrays.
For example
$p4 = new P4();
$p4->exception_level = 1;
$p4->connect();  # P4_Exception on failure
$p4->run_sync(); # File(s) up-to-date is a warning - no exception raised
$p4->disconnect();
P4::host -> string
Contains the name of the current host. It defaults to the value of P4HOST taken from any P4CONFIG file present, or from the environment as per the usual Perforce convention. Must be called before connecting to the Perforce server.
$p4 = new P4();
$p4->host = "workstation123.perforce.com";
$p4->connect();
P4::input -> string | array
Contains input for the next command.
Set this property prior to running a command that requires input from the user. When the command requests input, the specified data is supplied to the command. Typically, commands of the form p4 cmd -i are invoked using the P4::save_spectype methods, which retrieve the value from P4::input internally; there is no need to set P4::input when using the P4::save_spectype shortcuts.
You may pass a string, an array, or (for commands that take multiple inputs from the user) an array of strings or arrays. If you pass an array, note that the first element of the array will be popped each time Perforce asks the user for input.
For example, the following code supplies a description for the default changelist and then submits it to the depot:
$p4 = new P4();
$p4->connect();
$change = $p4->run_change( "-o" )[0];
$change[ 'Description' ] = "Autosubmitted changelist" ;
$p4->input = $change;
$p4->run_submit( "-i" );
$p4->disconnect();
P4::maxlocktime -> int
Limit the amount of time (in milliseconds) spent during data scans to prevent the server from locking tables for too long. Commands that take longer than the limit will be aborted. The limit remains in force until you disable it by setting it to zero. See p4 help maxlocktime for information on the commands that support this limit.
P4::maxresults -> int
Limit the number of results Perforce permits for subsequent commands. Commands that produce more than this number of results will be aborted. The limit remains in force until you disable it by setting it to zero. See p4 help maxresults for information on the commands that support this limit.
P4::maxscanrows -> int
Limit the number of database records Perforce scans for subsequent commands. Commands that attempt to scan more than this number of records will be aborted. The limit remains in force until you disable it by setting it to zero. See p4 help maxscanrows for information on the commands that support this limit.
P4::p4config_file -> string (read-only)
Contains the name of the current P4CONFIG file, if any. This property cannot be set.
P4::password -> string
Contains your Perforce password or login ticket. If not used, takes the value of P4PASSWD from any P4CONFIG file in effect, or from the environment according to the normal Perforce conventions.
This password is also used if you later call P4::run_login() to log in using the 2003.2 and later ticket system. After running P4::run_login(), the property contains the ticket the allocated by the server.
$p4 = new P4();
$p4->password = "mypass";
$p4->connect();
$p4->run_login();
...
P4::port -> string
Contains the host and port of the Perforce server to which you want to connect. It defaults to the value of P4PORT in any P4CONFIG file in effect, and then to the value of P4PORT taken from the environment.
$p4 = new P4();
$p4->port = "localhost:1666";
$p4->connect();
...
P4::prog -> string
Contains the name of the program, as reported to Perforce system administrators running p4 monitor show -e. The default is unnamed p4-php script
$p4 = new P4();
$p4->prog = "sync-script";
print $p4->prog;
$p4->connect();
...
P4::server_level -> int (read-only)
Returns the current Perforce server level. Each iteration of the Perforce Server is given a level number. As part of the initial communication this value is passed between the client application and the Perforce Server. This value is used to determine the communication that the Perforce Server will understand. All subsequent requests can therefore be tailored to meet the requirements of this Server level.
This property is 0 before the first command is run, and is set automatically after the first communication with the server.
For the API integer levels that correspond to each Perforce release, see:
http://kb.perforce.com/?article=571
P4::tagged -> bool
If true, P4::tagged enables tagged output. By default, tagged output is on.
$p4 = new P4();
$p4->tagged = false;
print $p4->tagged;
P4::ticket_file -> string
Contains the location of the P4TICKETS file
P4::user -> string
Contains the Perforce username. It defaults to the value of P4USER taken from any P4CONFIG file present, or from the environment as per the usual Perforce convention.
$p4 = new P4();
$p4->user = "sven";
$p4->connect();
...
P4::disconnect()
P4::version -> string
Contains the version of the program, as reported to Perforce system administrators in the server log.
$p4 = new P4();
$p4->version = "123";
print $p4->version;
$p4->connect();
...
P4::warnings -> array (read-only)
Contains the array of warnings that arose during execution of the last command
$p4 = new P4();
$p4->connect();  # P4_Exception on failure
$p4->exception_level = 2;
$files = $p4->run_sync();
$warn = $p4->warnings;
print_r($warn);
Constructor
P4::__construct
Construct a new P4 object. For example:
<?php
$p4 = new P4();
?>
Static Methods
P4::identify() -> string
Return the version of P4PHP that you are using.
<?php
print P4::identify();
?>
produces output similar to the following:
Perforce - The Fast Software Configuration Management System.
Copyright 1995-2009 Perforce Software.  All rights reserved.
Rev. P4PHP/LINUX26X86/2009.1/205670 (2009.1 API) (2009/06/29).
Instance Methods
P4::connect() -> bool
Initializes the Perforce client and connects to the server.
If the connection is successfully established, returns None. If the connection fails and exception_level is 0, returns False, otherwise raises a P4_Exception. If already connected, prints a message.
$p4 = new P4();
$p4->connect();
...
$p4->disconnect();
P4::connected() -> bool
Returns true if connected to the Perforce Server and the connection is alive, otherwise false.
$p4 = new P4();
if (!$p4->connected()) {
    print "Not Connected\n";
}
$p4->connect();
if ($p4->connected()) {
    print "Connected\n";
}
P4::delete_<spectype>( [ options ], name ) -> array
The delete_spectype methods are shortcut methods that allow you to delete the definitions of clients, labels, branches, etc. These methods are equivalent to:
P4::run( <spectype>, '-d', [options], <spec name> );
The following code uses delete_client to delete client workspaces that have not been accessed in more than 365 days:
<?php
$p4 = new P4();
try {
  $p4->connect();
  foreach ($p4->run_clients() as $client) {
    $atime = int($client['Access']);
    // If the client has not been accessed for a year, delete it
    if ((time() - $atime) > 31536000) { // seconds in 365 days
      $p4->delete_client("-f", $client["Client"]);
    }
  }
} catch (P4_Exception $e) {
  // handle exception
}
?>
P4::disconnect() -> void
Disconnect from the Perforce Server. Call this method before exiting your script.
$p4 = new P4();
$p4->connect();
...
$p4->disconnect();
P4::env( var ) -> string
Get the value of a Perforce environment variable, taking into account P4CONFIG files and (on Windows) the registry.
$p4 = new P4();
print $p4->env( "P4PORT" );
P4::fetch_<spectype>() -> array
The fetch_spectype methods are shortcuts for running $p4->run("spectype", "-o") and returning the first element of the array. For example:
$label      = $p4->fetch_label(labelname);
$change     = $p4->fetch_change(changeno);
$clientspec = $p4->fetch_client(clientname);
are equivalent to
$label      = $p4->run("label", "-o", labelname);
$change     = $p4->run("change", "-o", changeno);
$clientspec = $p4->run("client", "-o", clientname);
P4::format_spec( <spectype>, array ) -> string
Converts the fields in the array containing the elements of a Perforce form (spec) into the string representation familiar to users. The first argument is the type of spec to format: for example, client, branch, label, and so on. The second argument is the hash to parse.
There are shortcuts available for this method. You can use $p4->format_spectype( array ) instead of $p4->format_spec( spectype, array ), where spectype is the name of a Perforce spec, such as client, label, etc.
P4::format_<spectype>( array ) -> string
The format_spectype methods are shortcut methods that allow you to quickly fetch the definitions of clients, labels, branches, etc. They're equivalent to:
$p4->format_spec( spectype, array );
P4::parse_spec( <spectype>, string ) -> array
Parses a Perforce form (spec) in text form into an array using the spec definition obtained from the server. The first argument is the type of spec to parse: client, branch, label, and so on. The second argument is the string buffer to parse.
There are shortcuts available for this method. You can use:
$p4->parse_spectype( buf );
instead of
$p4->parse_spec( spectype, buf );
where spectype is one of client, branch, label, and so on.
P4::parse_<spectype>( string ) -> array
This is equivalent to $p4->parse_spec( spectype, string ).
For example, $p4->parse_job(myJob) converts the String representation of a job spec into an array.
To parse a spec, P4 needs to have the spec available. When not connected to the Perforce Server, P4 assumes the default format for the spec, which is hardcoded. This assumption can fail for jobs if the Server's jobspec has been modified. In this case, your script can load a job from the Server first with the command fetch_job('somename'), andP4 will cache and use the spec format in subsequent parse_job() calls.
P4::run(cmd, [arg, ...]) -> mixed
Base interface to all the run methods in this API. Runs the specified Perforce command with the arguments supplied. Arguments may be in any form as long as they can be converted to strings.
The P4::run() method returns an array of results whether the command succeeds or fails; the array may, however, be empty. Whether the elements of the array are strings or arrays depends on:
(a) server support for tagged output for the command, and
(b) whether tagged output was disabled by calling $p4->tagged = false.
In the event of errors or warnings, and depending on the exception level in force at the time, run() raises a P4_Exception. If the current exception level is below the threshold for the error/warning, run() returns the output as normal and the caller must explicitly review P4::errors and P4::warnings to check for errors or warnings.
$p4 = new P4();
print $p4->env( "P4PORT" );
$p4->connect();
$spec = $p4->run( "client", "-o" )[0];
$p4->disconnect();
Shortcuts are available for P4::run. For example, $p4->run_command( args ) is equivalent to $p4->run( "command", args )
There are also some shortcuts for common commands such as editing Perforce forms and submitting. For example, this:
<?php
$p4 = new P4();
$p4->connect();
$clientspec = array_pop($p4->run_client("-o"));
$clientspec["Description"] = "Build Client";
$p4->input = $clientspec;
$p4->run_client("-i");
...may be shortened to
<?php
$p4 = new P4();
$p4->connect();
$clientspec = $p4->fetch_spec();
$clientspec["Description"] = "Build client";
The following are equivalent:
$p4->delete_spectype();
$p4->run( "spectype", "-d ");
$p4->fetch_spectype();
array_shift($p4->run("spectype", "-o "));
$p4->save_spectype( spec );
$p4->input = $spec;
$p4->run( "spectype", "-i" );
As the commands associated with fetch_spectype typically return only one item, these methods do not return an array, but instead return the first result element.
For convenience in submitting changelists, changes returned by fetch_change() can be passed to run_submit(). For example:
<?php
$p4 = new P4();
$p4->connect();
$spec = $p4->fetch_change();
$spec["Description"] = "Automated change";
$p4->run_submit($spec);
P4::run_<cmd>() -> mixed
Shorthand for P4::run("cmd", arguments... )
P4::run_filelog(<fileSpec >) -> array
Runs a p4 filelog on the fileSpec provided and returns an array of P4_DepotFile results (when executed in tagged mode), or an array of strings when executed in nontagged mode. By default, the raw output of p4 filelog is tagged; this method restructures the output into a more user-friendly (and object-oriented) form.
For example:
<?php
$p4 = new P4();
try {
  $p4->connect();
  $filelog = $p4->run_filelog("index.html");
  foreach ($filelog->revisions as $revision) {
    // do something
  }
} catch (P4_Exception $e) {
  // handle exception
}
?>
P4::run_login( arg... ) -> array
Runs p4_login using a password (or other arguments) set by the user.
P4::run_password( oldpass, newpass ) -> array
A thin wrapper to make it easy to change your password. This method is equivalent to the following:
<?php
$p4->input = array( $oldpass, $newpass, $newpass );
$p4->run( "password" );
?>
For example
<?php
$p4 = new P4();
$p4->password = "myoldpass";
try {
  $p4->connect();
  $p4->run_password("myoldpass", "mynewpass");
  $p4->disconnect();
} catch (P4_Exception $e) {
  // handle exception
}
?>
P4::run_resolve( [resolver], [arg...] ) -> array
Run a p4 resolve command. Interactive resolves require the resolver parameter to be an object of a class derived from P4_Resolver. In these cases, the resolve method of this class is called to handle the resolve. For example:
<?php
$p4->run_resolve(new MyResolver());
?>
To perform an automated merge that skips whenever conflicts are detected:
<?php
class MyResolver extends P4_Resolver {
  public function resolve($merge_data) {
    if ($merge_data->merge_hint != 'e') {
      return $merge_data->merge_hint;
    } else {
      return "s"; // skip, there's a conflict
    }
  }
}
?>
In non-interactive resolves, no P4_Resolver object is required. For example:
P4::run_submit( [ array ], [ arg... ] ) -> array
Submit a changelist to the server. To submit a changelist, set the fields of the changelist as required and supply any flags:
$p4->change = $p4->fetch_change();
$change["Description"] = "Some description";
$p4->run_submit( "-r", $change );
You can also submit a changelist by supplying the arguments as you would on the command line:
P4::save_<spectype>()>
The save_spectype methods are shortcut methods that allow you to quickly update the definitions of clients, labels, branches, etc. They are equivalent to:
$p4->input = $arrayOrString;
$p4->run( "spectype", "-i" );
For example:
<?php
$p4 = new P4();
try {
  $p4->connect();
  $client = $p4->fetch_client();
  $client["Owner"] = $p4->user;
  $p4->save_client($client);
  $p4->disconnect();
} catch (P4_Exception $e) {
  // handle exception
}
?>
 
Class P4_Exception
Description
Instances of this class are raised when P4 encounters an error or a warning from the server. The exception contains the errors in the form of a string. P4_Exception is an extension of the standard Exception class.
Class Attributes
None.
Static Methods
None.
Class P4_DepotFile
Description
Utility class providing easy access to the attributes of a file in a Perforce depot. Each P4_DepotFile object contains summary information about the file and an array of revisions (P4_Revision objects) of that file. Currently, only the P4::run_filelog method returns an array of P4_DepotFile objects.
Properties
$df->depotFile -> string
Returns the name of the depot file to which this object refers.
$df->revisions -> array
Returns an array of P4_Revision objects, one for each revision of the depot file.
Static Methods
None.
Instance Methods
None.
 
Class P4_Revision
Description
Utility class providing easy access to the revisions of P4_DepotFile objects. Created by P4::run_filelog().
Properties
$rev->action -> string
Returns the name of the action which gave rise to this revision of the file.
$rev->change -> long
Returns the change number that gave rise to this revision of the file.
$rev->client -> string
Returns the name of the client from which this revision was submitted.
$rev->depotFile -> string
Returns the name of the depot file to which this object refers.
$rev->desc -> string
Returns the description of the change which created this revision. Note that only the first 31 characters are returned unless you use p4 filelog -L for the first 250 characters, or p4 filelog -l for the full text.
$rev->digest -> string
Returns the MD5 checksum of this revision.
$rev->fileSize -> long
Returns this revision's size in bytes.
$rev->integrations -> array
Returns the array of P4_Integration objects for this revision.
$rev->rev -> long
Returns the number of this revision of the file.
$rev->time -> string
Returns the date/time that this revision was created.
$rev->type -> string
Returns this revision's Perforce filetype.
$rev->user -> string
Returns the name of the user who created this revision.
Static Methods
None.
Instance Methods
None.
Class P4_Integration
Description
Utility class providing easy access to the details of an integration record. Created by P4::run_filelog().
Properties
$integ->how -> string
Returns the type of the integration record - how that record was created.
$integ->file -> string
Returns the path to the file being integrated to/from.
$integ->srev -> int
Returns the start revision number used for this integration.
$integ->erev -> int
Returns the end revision number used for this integration.
Static Methods
None.
Instance Methods
None.
Class P4_Map
Description
The P4_Map class allows users to create and work with Perforce mappings, without requiring a connection to a Perforce server.
Properties
None
Constructor
P4_Map::__construct( [ array ] ) -> P4_Map
Constructs a new P4_Map object.
Static Methods
P4_Map::join ( map1, map2 ) -> P4_Map
Join two P4_Map objects and create a third P4_Map. The new map is composed of the left-hand side of the first mapping, as joined to the right-hand side of the second mapping. For example:
# Map depot syntax to client syntax
$client_map = new P4_Map();
$client_map->insert( "//depot/main/...", "//client/..." );
# Map client syntax to local syntax
$client_root = new P4_Map();
$client_root->insert( "//client/...", "/home/tony/workspace/..." );
# Join the previous mappings to map depot syntax to local syntax
$local_map = P4_Map::join( $client_map, $client_root );
$local_path = $local_map->translate("//depot/main/www/index.html");
Instance Methods
$map->clear() -> void
Empty a map.
$map->count() -> int
Return the number of entries in a map.
$map->is_empty() -> bool
Test whether a map object is empty.
$map->insert( string ... ) -> void
Inserts an entry into the map.
May be called with one or two arguments. If called with one argument, the string is assumed to be a string containing either a half-map, or a string containing both halves of the mapping. In this form, mappings with embedded spaces must be quoted. If called with two arguments, each argument is assumed to be half of the mapping, and quotes are optional.
# called with two arguments:
$map->insert( "//depot/main/...", "//client/..." );
# called with one argument containing both halves of the mapping:
$map->insert( "//depot/live/... //client/live/..." );
# called with one argument containing a half-map:
# This call produces the mapping "depot/... depot/..."
$map->insert( "depot/..." );
$map->translate ( string, [ bool ] )-> string
Translate a string through a map, and return the result. If the optional second argument is 1, translate forward, and if it is 0, translate in the reverse direction. By default, translation is in the forward direction.
$map->includes( string ) -> bool
Tests whether a path is mapped or not.
$map->reverse() -> P4_Map
Return a new P4_Map object with the left and right sides of the mapping swapped. The original object is unchanged.
$map->lhs() -> array
Returns the left side of a mapping as an array.
$map->rhs() -> array
Returns the right side of a mapping as an array.
$map->as_array() -> array
Returns the map as an array.
Class P4_MergeData
Description
Class containing the context for an individual merge during execution of a p4 resolve.
Properties
$md->your_name -> string
Returns the name of "your" file in the merge. This is typically a path to a file in the workspace.
$md->their_name -> string
Returns the name of "their" file in the merge. This is typically a path to a file in the depot.
$md->base_name -> string
Returns the name of the "base" file in the merge. This is typically a path to a file in the depot.
$md->your_path -> string
Returns the path of "your" file in the merge. This is typically a path to a file in the workspace.
$md->their_path -> string
Returns the path of "their" file in the merge. This is typically a path to a temporary file on your local machine in which the contents of their_name have been loaded.
$md->base_path -> string
Returns the path of the base file in the merge. This is typically a path to a temporary file on your local machine in which the contents of base_name have been loaded.
$md->result_path -> string
Returns the path to the merge result. This is typically a path to a temporary file on your local machine in which the contents of the automatic merge performed by the server have been loaded.
$md->merge_hint -> string
Returns the hint from the server as to how it thinks you might best resolve this merge.
Class P4_Resolver
Description
P4_Resolver is a class for handling resolves in Perforce. It must be subclassed, to be used; subclasses can override the resolve() method. When P4::run_resolve() is called with a P4_Resolver object, it calls the resolve() method of the object once for each scheduled resolve.
Properties
None
Static Methods
None
Instance Methods
$resolver->resolve(self, mergeData) -> string
Returns the resolve decision as a string. The standard Perforce resolve strings apply:
By default, all automatic merges are accepted, and all merges with conflicts are skipped. The resolve method is called with a single parameter, which is a reference to a P4_MergeData object.
 


Previous Table of Contents Next

Perforce 2009.2: APIs for Scripting
Copyright 2008-2009 Perforce Software.