diff options
Diffstat (limited to 'src/Utils/Routine.php')
-rw-r--r-- | src/Utils/Routine.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php new file mode 100644 index 0000000..3015a3f --- /dev/null +++ b/src/Utils/Routine.php @@ -0,0 +1,46 @@ +<?php + +namespace SqlParser\Utils; + +class Routine +{ + + /** + * Gets the parameters of a routine from the parse tree. + * + * @param array $tree + * + * @return array + */ + public static function getParameters($tree) + { + $retval = array( + 'num' => 0, + 'dir' => array(), + 'name' => array(), + 'type' => array(), + 'length' => array(), + 'opts' => array(), + ); + + $idx = 0; + foreach ($tree->parameters as $param) { + $retval['dir'][$idx] = $param->inOut; + $retval['name'][$idx] = $param->name; + $retval['type'][$idx] = $param->type->name; + $retval['length'][$idx] = implode(',', $param->type->size); + $retval['opts'][$idx] = array(); + foreach ($param->type->options->options as $opt) { + $retval['opts'][$idx][] = is_string($opt) ? + $opt : $opt['value']; + } + $retval['opts'][$idx] = implode(' ', $retval['opts'][$idx]); + ++$idx; + } + + $retval['num'] = $idx; + + return $retval; + } + +} |