all files / src/context/ variables.js

53.85% Statements 7/13
0% Branches 0/2
25% Functions 1/4
53.85% Lines 7/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                      1× 1× 1×       1×                       1×           1×       1×  
/*!
 * Copyright (C) 2017 Glayzzle (BSD3 License)
 * @authors https://github.com/glayzzle/php-transpiler/graphs/contributors
 * @url http://glayzzle.com
 */
'use strict';
 
/**
 * Handles variables (from global context)
 * @constructor Variables
 */
var Variables = function(php) {
  this.items = {};
  this.php = php;
};
 
// gets a variable
Variables.prototype.get = function(name) {
  if (!this.items.hasOwnProperty(name)) {
    this.php.trigger_error(
      'Undefined variable: '+name
      , this.php.constant('E_NOTICE')
    );
  } else {
    return this.items[name];
  }
};
 
// sets a variable
Variables.prototype.set = function(name, value) {
  this.items[name] = value;
  return value;
};
 
// check if a variable exists
Variables.prototype.has = function(name) {
  return this.items.hasOwnProperty(name);
};
 
module.exports = Variables;