示例#1
0
 /**
  * Get or inject a MAB API variable
  * 
  * 1. As a getter (option 1): 
  * ==========================
  * Usage: $this->MAB('name'); // name is an API variable name
  * If 'name' does not exist, a WireException will be thrown.
  * 
  * 2. As a getter (option 2): 
  * ==========================
  * Usage: $this->MAB()->name; // name is an API variable name
  * Null will be returned if API var does not exist (no Exception thrown).
  * 
  * 3. As a setter: 
  * ===============
  * $this->MAB('name', $value); 
  * $this->MAB('name', $value, true); // lock the API variable so nothing else can overwrite it
  * $this->MAB()->set('name', $value); 
  * $this->MAB()->set('name', $value, true); // lock the API variable so nothing else can overwrite it
  * 
  * @param string $name Name of API variable to retrieve, set, or omit to retrieve the master ProcessWire object
  * @param null|mixed $value Value to set if using this as a setter, otherwise omit.
  * @param bool $lock When using as a setter, specify true if you want to lock the value from future changes (default=false)
  * @return mixed|ProcessWire
  * @throws WireException
  * 
  *
  */
 public function MAB($name = '', $value = null, $lock = false)
 {
     if (is_null(self::$fuel)) {
         self::$fuel = new MAB_Fuel();
     }
     if (!is_null($value)) {
         return self::$fuel->set($name, $value, $lock);
     }
     if (empty($name)) {
         return self::$fuel->MAB;
     }
     $value = self::$fuel->{$name};
     if (is_null($value)) {
         throw new MAB_Exception("Unknown API variable: {$name}");
     }
     return $value;
 }
示例#2
0
/**
 * Return a MAB API variable, or NULL if it doesn't exist
 *
 * Like the fuel() function, except that ommitting $name returns the current MabStats instance rather than the fuel.
 * The distinction may not matter in most cases.
 *
 * @param string $name If ommitted, returns a MabStats_Fuel object with references to all the fuel.
 * @return mixed MAB_Fuel value if available, NULL if not. 
 *
 */
function MAB($name = 'MAB')
{
    return MAB_Base::getFuel($name);
}