public function rollOut(&$output) { if ($this->getFunctionName()) { parent::rollOut($output); } $execution_variables = $this->getVariableNames($this->getFunctionName()); foreach ($execution_variables as $execution_variable) { if (empty($output[$execution_variable])) { $output[$execution_variable] = array(); } } $execution_declarations = $this->getFunctionDeclarations(); foreach ($execution_declarations as $declaration) { $declaration->rollOut($output); } $execution_objects = $this->getObjects(); foreach ($execution_objects as $object) { $object->rollOut($output); } unset($object); unset($execution_objects); if ($this->getFunctionName()) { $instance_declarations = $this->getInstanceFunctions($this->getFunctionName()); foreach ($instance_declarations as $declaration) { $declaration->rollOut($output); } } }
public function build() { if (!$this->start) { die("DojoExecutedFunction->build() used before setting a start position"); } if ($this->end) { return $this->end; } $lines = Text::chop($this->package->getCode(), $this->start[0], $this->start[1]); $line = $lines[$this->start[0]]; $this->start = array($this->start[0], strpos($line, 'function')); $this->end = parent::build(); $lines = Text::chop($this->package->getCode(), $this->end[0], $this->end[1], false, false, true); $closed = false; foreach ($lines as $line_number => $line) { $offset = 0; if ($line_number == $this->end[0]) { $offset = $this->end[1]; } if (preg_match('%\\S%', $line, $match, PREG_OFFSET_CAPTURE, $offset)) { if (!$closed) { if ($match[0][0] != ')') { return false; } else { $closed = true; $offset = $match[0][1] + 1; } } } if (preg_match('%\\S%', $line, $match, PREG_OFFSET_CAPTURE, $offset)) { if ($closed) { if ($match[0][0] != '(') { return false; } else { $parameters = new DojoParameters($this->package, $line_number, $match[0][1]); $end = $parameters->build(); break; } } } } return $end; }
public function removeCodeFrom($lines) { $keys = array_keys($lines); $first = array_shift($keys); $last = array_pop($keys); for ($i = $first; $i <= $last; $i++) { $line = $lines[$i]; if (preg_match('%function\\s*\\([^)]*\\)\\s*{%', $line, $match, PREG_OFFSET_CAPTURE)) { $declaration = new DojoFunctionDeclare($this, $i, $match[0][1]); list($i, ) = $declaration->build(); $lines = $declaration->removeCodeFrom($lines); } elseif (preg_match('%^.*(with|switch)\\s*\\([^(]*\\)\\s*{%', $line, $match)) { $with_lines = Text::chop($lines, $i, strlen($match[0]) - 1, null, null, true); list($end_line, $end_pos) = Text::findTermination($with_lines, '}', '{}()[]'); for ($j = $i; $j <= $end_line; $j++) { $line = $lines[$j]; if ($j == $i) { $lines[$j] = Text::blankOutAt($line, strlen($match[0]) - 1); } elseif ($j == $end_line) { $lines[$j] = Text::blankOutAt($line, 0, $end_pos); } else { $lines[$j] = Text::blankOut($line, $line); } } } } return $lines; }
public function rollOut(&$output) { // Basically, any this.variables in here never impact this object, they apply to the "this" function $masquerading_as_function = $function_name = $this->getFunctionName(); if (substr($masquerading_as_function, 0, 7) == 'window.') { $masquerading_as_function = $function_name = substr($masquerading_as_function, 7); } $check_keys = array('summary', 'description', 'returns', 'tags', 'exceptions'); if (!empty($output[$function_name]['aliases'])) { unset($output[$function_name]['aliases']); // This is implemented, it aliases nothing. } if ($this->isThis()) { $masquerading_as_function = $this->getThis(); } $output[$function_name]['type'] = 'Function'; if (!empty($output[$masquerading_as_function])) { $output[$masquerading_as_function]['type'] = 'Function'; } if ($aliases = $this->getAliases()) { foreach ($aliases as $alias) { if (empty($output[$alias])) { $output[$alias]['aliases'] = $function_name; } } } $parameters = $this->getParameters(); foreach ($parameters as $parameter) { if ($parameter->isA(DojoVariable)) { $parameter_name = $parameter->getVariable(); $parameter_type = $parameter->getType(); if (strpos($parameter_type, '?')) { $parameter_type = substr($parameter_type, 0, strlen($parameter_type) - 1); $output[$function_name]['parameters'][$parameter_name]['optional'] = true; } if (strpos($parameter_type, '...')) { $parameter_type = substr($parameter_type, 0, strlen($parameter_type) - 3); $output[$function_name]['parameters'][$parameter_name]['repeating'] = true; } if (empty($output[$function_name]['parameters'][$parameter_name]['type']) || $parameter_type) { $output[$function_name]['parameters'][$parameter_name]['type'] = $parameter_type; } $this->addBlockCommentKey($parameter->getVariable()); } } if ($this->isAnonymous()) { $output[$function_name]['initialized'] = true; $declarations = $this->body->getExternalizedFunctionDeclarations($function_name); foreach ($declarations as $declaration) { $declaration->rollout($output); } $variables = $this->body->getExternalizedInstanceVariableNames($function_name, $this->getParameterNames()); foreach ($variables as $variable) { $output[$function_name . '.' . $variable]['instance'] = $function_name; } $variables = $this->body->getExternalizedVariableNames($function_name, $this->getParameterNames()); foreach ($variables as $variable) { list($first, ) = explode('.', $variable, 2); if (!is_array($output[$function_name]['parameters']) || !array_key_exists($first, $output[$function_name]['parameters'])) { if (empty($output[$variable])) { $output[$variable] = array(); } } } } foreach ($check_keys as $ck) { $this->addBlockCommentKey($ck); } $this->addBlockCommentKeySet('example'); $check_keys[] = 'example'; $output[$function_name]['source'] = $this->getSource(); $all_variables = array(); $instance_variables = $this->getInstanceVariableNames(); foreach ($instance_variables as $instance_variable) { $this->addBlockCommentKey($instance_variable); $all_variables[] = $instance_variable; $full_variable_name = "{$masquerading_as_function}.{$instance_variable}"; $output[$full_variable_name]['instance'] = $masquerading_as_function; } $instance_functions = $this->getInstanceFunctions($function_name); foreach ($instance_functions as $instance_function) { $instance_function->rollOut($output); $output[$instance_function->getFunctionName()]['instance'] = $function_name; } $comment_keys = $this->getBlockCommentKeys(); foreach ($comment_keys as $key) { if ($key == 'returns') { $output[$function_name]['return_summary'] = $this->getBlockComment($key); } elseif (in_array($key, $check_keys)) { $output[$function_name][$key] = $this->getBlockComment($key); } if (in_array($key, $all_variables) && ($comment = $this->getBlockComment($key))) { list($type, $comment) = preg_split('%\\s+%', $comment, 2); $type = preg_replace('%(^[^a-zA-Z0-9._$]|[^a-zA-Z0-9._$?]$)%', '', $type); if ($type) { $output[$function_name . '.' . $key]['type'] = $type; } $output[$function_name . '.' . $key]['summary'] = $comment; } if (!empty($output[$function_name]['parameters']) && array_key_exists($key, $output[$function_name]['parameters']) && ($comment = $this->getBlockComment($key))) { list($tags, $parameter_type, $options, $summary) = DojoFunctionDeclare::parseVariable($comment); // If type is specified in the parameters, and it doesn't // match the first word in this comment block, assume that // this first word doesn't represent its type if (!empty($output[$function_name]['parameters'][$key]['type']) && $parameter_type != $output[$function_name]['parameters'][$key]['type']) { $summary = $comment; $parameter_type = $output[$function_name]['parameters'][$key]['type']; } $output[$function_name]['parameters'][$key] = array_merge($output[$function_name]['parameters'][$key], $options); $output[$function_name]['parameters'][$key]['type'] = $parameter_type; $output[$function_name]['parameters'][$key]['summary'] = htmlentities($summary); } } $returns = $this->getReturnComments(); if (count($returns)) { $output[$function_name]['returns'] = implode('|', $returns); } if ($output[$function_name]['example']) { $output[$function_name]['examples'] = $output[$function_name]['example']; unset($output[$function_name]['example']); } if ($calls = $this->getThisInheritanceCalls()) { foreach ($calls as $call) { $output[$function_name]['chains']['call'][] = $call; } } if ($this->getPrototype()) { $output[$function_name]['prototype'] = $this->getPrototype(); } if ($this->getInstance()) { $output[$function_name]['instance'] = $this->getInstance(); } }
public function getInstanceFunctions($function_name) { $functions = array(); $this->build(); $lines = Text::chop($this->package->getCode(), $this->start[0], $this->start[1], $this->end[0], $this->end[1], true); foreach ($lines as $line_number => $line) { if (preg_match('%\\bthis\\.([a-zA-Z0-9._$]+)\\s*=\\s*function\\b%', $line, $match, PREG_OFFSET_CAPTURE)) { $function = new DojoFunctionDeclare($this->package, $line_number, $match[0][1]); $function->setFunctionName($function_name); $end = $function->build(); $functions[] = $function; } } return $functions; }
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; } } }