X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FCommand%2FListCommand%2FConstantEnumerator.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FCommand%2FListCommand%2FConstantEnumerator.php;h=4ec7d7426822a78ecf9a724ba393d7bd3f303791;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/psy/psysh/src/Psy/Command/ListCommand/ConstantEnumerator.php b/vendor/psy/psysh/src/Psy/Command/ListCommand/ConstantEnumerator.php new file mode 100644 index 000000000..4ec7d7426 --- /dev/null +++ b/vendor/psy/psysh/src/Psy/Command/ListCommand/ConstantEnumerator.php @@ -0,0 +1,103 @@ +getOption('constants')) { + return; + } + + $category = $input->getOption('user') ? 'user' : $input->getOption('category'); + $label = $category ? ucfirst($category) . ' Constants' : 'Constants'; + $constants = $this->prepareConstants($this->getConstants($category)); + + if (empty($constants)) { + return; + } + + $ret = array(); + $ret[$label] = $constants; + + return $ret; + } + + /** + * Get defined constants. + * + * Optionally restrict constants to a given category, e.g. "date". + * + * @param string $category + * + * @return array + */ + protected function getConstants($category = null) + { + if (!$category) { + return get_defined_constants(); + } + + $consts = get_defined_constants(true); + + return isset($consts[$category]) ? $consts[$category] : array(); + } + + /** + * Prepare formatted constant array. + * + * @param array $constants + * + * @return array + */ + protected function prepareConstants(array $constants) + { + // My kingdom for a generator. + $ret = array(); + + $names = array_keys($constants); + natcasesort($names); + + foreach ($names as $name) { + if ($this->showItem($name)) { + $ret[$name] = array( + 'name' => $name, + 'style' => self::IS_CONSTANT, + 'value' => $this->presentRef($constants[$name]), + ); + } + } + + return $ret; + } +}