Skip to content

Instantly share code, notes, and snippets.

@sotarok
Created January 16, 2009 17:44
Show Gist options
  • Save sotarok/48028 to your computer and use it in GitHub Desktop.
Save sotarok/48028 to your computer and use it in GitHub Desktop.
<?php
/**
* Echo php builtin classes, interfaces, functions, constants for vim dictionary
*
* eg:# php dict.php | sort > ~/.vim/dict/php_functions.dict
*
* @version $id$
* @copyright 2009 Heavens hell
* @author Heavens hell <[email protected]>
* @license New BSD License
* @forked sotarok
*/
$f = false;
$c = false;
$i = false;
$d = false;
$m = false;
$usage = null;
if ($argc > 1) {
foreach (array_slice($argv, 1) as $val) {
if ($val === '-c') {
// Classes
$c = true;
} else if ($val === '-f') {
// Functions
$f = true;
} else if ($val === '-i') {
// Interfaces
$i = true;
} else if ($val === '-d') {
// Constants
$d = true;
} else if ($val === '-m') {
// Classes
$m = true;
} else {
$usage = 'Usage: php dict.php [-c] [-f] [-i] [-d] [-m]' . PHP_EOL;
$usage .= ' -c display built in classes' . PHP_EOL;
$usage .= ' -f display built in functions' . PHP_EOL;
$usage .= ' -i display builtin interfaces' . PHP_EOL;
$usage .= ' -d display builtin constants' . PHP_EOL;
$usage .= ' -m display builtin class methods' . PHP_EOL;
}
}
} else {
$f = true;
$c = true;
$i = true;
$d = true;
$m = true;
}
if (!is_null($usage)) {
echo $usage;
exit(0);
}
$buffer = array();
if ($f === true) {
$functions = get_defined_functions();
$buffer += $functions["internal"];
}
if ($c === true) {
$class = get_declared_classes();
foreach ($class as $value) {
$buffer[] = $value;
if ($m === true) {
foreach (get_class_methods($value) as $method) {
$buffer[] = $method;
}
}
}
}
if ($i === true) {
$interface = get_declared_interfaces();
foreach ($interface as $value) {
$buffer[] = $value;
}
}
if ($d === true) {
$constants = get_defined_constants();
foreach ($constants as $key => $value) {
$buffer[] = $key;
}
}
echo join(PHP_EOL, array_unique($buffer)) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment