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
= 0
Indicates how pre-existing objects are treated on install/uninstall.
- integer
integer
ARCHIVE_WITH_DEFAULT
= 0
Indicates 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.
null
Details- Type
- string
string
$path= 'null'
The physical location of the transport package.
null
Details- Type
- string
string
$signature= 'null'
A unique signature to identify the package.
null
Details- Type
- string
- Access
- public
integer
$state= 'null'
Indicates the state of the xPDOTransport instance.
null
Details- 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.
null
Details- Type
- string
\xPDO
$xpdo= 'null'
An {@link xPDO} reference controlling this transport instance.
null
Details- Type
- \xPDO
- Access
- public
Methods
__construct(
\xPDO $xpdo, string $signature, string $path, array $options
=
array()
)
:
void
Prepares 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
)
:
array
Converts 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
)
:
array
Converts 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
)
:
boolean
Pack 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 | boolean
Unpack 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 | int
Compares 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 ()
)
:
\xPDOVehicle
Get 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
)
:
mixed
Get 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 ()
)
:
boolean
Install 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(
)
:
array
Load preserved objects from the previous install().
Type | Description |
---|---|
array | An array of preserved objects, or an empty array. |
manifestVersion(
array $manifest
)
:
string
Returns 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(
)
:
boolean
Pack the {@link xPDOTransport} instance in preparation for distribution.
Type | Description |
---|---|
boolean | Indicates if the transport was packed successfully. |
parseSignature(
string $signature
)
:
array
Parse 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 ()
)
:
void
Wrap 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
)
:
void
Register 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
)
:
void
Get an existing {@link xPDOTransport} instance.
Name | Type | Description |
---|---|---|
$xpdo | ||
$source | ||
$target | ||
$state |
setAttribute(
string $key, mixed $value
)
:
void
Set 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
)
:
void
Store 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 ()
)
:
boolean
Uninstall 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
)
:
array
Unpack 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(
)
:
boolean
Write the package manifest file.
Type | Description |
---|---|
boolean | Indicates if the manifest was successfully written. |