1 | <?php |
---|
2 | |
---|
3 | require_once('DojoFunctionDeclare.php'); |
---|
4 | require_once('DojoParameters.php'); |
---|
5 | require_once('Text.php'); |
---|
6 | |
---|
7 | class DojoExecutedFunction extends DojoFunctionDeclare |
---|
8 | { |
---|
9 | private $object = 'DojoExecutedFunction'; |
---|
10 | |
---|
11 | public function build(){ |
---|
12 | if(!$this->start){ |
---|
13 | die("DojoExecutedFunction->build() used before setting a start position"); |
---|
14 | } |
---|
15 | if($this->end){ |
---|
16 | return $this->end; |
---|
17 | } |
---|
18 | |
---|
19 | $lines = Text::chop($this->package->getCode(), $this->start[0], $this->start[1]); |
---|
20 | $line = $lines[$this->start[0]]; |
---|
21 | |
---|
22 | $this->start = array($this->start[0], strpos($line, 'function')); |
---|
23 | |
---|
24 | $this->end = parent::build(); // Basically, the end array here will hold the position of the final } in the function declaration. |
---|
25 | |
---|
26 | $parameters = $this->getParameters(); |
---|
27 | if (count($parameters) && ($pos = strpos($lines[$this->end[0]], '(')) !== false) { |
---|
28 | $arguments = new DojoParameters($this->package); |
---|
29 | $arguments->start = array($this->end[0], $pos); |
---|
30 | $arguments->build(); |
---|
31 | $arguments = $arguments->getParameters(); |
---|
32 | foreach ($parameters as $pos => $parameter) { |
---|
33 | if ($arguments[$pos]) { |
---|
34 | $argument = $arguments[$pos]; |
---|
35 | if ($argument->isA(DojoVariable) && $parameter->isA(DojoVariable)) { |
---|
36 | if (preg_match('%(^|\|\|)([a-zA-Z0-9_.$]+)(\|\||$)%', $argument->getVariable(), $match)) { |
---|
37 | $this->body->addResolvedParameter($parameter->getVariable(), $match[2]); |
---|
38 | } |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|
42 | } |
---|
43 | $lines = Text::chop($this->package->getCode(), $this->end[0], $this->end[1], false, false, true); |
---|
44 | $closed = false; |
---|
45 | foreach($lines as $line_number => $line){ |
---|
46 | $offset = 0; |
---|
47 | if($line_number == $this->end[0]){ |
---|
48 | $offset = $this->end[1]; |
---|
49 | } |
---|
50 | if(preg_match('%\S%', $line, $match, PREG_OFFSET_CAPTURE, $offset)){ |
---|
51 | if(!$closed){ |
---|
52 | if($match[0][0] != ')'){ |
---|
53 | return false; |
---|
54 | }else{ |
---|
55 | $closed = true; |
---|
56 | $offset = $match[0][1] + 1; |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | if(preg_match('%\S%', $line, $match, PREG_OFFSET_CAPTURE, $offset)){ |
---|
61 | if($closed){ |
---|
62 | if($match[0][0] != '('){ |
---|
63 | return false; |
---|
64 | }else{ |
---|
65 | $parameters = new DojoParameters($this->package, $line_number, $match[0][1]); |
---|
66 | $end = $parameters->build(); |
---|
67 | break; |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | return $end; |
---|
73 | } |
---|
74 | |
---|
75 | public function rollOut(&$output) { |
---|
76 | if ($this->getFunctionName()) { |
---|
77 | parent::rollOut($output); |
---|
78 | } |
---|
79 | |
---|
80 | $execution_variables = $this->getVariableNames($this->getFunctionName()); |
---|
81 | foreach ($execution_variables as $execution_variable) { |
---|
82 | if (empty($output[$execution_variable])) { |
---|
83 | $output[$execution_variable] = array(); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | $execution_declarations = $this->getFunctionDeclarations(); |
---|
88 | foreach ($execution_declarations as $declaration) { |
---|
89 | $declaration->rollOut($output); |
---|
90 | } |
---|
91 | |
---|
92 | $execution_objects = $this->getObjects(); |
---|
93 | foreach ($execution_objects as $object) { |
---|
94 | $object->rollOut($output); |
---|
95 | } |
---|
96 | unset($object); |
---|
97 | unset($execution_objects); |
---|
98 | |
---|
99 | if ($this->getFunctionName()) { |
---|
100 | $instance_declarations = $this->getInstanceFunctions($this->getFunctionName()); |
---|
101 | foreach ($instance_declarations as $declaration) { |
---|
102 | $declaration->rollOut($output); |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | ?> |
---|