cargo

cargo implements a container class of sorts. You can use it to hold whatever type of data you wish to store. There can be multiple instances of the cargo class and all can be referenced by a static method that returns the instance by name. This makes it handy to store certain things in one cargo while storing other things in a separate cargo. To aid in storing cargo objects to a database, the asJson() and loadFromJson() methods are useful.

Parent Class

None


Static Properties

$instances
This array contains a reference to all the instances of cargo that have been created. Normally you would not want to access this directly, but instead you should probably use the getInstances() method.
Data Type: array
Default Value: Empty array

Static Methods

mixed getInstance( string $name )
Allows your application to get a specific cargo instance from the list of all cargo’s created
Parameters:
$name (string) is the name of the instance you wish to obtain. Default: ‘main’
Returns:
A cargo instance with the name you specified or null if it does not exist
Example:

Public Properties

$vars
This is an associative (key->value pairs) array containing all the data you have stored in this instance of cargo. Under normal circumstances, you really shouldn’t access this directly either. Use either the getter or setter methods.
Data Type: array
Default Value: Empty array
$name
This string is the name for the current instance. You definitively should not set this property manually, but instead you should use the setName() method.
Data Type: string
Default Value: ‘main’

Public Methods

\ipinga\cargo __construct( string $name )
This is the class constructor. You can optionally provide a name for the instance you are creating.
Parameters:
$name (string) is the name of the instance you wish to create. Default: ‘main’
Returns:
A cargo instance
Example:
mixed __get( string $index )
Retrieves the $value associated with the $index
Parameters:
$index (string) is the key to the $value you wish to retrieve
Returns:
(mixed) Whatever data is associated with the $index or null if the $index doesn’t exist.
Example:
mixed __set( string $index, mixed $value )
Stores the $value in the cargo instance associated to the $index
Parameters:
$index (string) is the key you wish to store the $value under
$value (mixed) is the value to associate with the $index
Returns:
$value (mixed)
Example:
void clear( string $index )
Removes an $index and its associated data
Parameters:
$index (string) is the key you wish to remove
Returns:
null
Example:
void setName( string $name )
Sets the name for the current instance
Parameters:
$name (string) is the name you wish to assign to the instance. Default: ‘main’
Returns:
null
Example:
string asJson()
Sets the name for the current instance
Parameters:
None
Returns:
A json string representing the $vars internal array
Example:
array loadFromJson( string $json)
Loads the internal $vars array from the supplied json string
Parameters:
$json (string) is a json encoded string used to replace the internal $vars
Returns:
A reference to the $vars internal array
Example:
array keys()
Returns a list of all the available keys in this instance of cargo
Parameters:
None
Returns:
An array of all the keys in this cargo
Example: