Class P4_Map

Description

The P4_Map class allows users to create and work with Helix Server mappings, without requiring a connection to a Helix 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/bruno/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" );

// local_path is now /home/bruno/workspace/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.

if $map->includes( "//depot/main/..." ) {
  ...
}

$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.