X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FCommand%2FListCommand%2FFunctionEnumerator.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FCommand%2FListCommand%2FFunctionEnumerator.php;h=733055a60a8ab7b28a595aa8ffe2b121c2cc48a9;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/psy/psysh/src/Command/ListCommand/FunctionEnumerator.php b/vendor/psy/psysh/src/Command/ListCommand/FunctionEnumerator.php new file mode 100644 index 000000000..733055a60 --- /dev/null +++ b/vendor/psy/psysh/src/Command/ListCommand/FunctionEnumerator.php @@ -0,0 +1,112 @@ +getOption('functions')) { + return; + } + + if ($input->getOption('user')) { + $label = 'User Functions'; + $functions = $this->getFunctions('user'); + } elseif ($input->getOption('internal')) { + $label = 'Internal Functions'; + $functions = $this->getFunctions('internal'); + } else { + $label = 'Functions'; + $functions = $this->getFunctions(); + } + + $functions = $this->prepareFunctions($functions); + + if (empty($functions)) { + return; + } + + $ret = []; + $ret[$label] = $functions; + + return $ret; + } + + /** + * Get defined functions. + * + * Optionally limit functions to "user" or "internal" functions. + * + * @param null|string $type "user" or "internal" (default: both) + * + * @return array + */ + protected function getFunctions($type = null) + { + $funcs = get_defined_functions(); + + if ($type) { + return $funcs[$type]; + } else { + return array_merge($funcs['internal'], $funcs['user']); + } + } + + /** + * Prepare formatted function array. + * + * @param array $functions + * + * @return array + */ + protected function prepareFunctions(array $functions) + { + natcasesort($functions); + + // My kingdom for a generator. + $ret = []; + + foreach ($functions as $name) { + if ($this->showItem($name)) { + $ret[$name] = [ + 'name' => $name, + 'style' => self::IS_FUNCTION, + 'value' => $this->presentSignature($name), + ]; + } + } + + return $ret; + } +}