Setters and Getters

Setter is special top level class that is capable of manipulating or protecting pre-defined keys across the web application. This system can be used within the web application to store and even protect values which must not be tampered with unless certain strict conditions are met. It also prevents the use of modifiable php variables and keeps defined values in their own specific division, away from being updated without real known intent. The idea behind this is to protect and safeguard values in an entirely desired separate top level storage spaces away from variables such that they can be obtained later within the application. The setter system (or class) involves three specific methods SET(), GET() and MOD() which are applied synergetically. This means that for any defined value to be properly managed, there has to be a top level to down level relationship between values. Values that are defined at top level can then be handled or managed in a manner desired by the developer. This system can be mostly used to keep track of specific value properties. For example, while php variables may be updated as desired along the code, setter values can be prevented from being updated at a low level if certain conditions are not met. This system also makes it easier to detect when a value which must not change is being modified more than once or when a function or class is running more than once.

Defining Values
In order to define a new value, the SET() method has to be called at the top level. This method takes two arguments. The syntax is shown below:
Syntax: SETTER::SET()
  SETTER::SET(KEY, VALUE, SECURE)  
  
    where: 

     KEY : Protected Key
     VALUE : Key's value
     SECURE : secure hash/string
  
                                    
The KEY above is the value (or variable) that needs to be protected while the VALUE is the content of that KEY. The SECURE defines the security level of the KEY. If SECURE is set as TRUE, then the KEY defined cannot be updated or modified after it has been defined. This turns the KEY to a read-only key. Any attempt to use SETTER::MOD() to modify the key's value, an error will be thrown preventing such activity. However, if the SECURE value is a non-empty string, then it is assumed to be a secure hash string. Whenever secure hash strings are used, then such hash must be provided by the SETTER::MOD() in order for the value to be updated. If the MOD() (i.e modifier) hash does not match the one used to secure the KEY, then an error is thrown. Also, whenever a new value is defined, it cannot be redefined using SETTER::SET() again. Instead, the SETTER::MOD() must be called.

Modifying Key's Value
In other to modify any key, the SETTER::MOD() method has to be called. If this method is called before a value is set, an error will be thrown. It takes three argument and the syntax is shown below:
Syntax: SETTER::MOD()
  SETTER::MOD(KEY, VALUE, HASH)  
  
    where: 

     KEY : Protected Key
     VALUE : Key's new value
     HASH : secure hash string
  
                                    
The KEY above is the value (or variable) that needs to be modified or updated while the VALUE is the new content of that KEY. The HASH defines the secure hash string used to set the key, if defined. This means that whenever secure hash strings are used to lock a value when defined using SETTER::SET(), then such hash must be provided by the SETTER::MOD() in order for the value to be updated. If the MOD() (i.e modifier) hash does not match the one used to secure the KEY, then an error is thrown.

Getting Defined Key's Value
In other to fetch any defined key, the SETTER::GET() method has to be called. If this method is called before a value is set, an error will be thrown. This method takes two argument. The syntax is shown below:
Syntax: SETTER::GET()
  SETTER::GET(KEY, HASH)  
  
    where: 

     KEY : Protected Key
     HASH : secure hash string
  
                                    
The KEY above is the value (or variable) whose value needs to be fetched. Whenever a key is secured with an hash, then the HASH string must be provided before the value of that key can be obtained. If the value of the HASH does not match, an error is thrown. Also, if a KEY is not secured in SET() but HASH was provided in GET(), although the value will be returned, an error will still be triggered discouraging such activity.

Detecting Existing Key
In other to prevent errors which may occur from SETTER::SET() if the key has already been defined, we have to check if a key already exists by using the method SETTER::EXIST(). This will only return true if a key already exists. The usage is shown below:
Usage: SETTER::EXIST()

  if( !SETTER::EXISTS('key') ) {

    SETTER::SET('key', 'value');

  }
                                    
The code above will only set the key if it does not already exist.

Setter Helper Functions
There are two provided helper functions for running the Setter system. These functions are SET() and GET() functions. Although, we don't have any MOD() helper function, the SET() function is build to handle updates in the manner SETTER::MOD() will handle it. The SET() function naturally checks if a varible is updateable or not previously set before setting them and it takes the same parameter as the SETTER::SET() or SETTER::MOD() methods. This obviously save more time. The GET() method obtains the value of a previously defined key.
Example: SET and GET
  SET('NAME 1', 'Felix');  
  SET('NAME 2', 'Rolland', true);  
  SET('NAME 3', 'Charley', 'hash123');  

  GET('NAME 1') // returns Felix
  GET('NAME 1', 'hash234') // returns Felix, but triggers error

  GET('NAME 2') // returns Rolland
  GET('NAME 2', 'hash234') // returns Rolland, but triggers error

  GET('NAME 3') // invalid hash triggers error
  GET('NAME 3', 'hash123') // returns Charley
  GET('NAME 3', 'hash234') // invalid hash triggers error 
                                    
The example above best explains how the SET and GET functions work while the example below explains how modifications work.
Example 2: Modifying values
  SET('NAME 1', 'Felix');  
  SET('NAME 2', 'Rolland', true);  
  SET('NAME 3', 'Charley', 'hash123');  

  SET('NAME 1', 'New Felix') // allowed

  SET('NAME 2', 'New Rolland') // denied (read-only)

  SET('NAME 3', 'New Charley', 'hash123') // allowed (valid hash)
  SET('NAME 3') // denied (invalid hash)
  SET('NAME 3', 'hash234') // denied (invalid hash)