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
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
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 existExample:
1 |
$myCargo = \ipinga\cargo::getInstance('some_name'); |
Public Properties
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
setName()
method.Data Type: string
Default Value: ‘main’
Public Methods
Parameters:
$name
(string) is the name of the instance you wish to create. Default: ‘main’Returns:
A cargo instance
Example:
1 |
$myCargo = new \ipinga\cargo('my_cargo'); |
$value
associated with the $index
Parameters:
$index
(string) is the key to the $value
you wish to retrieveReturns:
(mixed) Whatever data is associated with the
$index
or null
if the $index
doesn’t exist.Example:
1 2 3 4 |
$myCargo = new \ipinga\cargo('my_cargo'); $myCargo->some_index = 'whatever data you want here'; echo $myCargo->some_index; // outputs: 'whatever data you want here' |
$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:
1 2 3 4 |
$myCargo = new \ipinga\cargo('my_cargo'); $myCargo->some_index = 'whatever data you want here'; echo $myCargo->some_index; // outputs: 'whatever data you want here' |
$index
and its associated dataParameters:
$index
(string) is the key you wish to removeReturns:
null
Example:
1 2 3 4 5 6 7 |
$myCargo = new \iPinga\cargo('my_cargo'); $myCargo->some_index = 'whatever data you want here'; echo $myCargo->some_index; // outputs: 'whatever data you want here' $myCargo->clear('some_index'); echo $myCargo->some_index; // outputs: null |
Parameters:
$name
(string) is the name you wish to assign to the instance. Default: ‘main’Returns:
null
Example:
1 2 3 |
$myCargo = \ipinga\cargo::getInstance('my_cargo'); $myCargo->setName('something_else_now'); |
Parameters:
None
Returns:
A json string representing the
$vars
internal arrayExample:
1 2 3 4 5 |
$myCargo = \ipinga\cargo::getInstance('my_cargo'); $myCargo->helloString = 'Hello World!'; echo $myCargo->helloString; // outputs: { "helloString": "Hello World!" } |
$vars
array from the supplied json stringParameters:
$json (string) is a json encoded string used to replace the internal
$vars
Returns:
A reference to the
$vars
internal arrayExample:
1 2 3 4 5 |
$myCargo = \ipinga\cargo::getInstance('my_cargo'); $myCargo->loadFromJson( '{ "helloString": "Hello World!" }' ); echo $myCargo->helloString; // outputs: "Hello World!" |
cargo
Parameters:
None
Returns:
An array of all the keys in this
cargo
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$myCargo = new \ipinga\cargo('my_cargo'); $myCargo->key1 = 'this is number one'; $myCargo->key2 = 15; $myCargo->key3 = 'this is the third one'; foreach ($myCargo as $keyName) { echo $keyName. '<br/>'; } Outputs: key1 key2 key3 |