Class \Scrivo\IdLabel
Class to represent id-label pairs.
Object id's can be labeled in Scrivo, these labels then can be used as constants in the template code. For instance suppose that the contact page in a site has id 12349 then this id can be labeled "CONTACT". When loading the page the label can be used instead of the id, thus allowing for clearer program code. For example:
\Scrivo\CachedData::load($context, 12349); vs \Scrivo\CachedData::load($context, $context->labels->CONTACT);
Also deletion of labeled objects is not allowed: defining a label means that the object has a special function in a project, deleting is likely to cause an inconsistent project state.
You can retrieve a labelled id by referring to its label as a member of of an IdLabel object. A Scrivo Context object contains an IdLabel object with all labelled ids for the contexts instance.
$cfg = new Scrivo\Config(); $context = new Scrivo\Context($cfg, \Scrivo\User::PRIMARY_ADMIN_ID); \Scrivo\CachedData::load($context, $context->labels->CONTACT);
You can add and delete values using the set member:
// Set an id-label pair $context->labels->set($context, 123, \Scrivo\String("CONTACT")); // Update an id-label pair $context->labels->set($context, 123, \Scrivo\String("CONTACT_B")); // Delete an id-label pair $context->labels->set($context, 123);
Implements
Defined in:
IdLabel.php.
Attr. | Name / Description |
---|---|
protected |
IdLabel($context) Create an IdLabel object, the object will contain all the id-label pairs that are defined for the given instance. |
Attr. | Type | Name | Description |
---|---|---|---|
private | \..\int[] | $labels | Array that holds the id-label pairs. |
Attr. | Type | Name / Description |
---|---|---|
public | int |
__get($label) Accessor method for id-label members. |
public | boolean |
__isset($label) Test if a particular label was set. |
public |
current() Get the current label when iterating. |
|
public |
key() Get the key of the current label when iterating. |
|
public |
next() Get the next label when iterating. |
|
public |
rewind() Rewind the labels array so iterating will start at the beginning again. |
|
public static |
select($context) Select the id label pairs for a given context. |
|
public static |
set($context, $id, $label) Set an id-label pair. |
|
public |
valid() Check if the current key is valid. |
Constructor
- protected IdLabel(\Scrivo\Context $context)
-
Create an IdLabel object, the object will contain all the id-label pairs that are defined for the given instance.
Parameters:
Type Name Def. Description \Scrivo\Context $context A Scrivo context.
View source: IdLabel.php line 86.
Members
- private \Scrivo\int[string] $labels
-
Array that holds the id-label pairs.
View source: IdLabel.php line 78.
Methods
- public int __get(string $label)
-
Accessor method for id-label members.
Parameters:
Type Name Def. Description string $label The label to retrieve the object id for.
Returns:
int Accessor method for id-label members.
View source: IdLabel.php line 142.
- public boolean __isset(string $label)
-
Test if a particular label was set.
Parameters:
Type Name Def. Description string $label The label to test.
Returns:
boolean Test if a particular label was set.
View source: IdLabel.php line 131.
- public current()
-
Get the current label when iterating.
View source: IdLabel.php line 222.
- public key()
-
Get the key of the current label when iterating.
View source: IdLabel.php line 229.
- public next()
-
Get the next label when iterating.
View source: IdLabel.php line 236.
- public rewind()
-
Rewind the labels array so iterating will start at the beginning again.
View source: IdLabel.php line 215.
- public static select(\Scrivo\Context $context)
-
Select the id label pairs for a given context.
Parameters:
Type Name Def. Description \Scrivo\Context $context A Scrivo context.
View source: IdLabel.php line 108.
- public static set(\Scrivo\Context $context, int $id, \Scrivo\String $label=null)
-
Set an id-label pair.
Use this method to insert/update/delete an id-label pair in the database. To delete a value just ommit the $label parameter.
Parameters:
Type Name Def. Description \Scrivo\Context $context A valid Scrivo context.
int $id An object id.
\Scrivo\String $label null A label for the object id.
Throws:
Exception Type Description \Scrivo\ApplicationException If the given label is not unique. View source: IdLabel.php line 161.
- public valid()
-
Check if the current key is valid.
View source: IdLabel.php line 243.
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013