core/xpdo/transport/xpdotransport.class.php
Represents a transportable package of related data and other resources.
- Package
- xpdo
- Subpackage
- transport
\xPDOTransport
Represents xPDOObject and related data in a serialized format for exchange.
Constants
integer
PRESERVE_PREEXISTING
= 0Indicates how pre-existing objects are treated on install/uninstall.
- integer
integer
ARCHIVE_WITH_DEFAULT
= 0Indicates which archiving tool to use for pack()'ing and unpack()'ing the transport.
- integer
Properties

array
$_preserved= 'array()'
An map of preserved objects from an install used by uninstall.
array()Details- Type
- array

array
$attributes= 'array ()'
Stores various attributes about the transport package.
array ()Details- Type
- array

string
$manifestVersion= ''1.1''
The current manifest version for this transport.
'1.1'Details- Type
- string

string
$name= 'null'
A unique name used to identify the package without the version.
nullDetails- Type
- string

string
$path= 'null'
The physical location of the transport package.
nullDetails- Type
- string

string
$signature= 'null'
A unique signature to identify the package.
nullDetails- Type
- string
- Access
- public

integer
$state= 'null'
Indicates the state of the xPDOTransport instance.
nullDetails- Type
- integer

array
$vehicles= 'array ()'
A map of object vehicles containing payloads of data for transport.
array ()Details- Type
- array

string
$version= 'null'
The package version, as a PHP-standardized version number string.
nullDetails- Type
- string

\xPDO
$xpdo= 'null'
An {@link xPDO} reference controlling this transport instance.
nullDetails- Type
- \xPDO
- Access
- public
Methods

__construct(
\xPDO $xpdo, string $signature, string $path, array $options
=
array()
)
:
voidPrepares and returns a new xPDOTransport instance.
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | &$xpdo The xPDO instance accessing this package. |
| $signature | string | The unique signature of the package. |
| $path | string | Valid path to the physical transport package. |
| $options | array | An optional array of attributes for constructing the instance. |

_convertManifestVer1_0(
array $manifestVehicles
)
:
arrayConverts older manifest vehicles to 1.0 format.
| Name | Type | Description |
|---|---|---|
| $manifestVehicles | array | A structure representing vehicles from a pre-1.0 manifest format. |
| Type | Description |
|---|---|
| array | Vehicle definition structures converted to 1.0 format. |
- Access
- private
- Static

_convertManifestVer1_1(
array $vehicles
)
:
arrayConverts 1.0 manifest vehicles to 1.1 format.
| Name | Type | Description |
|---|---|---|
| $vehicles | array | A structure representing vehicles from a pre-1.1 manifest format. |
| Type | Description |
|---|---|
| array | Vehicle definition structures converted to 1.1 format. |
- Access
- private
- Static

_pack(
\xPDO $xpdo, string $filename, string $path, string $source
)
:
booleanPack the resources from path relative to source into an archive with filename.
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | &$xpdo A reference to an xPDO instance. |
| $filename | string | A valid zip archive filename. |
| $path | string | An absolute file system path location of the resources to pack. |
| $source | string | A relative portion of path to include in the archive. |
| Type | Description |
|---|---|
| boolean | True if packed successfully. |
- Todo
- Refactor this to be implemented in a service class external to xPDOTransport.
- Uses
- \compression.xPDOZip

_unpack(
\xPDO $xpdo, string $from, string $to
)
:
array | booleanUnpack a zip archive to a specified location.
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | &$xpdo A reference to an xPDO instance. |
| $from | string | An absolute file system location to a valid zip archive. |
| $to | string | A file system location to extract the contents of the archive to. |
| Type | Description |
|---|---|
| array | boolean | An array of unpacked resources or false on failure. |
- Todo
- Refactor this to be implemented in a service class external to xPDOTransport.
- Uses
- \compression.xPDOZip

compareSignature(
\$signature1 $signature1, \$signature2 $signature2
)
:
bool | intCompares two package versions by signature.
| Name | Type | Description |
|---|---|---|
| $signature1 | \$signature1 | A package signature. |
| $signature2 | \$signature2 | Another package signature to compare. |
| Type | Description |
|---|---|
| bool | int | Returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower if the package names in the provided signatures are equal; otherwise returns false. |
- Static

