File: DojoObject.php

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (209 lines) | stat: -rw-r--r-- 6,182 bytes parent folder | download | duplicates (7)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php

require_once('DojoBlock.php');
require_once('DojoFunctionDeclare.php');
require_once('DojoFunctionBody.php');
require_once('Text.php');

class DojoObject extends DojoBlock
{
  private $object = 'DojoObject';

  private $values = array();
  public $declarations = array();
  private $name = '';
  private $body;
  private $extra_block_values = array();
  private $anonymous = false;

  public function __construct($package, $line_number = false, $position = false){
    parent::__construct($package, $line_number, $position);
    $this->body = new DojoFunctionBody($package, $line_number, $position);
  }

  public function __destruct() {
    parent::__destruct();
    unset($this->values);
    unset($this->declarations);
    unset($this->body);
    unset($this->extra_block_values);
    unset($this->anonymous);
  }

  public function setName($name){
    $this->name = $name;
  }

  public function getName(){
    return $this->name;
  }
  
  public function setAnonymous($anonymous){
    $this->anonymous = true;
  }
  
  public function isAnonymous(){
    return $this->anonymous;
  }
  
  public function getBlockCommentKeys(){
    return $this->body->getBlockCommentKeys();
  }
  
  public function getBlockComment($key){
    return $this->body->getBlockComment($key);
  }
  
  public function addBlockCommentKey($key){
    return $this->body->addBlockCommentKey($key);
  }

  public function addBlockCommentKeySet($key){
    return $this->body->addBlockCOmmentKeySet($key);
  }

  public function build(){
    if(!$this->start){
      die("DojoObject->build() used before setting a start position");
    }
  
    $lines = Text::chop($this->package->getCode(), $this->start[0], $this->start[1], false, false, true);
    $end = array($this->start[0], $this->start[1]);
  
    do {
      $lines = Text::chop($this->package->getCode(), $end[0], $end[1], false, false, true);
      foreach ($lines as $line_number => $line) {
        if (preg_match('%^\s*}%', $line)) {
          break;
        }
        if (preg_match('%^(\s*)([a-zA-Z0-9_$]+|"\s+")\s*:%', $line, $match)) {
          if ($end[0] != $this->start[0] && $end[1] != $this->start[1]) {
            if ($end[0]+1 > $line_number) {
              continue;
            }
            $between_lines = Text::chop($this->package->getSource(), $end[0]+1, 0, $line_number, strlen($match[1]), true);
            foreach ($between_lines as $between_line) {
              $this->body->addBlockCommentLine($between_line);
            }
          }
          $end = array($line_number, strlen($match[0]));
          if ($match[2]{0} == '"' || $match[2]{0} == "'") {
            $key = trim(implode(Text::chop($this->package->getSource(), $line_number, strpos($line, '"') + 1, $line_number, strlen($match[0]) - 3, false)));
          }else{
            $key = $match[2];
          }
          break;
        }
      }
      if (!$key) {
        $end = Text::findTermination($lines, '}');
      }else{
        $parameter = new DojoParameter($this->package, $end[0], $end[1], '}');
        $end = $parameter->build();
        $this->values[$key][] = $parameter;
      }
    }
    while ($lines[$end[0]]{$end[1]} != '}');
    
    $this->setEnd($end[0], $end[1]);
    return $end;
  }
  
  public function getKeys(){
    if (!$this->values) {
      $this->build();
    }
    return array_keys($this->values);
  }
  
  public function getValues(){
    if(!$this->values){
      $this->build();
    }
    return $this->values;
  }
  
  public function rollOut(&$output, $item_type = 'Object'){
    $package_name = $this->package->getPackageName();
    $name = $this->getName();
    $variables = array();
    $check_keys = array('summary','description');

    foreach($this->getValues() as $key => $values){
      foreach ($values as $value) {
        if($value->isA(DojoFunctionDeclare)){
          $function = $value->getFunction();
          $this->declarations[] = $function;
          if(!$function->isConstructor()){
            $function->setFunctionName("{$name}.{$key}");
            $function->rollOut($output);
          }
        }elseif ($value->isA(DojoObject)){
          $object = $value->getObject();
          $object->setName("{$name}.{$key}");
          $object->rollOut($output);
        }else{
          $this->addBlockCommentKey($key);
          $full_variable_name = "{$name}.{$key}";
          if (empty($output[$full_variable_name])) {
            $output[$full_variable_name] = array();
          }
        $variables[] = $key;
        }
      }
    }

    foreach($check_keys as $ck){
      $this->addBlockCommentKey($ck);
    }
    $this->addBlockCommentKeySet("example");

    $output[$name]['type'] = $item_type;
    if ($comment = $this->getBlockComment('summary')) {
      $output[$name]['summary'] = $comment;
    }
    if ($comment = $this->getBlockComment('description')) {
      $output[$name]['description'] = $comment;
    }
    $examples = $this->getBlockComment('example');
    if ($examples && count($examples)) {
      $output[$name]['examples'] = $examples;
    }

    foreach($variables as $key){
      $full_variable_name = "{$name}.{$key}";
      if($comment = $this->getBlockComment($key)){
        list($tags, $parameter_type, $options, $summary) = DojoFunctionDeclare::parseVariable($comment);
        if (!empty($tags)) {
          $output[$full_variable_name]['tags'] = $tags;
        }
        if (!empty($parameter_type)) {
          $output[$full_variable_name]['type'] = $parameter_type;
        }
        $output[$full_variable_name]['summary'] = $summary;
      }
    }

    foreach($check_keys as $ck){
      if(!$this->isAnonymous() && $comment = $this->getBlockComment($ck)){
        $output[$name][$ck] = $comment; 
      }
    }
  }
  
  public function removeCodeFrom($lines){
    for($i = $this->start[0]; $i <= $this->end[0]; $i++){
      $line = $lines[$i];
      if($i == $this->start[0]){
        $lines[$i] = Text::blankOutAt($line, $this->start[1]);
      }elseif ($i == $this->end[0]){
        $lines[$i] = Text::blankOutAt($line, 0, $this->end[1]);
      }else{
        $lines[$i] = Text::blankOut($line, $line);
      } 
    }
    return $lines;
  }
}

?>