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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
<?php
require_once('JavaScriptStatements.php');
require_once('JavaScriptVariable.php');
require_once('JavaScriptLiteral.php');
require_once('JavaScriptString.php');
require_once('JavaScriptNumber.php');
require_once('JavaScriptRegExp.php');
require_once('JavaScriptFunction.php');
require_once('JavaScriptObject.php');
require_once('Destructable.php');
class JavaScriptArray extends Destructable {
protected $args;
protected $resolved_args;
public $length;
public function __construct($args) {
$this->length = count($args);
$this->args = $args;
}
public function __destruct() {
$this->mem_flush('args', 'resolved_args');
}
public function type() {
return 'Array';
}
public function get($position) {
$args = $this->all();
return $args[$position];
}
private function getType($position, $type) {
$args = $this->all();
if ($args[$position] && get_class($args[$position]) == $type) {
return $args[$position];
}
}
public function getVariable($position, $is_global = FALSE) {
if ($variable = $this->getType($position, 'JavaScriptVariable')) {
return (!$is_global || $variable->is_global()) ? $variable->value() : NULL;
}
if ($variable = $this->getType($position, 'JavaScriptLiteral')) {
return $is_global ? NULL : $variable->value();
}
}
public function getString($position) {
if ($string = $this->getType($position, 'JavaScriptString')) {
return $string->value();
}
}
public function getNumber($position) {
if ($number = $this->getType($position, 'JavaScriptNumber')) {
return $number->value();
}
}
public function getRegExp($position) {
if ($regexp = $this->getType($position, 'JavaScriptRegExp')) {
return $regexp->value();
}
}
public function getFunction($position) {
return $this->getType($position, 'JavaScriptFunction');
}
public function getArray($position) {
return $this->getType($position, 'JavaScriptArray');
}
public function getObject($position) {
return $this->getType($position, 'JavaScriptObject');
}
public function all() {
if (isset($this->resolved_args)) {
return $this->resolved_args;
}
$args = array();
foreach ($this->args as $arg) {
if (is_object($arg)) {
$args[] = $arg->convert();
}
}
return ($this->resolved_args = $args);
}
}
?>
|