get(
string $objFile, array $options
=
array ()
)
:
\xPDOVehicleGet an {@link xPDOVehicle} instance from an unpacked transport package.
| Name | Type | Description |
|---|---|---|
| $objFile | string | Full path to a payload file to import. The payload file, when included must return a valid {@link xPDOVehicle::$payload}. |
| $options | array | An array of options to be applied when getting the object. |
| Type | Description |
|---|---|
| \xPDOVehicle | The vehicle represented in the file. |

getAttribute(
string $key
)
:
mixedGet an attribute of the package manifest.
| Name | Type | Description |
|---|---|---|
| $key | string | The key of the attribute to retrieve. |
| Type | Description |
|---|---|
| mixed | The value of the attribute or null if it is not set. |

install(
array $options
=
array ()
)
:
booleanInstall vehicles in the package into the sponsor {@link xPDO} instance.
| Name | Type | Description |
|---|---|---|
| $options | array | Install options to be applied to the process. |
| Type | Description |
|---|---|
| boolean | true if the vehicles were successfully installed. |

loadPreserved(
)
:
arrayLoad preserved objects from the previous install().
| Type | Description |
|---|---|
| array | An array of preserved objects, or an empty array. |

manifestVersion(
array $manifest
)
:
stringReturns the structure version of the given manifest array.
| Name | Type | Description |
|---|---|---|
| $manifest | array | A valid xPDOTransport manifest array. |
| Type | Description |
|---|---|
| string | Version string of the manifest structure. |
- Static

pack(
)
:
booleanPack the {@link xPDOTransport} instance in preparation for distribution.
| Type | Description |
|---|---|
| boolean | Indicates if the transport was packed successfully. |

parseSignature(
string $signature
)
:
arrayParse the name and version from a package signature.
| Name | Type | Description |
|---|---|---|
| $signature | string | The package signature to parse. |
| Type | Description |
|---|---|
| array | An array with two elements containing the name and version respectively. |
- Static

put(
mixed $artifact, array $attributes
=
array ()
)
:
voidWrap artifact with an {@link xPDOVehicle} and register in the transport.
| Name | Type | Description |
|---|---|---|
| $artifact | mixed | An artifact to load into the transport. |
| $attributes | array | A set of attributes related to the artifact; these can be anything from rules describing how to pack or unpack the artifact, or any other data that might be useful when dealing with a transportable artifact. |

registerVehicle(
\xPDOVehicle $vehicle
)
:
voidRegister an xPDOVehicle with this transport instance.
| Name | Type | Description |
|---|---|---|
| $vehicle | \xPDOVehicle | &$vehicle A reference to the vehicle being registered. |

retrieve(
$xpdo, $source, $target, $state
=
xPDOTransport::STATE_PACKED
)
:
voidGet an existing {@link xPDOTransport} instance.
| Name | Type | Description |
|---|---|---|
| $xpdo | ||
| $source | ||
| $target | ||
| $state |

setAttribute(
string $key, mixed $value
)
:
voidSet an attribute of the package manifest.
| Name | Type | Description |
|---|---|---|
| $key | string | The key identifying the attribute to set. |
| $value | mixed | The value to set the attribute to. |

store(
mixed $location
)
:
voidStore the package to a specified resource location.
| Name | Type | Description |
|---|---|---|
| $location | mixed | The location to store the package. |
- Todo
- Implement ability to store a package to a specified location, supporting various transport methods.

uninstall(
array $options
=
array ()
)
:
booleanUninstall vehicles in the package from the sponsor {@link xPDO} instance.
| Name | Type | Description |
|---|---|---|
| $options | array | Uninstall options to be applied to the process. |
| Type | Description |
|---|---|
| boolean | true if the vehicles were successfully uninstalled. |

unpack(
\xPDO $xpdo, string $from, string $to, integer $state
=
xPDOTransport::STATE_PACKED
)
:
arrayUnpack the package to prepare for installation and return a manifest.
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | &$xpdo A reference to an xPDO instance. |
| $from | string | Filename of the archive containing the transport package. |
| $to | string | The root path where the contents of the archive should be extracted. This path must be writable by the user executing the PHP process on the server. |
| $state | integer | The current state of the package, i.e. packed or unpacked. |
| Type | Description |
|---|---|
| array | The manifest which is included after successful extraction. |

writeManifest(
)
:
booleanWrite the package manifest file.
| Type | Description |
|---|---|
| boolean | Indicates if the manifest was successfully written. |