source: Dev/trunk/src/client/util/docscripts/lib/parser2/JavaScriptArray.php

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.3 KB
Line 
1<?php
2
3require_once('JavaScriptStatements.php');
4require_once('JavaScriptVariable.php');
5require_once('JavaScriptLiteral.php');
6require_once('JavaScriptString.php');
7require_once('JavaScriptNumber.php');
8require_once('JavaScriptRegExp.php');
9require_once('JavaScriptFunction.php');
10require_once('JavaScriptObject.php');
11require_once('Destructable.php');
12
13class JavaScriptArray extends Destructable {
14  protected $args;
15  protected $resolved_args;
16  public $length;
17
18  public function __construct($args) {
19    $this->length = count($args);
20    $this->args = $args;
21  }
22
23  public function __destruct() {
24    $this->mem_flush('args', 'resolved_args');
25  }
26
27  public function type() {
28    return 'Array';
29  }
30
31  public function get($position) {
32    $args = $this->all();
33    return $args[$position];
34  }
35
36  private function getType($position, $type) {
37    $args = $this->all();
38        if ($args[$position] && get_class($args[$position]) == $type) {
39      return $args[$position];
40    }
41  }
42
43  public function getVariable($position, $is_global = FALSE) {
44    if ($variable = $this->getType($position, 'JavaScriptVariable')) {
45      return (!$is_global || $variable->is_global()) ? $variable->value() : NULL;
46    }
47    if ($variable = $this->getType($position, 'JavaScriptLiteral')) {
48      return $is_global ? NULL : $variable->value();
49    }
50  }
51
52  public function getString($position) {
53    if ($string = $this->getType($position, 'JavaScriptString')) {
54      return $string->value();
55    }
56  }
57
58  public function getNumber($position) {
59    if ($number = $this->getType($position, 'JavaScriptNumber')) {
60      return $number->value();
61    }
62  }
63
64  public function getRegExp($position) {
65    if ($regexp = $this->getType($position, 'JavaScriptRegExp')) {
66      return $regexp->value();
67    }
68  }
69
70  public function getFunction($position) {
71    return $this->getType($position, 'JavaScriptFunction');
72  }
73
74  public function getArray($position) {
75    return $this->getType($position, 'JavaScriptArray');
76  }
77
78  public function getObject($position) {
79    return $this->getType($position, 'JavaScriptObject');
80  }
81
82  public function all() {
83    if (isset($this->resolved_args)) {
84      return $this->resolved_args;
85    }
86
87    $args = array();
88    foreach ($this->args as $arg) {
89      if (is_object($arg)) {
90        $args[] = $arg->convert();
91      }
92    }
93
94    return ($this->resolved_args = $args);
95  }
96}
97
98?>
Note: See TracBrowser for help on using the repository browser.