Example #1
0
 /**
  * @return array
  */
 protected function getTagsForExtension($name)
 {
     if (!extension_loaded($name)) {
         return array();
     }
     $tags = array();
     $module = new \ReflectionExtension($name);
     // Export constants.
     foreach ($module->getConstants() as $name => $value) {
         $tags[] = new Tag($name, 'constant', Tag::DEFINITION);
     }
     // Export functions.
     foreach ($module->getFunctions() as $function) {
         $tags[] = new Tag($function->getName(), 'function', TAG::DEFINITION);
     }
     // Export classes.
     foreach ($module->getClasses() as $class) {
         $tags[] = new Tag($class->getName(), 'class', TAG::DEFINITION);
         foreach ($class->getMethods() as $method) {
             $tags[] = new Tag(sprintf('%s::%s', $class->getName(), $method->getName()), 'function', TAG::DEFINITION);
         }
         foreach ($class->getProperties() as $property) {
             $tags[] = new Tag(sprintf('%s::%s', $class->getName(), $property->getName()), 'variable', TAG::DEFINITION);
         }
         foreach ($class->getConstants() as $constant => $value) {
             $tags[] = new Tag(sprintf('%s::%s', $class->getName(), $constant), 'constant', TAG::DEFINITION);
         }
     }
     return $tags;
 }
Example #2
0
 /**
  * Returns an associative array containing this extension's constants and
  * their values
  * @return array<string,mixed>
  */
 public function getConstants()
 {
     if ($this->reflectionSource) {
         return $this->reflectionSource->getConstants();
     } else {
         return parent::getConstants();
     }
 }
 function __construct(SymbolTable $symbolTable, \Guardrail\Output\OutputInterface $output)
 {
     parent::__construct($symbolTable, $output);
     foreach (get_loaded_extensions() as $extension) {
         try {
             $reflectedExtension = new \ReflectionExtension($extension);
             foreach ($reflectedExtension->getConstants() as $constant => $value) {
                 $this->reflectedConstants[$constant] = true;
             }
         } catch (\ReflectionException $e) {
         }
     }
 }
 /**
  * @param string[] $extensionNames
  * @return string[]
  * @throws UnknownExtensionException if the extension cannot be found
  */
 public function __invoke(array $extensionNames) : array
 {
     $definedSymbols = [];
     foreach ($extensionNames as $extensionName) {
         try {
             $extensionReflection = new \ReflectionExtension($extensionName);
             $definedSymbols = array_merge($definedSymbols, array_keys($extensionReflection->getConstants()), array_keys($extensionReflection->getFunctions()), $extensionReflection->getClassNames());
         } catch (\Exception $e) {
             throw new UnknownExtensionException($e->getMessage());
         }
     }
     return $definedSymbols;
 }
 public function introspect(\ReflectionExtension $extension)
 {
     $classes = $functions = $constants = array();
     foreach ($extension->getClasses() as $class) {
         assert($class instanceof \ReflectionClass);
         $phpClass = PhpClass::fromReflection($class);
         $classes[] = $phpClass;
     }
     foreach ($extension->getFunctions() as $function) {
         assert($function instanceof \ReflectionFunction);
         $phpFunction = PhpFunction::fromReflection($function);
         $functions[] = $phpFunction;
     }
     foreach ($extension->getConstants() as $name => $value) {
         $phpConstant = new PhpConstant($name);
         $phpConstant->setValue($value);
         $constants[] = $phpConstant;
     }
     return array('classes' => $classes, 'functions' => $functions, 'constants' => $constants);
 }
function export_ext($ext)
{
    $rf_ext = new ReflectionExtension($ext);
    $funcs = $rf_ext->getFunctions();
    $classes = $rf_ext->getClasses();
    $consts = $rf_ext->getConstants();
    $version = $rf_ext->getVersion();
    $defines = '';
    $sp4 = str_repeat(' ', 4);
    $fdefs = getFuncDef($funcs, $version);
    $class_def = '';
    foreach ($consts as $k => $v) {
        if (!is_numeric($v)) {
            $v = "'{$v}'";
        }
        $defines .= "define('{$k}',{$v});\n";
    }
    foreach ($classes as $k => $v) {
        $prop_str = '';
        $props = $v->getProperties();
        array_walk($props, function ($v, $k) {
            global $prop_str, $sp4;
            $modifiers = implode(' ', Reflection::getModifierNames($v->getModifiers()));
            $prop_str .= "{$sp4}/**\n{$sp4}*@var \$" . $v->name . " " . $v->class . "\n{$sp4}*/\n{$sp4} {$modifiers}  \$" . $v->name . ";\n\n";
        });
        if ($v->getParentClass()) {
            $k .= ' extends ' . $v->getParentClass()->name;
        }
        $modifier = 'class';
        if ($v->isInterface()) {
            $modifier = 'interface';
        }
        $mdefs = getMethodsDef($v->getMethods(), $version);
        $class_def .= sprintf("/**\n*@since %s\n*/\n%s %s{\n%s%s\n}\n", $version, $modifier, $k, $prop_str, $mdefs);
    }
    if (!file_exists('./ext')) {
        mkdir('./ext', 777, TRUE);
    }
    file_put_contents("./ext/" . $ext . ".php", "<?php\n" . $defines . $fdefs . $class_def);
}
Example #7
0
 function export()
 {
     /**
      * 获取所有define常量
      */
     $consts = $this->rf_ext->getConstants();
     $defines = '';
     foreach ($consts as $className => $ref) {
         if (!is_numeric($ref)) {
             $ref = "'{$ref}'";
         }
         $defines .= "define('{$className}', {$ref});\n";
     }
     file_put_contents(OUTPUT_DIR . '/constants.php', "<?php\n" . $defines);
     /**
      * 获取所有函数
      */
     $funcs = $this->rf_ext->getFunctions();
     $fdefs = $this->getFunctionsDef($funcs);
     file_put_contents(OUTPUT_DIR . '/functions.php', "<?php\n" . $fdefs);
     /**
      * 获取所有类
      */
     $classes = $this->rf_ext->getClasses();
     $class_alias = "<?php\n";
     foreach ($classes as $className => $ref) {
         //命名空间
         if (strchr($className, '\\')) {
             $this->exportNamespaceClass($className, $ref);
             continue;
         } else {
             $class_alias .= sprintf("\nclass %s extends %s\n{\n\n}\n", $className, self::getNamespaceAlias($className));
         }
     }
     file_put_contents(OUTPUT_DIR . '/classes.php', $class_alias);
 }
Example #8
0
function gen_extension_markup(ReflectionExtension $obj, $content, $xml_file)
{
    /* {{{ */
    global $INFO, $OPTION;
    switch ($xml_file) {
        case 'ini.xml':
            if ($ini = ini_get_all($obj->name)) {
                $visibility = array(INI_USER => 'PHP_INI_USER', INI_PERDIR => 'PHP_INI_PERDIR', INI_SYSTEM => 'PHP_INI_SYSTEM', INI_ALL => 'PHP_INI_ALL');
                $ident = get_ident_size('INI_ENTRIES', $content);
                $markup = "<tbody>" . PHP_EOL;
                $markup2 = '';
                foreach ($ini as $config => $value) {
                    $id = "ini." . format_config($config);
                    $markup .= str_repeat(' ', $ident + 1) . "<row>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 2) . "<entry><link linkend=\"" . $id . "\">" . $config . "</link></entry>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 2) . "<entry>" . $value['global_value'] . "</entry>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 2) . "<entry>" . (isset($visibility[$value['access']]) ? $visibility[$value['access']] : $value['access']) . "</entry>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 2) . "<entry><!-- leave empty, this will be filled by an automatic script --></entry>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 1) . "</row>" . PHP_EOL;
                    $markup2 .= ($markup2 ? str_repeat(' ', $ident) : '') . "<varlistentry xml:id=\"" . $id . "\">" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 1) . "<term>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 2) . "<parameter>" . $config . "</parameter>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 2) . "<type>" . get_type_by_string($value['global_value']) . "</type>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 1) . "</term>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 1) . "<listitem>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 2) . "<para>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 3) . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 2) . "</para>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident + 1) . "</listitem>" . PHP_EOL;
                    $markup2 .= str_repeat(' ', $ident) . "</varlistentry>" . PHP_EOL;
                }
                $markup .= str_repeat(' ', $ident) . "</tbody>";
                /* {INI_ENTRIES} */
                $content = preg_replace('/\\{INI_ENTRIES\\}/', $markup, $content, 1);
                /* {INI_ENTRIES_DESCRIPTION} */
                $content = preg_replace('/\\{INI_ENTRIES_DESCRIPTION\\}/', $markup2, $content, 1);
            } else {
                return false;
                /* Abort */
            }
            break;
        case 'constants.xml':
            if ($constants = $obj->getConstants()) {
                $ident = get_ident_size('CONSTANTS', $content);
                $markup = "&extension.constants;" . PHP_EOL;
                $markup .= str_repeat(' ', $ident) . "<para>" . PHP_EOL;
                $markup .= str_repeat(' ', $ident + 1) . "<variablelist>" . PHP_EOL;
                foreach ($constants as $name => $value) {
                    $markup .= str_repeat(' ', $ident + 2) . '<varlistentry xml:id="constant.' . format_id($name) . '">' . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 3) . "<term>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 4) . "<constant>" . $name . "</constant>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 4) . "(<type>" . gettype($value) . "</type>)" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 3) . "</term>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 3) . "<listitem>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 4) . "<simpara>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 4) . "</simpara>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 3) . "</listitem>" . PHP_EOL;
                    $markup .= str_repeat(' ', $ident + 2) . "</varlistentry>" . PHP_EOL;
                }
                $markup .= str_repeat(' ', $ident + 1) . "</variablelist>" . PHP_EOL;
                $markup .= str_repeat(' ', $ident) . "</para>";
                $content = preg_replace('/\\{CONSTANTS\\}/', $markup, $content, 1);
            } else {
                $content = preg_replace('/\\{CONSTANTS\\}/', '&no.constants;', $content, 1);
            }
            break;
        case 'configure.xml':
            $ident = get_ident_size('EXT_INSTALL_MAIN', $content);
            $ident2 = get_ident_size('EXT_INSTALL_WIN', $content);
            $markup = '';
            $markup2 = '';
            if ($OPTION['pecl'] === true) {
                $markup .= "<para>" . PHP_EOL;
                $markup .= str_repeat(' ', $ident + 1) . "&pecl.info;" . PHP_EOL;
                $markup .= str_repeat(' ', $ident + 1) . "<link xlink:href=\"&url.pecl.package;{EXT_NAME_ID}\">&url.pecl.package;{EXT_NAME_ID}</link>" . PHP_EOL;
                $markup .= str_repeat(' ', $ident) . "</para>" . PHP_EOL;
                /*
                $markup2 .= "<para>". PHP_EOL;
                $markup2 .= str_repeat(' ', $ident2 + 1) ."The latest PECL/{EXT_NAME_ID} Win32 DLL is available here:". PHP_EOL;
                $markup2 .= str_repeat(' ', $ident2 + 1) ."<link xlink:href=\"&url.pecl.win.ext;php_{EXT_NAME_ID}.dll\">php_{EXT_NAME_ID}.dll</link>". PHP_EOL;
                $markup2 .= str_repeat(' ', $ident2) ."</para>". PHP_EOL;
                */
            } else {
                $markup .= "<para>" . PHP_EOL;
                $markup .= str_repeat(' ', $ident + 1) . "Use <option role=\"configure\">--with-{EXT_NAME_ID}[=DIR]</option> when compiling PHP." . PHP_EOL;
                $markup .= str_repeat(' ', $ident) . "</para>" . PHP_EOL;
                $markup2 .= "<para>" . PHP_EOL;
                $markup2 .= str_repeat(' ', $ident2 + 1) . "Windows users should include <filename>php_{EXT_NAME_ID}.dll</filename> into &php.ini;" . PHP_EOL;
                $markup2 .= str_repeat(' ', $ident2) . "</para>" . PHP_EOL;
            }
            $content = str_replace('{EXT_INSTALL_MAIN}', $markup, $content);
            $content = str_replace('{EXT_INSTALL_WIN}', $markup2, $content);
            break;
        case 'versions.xml':
            $version_default = 'PHP 5 &gt;= Unknown';
            if ($OPTION['pecl'] === true) {
                $version_default = 'PECL {EXT_NAME_ID} &gt;= Unknown';
            }
            $markup = "";
            /* Function list */
            if ($functions = $obj->getFunctions()) {
                $markup .= "<!-- Functions -->" . PHP_EOL;
                foreach ($functions as $function) {
                    $markup .= " <function name='" . strtolower($function->getName()) . "' from='{$version_default}'/>" . PHP_EOL;
                }
            }
            /* Method list */
            if ($classes = $obj->getClasses()) {
                $markup .= " <!-- Classes and Methods -->" . PHP_EOL;
                foreach ($classes as $class) {
                    $markup .= PHP_EOL;
                    $markup .= " <function name='" . strtolower($class->name) . "' from='{$version_default}'/>" . PHP_EOL;
                    foreach ($class->getMethods() as $method) {
                        $markup .= " <function name='" . strtolower($class->name . '::' . $method->getName()) . "' from='{$version_default}'/>" . PHP_EOL;
                    }
                }
            }
            $content = preg_replace('/\\{VERSIONS\\}/', rtrim($markup), $content);
            break;
        case 'book.developer.xml':
            if ($OPTION['docbase'] && $OPTION['phpdoc']) {
                $content = preg_replace('/\\{PATH_TO_DOCBASE\\}/', $OPTION['docbase'], $content);
                $content = preg_replace('/\\{PATH_TO_DOC\\}/', $OPTION['phpdoc'], $content);
            }
            break;
    }
    return $content;
}
Example #9
0
    default:
    case 3:
        $out = fopen($argv[2], "w") or die;
    case 2:
        $ext = $argv[1];
        break;
    case 1:
        die(sprintf($out, "Usage: %s <ext>\n", $argv[0]));
}
fprintf($out, "<?php\n\n");
$ext = new ReflectionExtension($ext);
$constants = array();
$functions = array();
$structures = array();
// split up by namespace first
foreach ($ext->getConstants() as $constant => $value) {
    $ns = ($nsend = strrpos($constant, "\\")) ? substr($constant, 0, $nsend++) : "";
    $cn = substr($constant, $nsend);
    $constants[$ns][$cn] = $value;
}
foreach ($ext->getFunctions() as $f) {
    /* @var $f ReflectionFunction */
    $ns = $f->inNamespace() ? $f->getNamespaceName() : "";
    $functions[$ns][$f->getShortName()] = $f;
}
foreach ($ext->getClasses() as $c) {
    /* @var $c ReflectionClass */
    $ns = $c->inNamespace() ? $c->getNamespaceName() : "";
    $structures[$ns][$c->getShortName()] = $c;
}
$namespaces = array_unique(array_merge(array_keys($constants), array_keys($functions), array_keys($structures)));
Example #10
0
<pre>
<?php 
// Создание экземпляра класса ReflectionProperty
$ext = new ReflectionExtension('standard');
// Вывод основной информации
printf("Имя           : %s\n" . "Версия        : %s\n" . "Функции       : [%d] %s\n" . "Константы     : [%d] %s\n" . "Директивы INI : [%d] %s\n" . "Классы        : [%d] %s\n", $ext->getName(), $ext->getVersion() ? $ext->getVersion() : 'NO_VERSION', sizeof($ext->getFunctions()), var_export($ext->getFunctions(), 1), sizeof($ext->getConstants()), var_export($ext->getConstants(), 1), sizeof($ext->getINIEntries()), var_export($ext->getINIEntries(), 1), sizeof($ext->getClassNames()), var_export($ext->getClassNames(), 1));
?>
</pre>
Example #11
0
 public function printInfo()
 {
     $info = [];
     $ion = new \ReflectionExtension('ion');
     $info[] = $ion->info();
     foreach ($ion->getINIEntries() as $ini => $value) {
         $info[] = "ini {$ini} = " . var_export($value, true);
     }
     foreach ($ion->getConstants() as $constant => $value) {
         $info[] = "const {$constant} = " . var_export($value, true);
     }
     foreach ($ion->getFunctions() as $function) {
         $info[] = $this->_scanFunction($function);
     }
     foreach ($ion->getClasses() as $class) {
         $mods = [];
         if ($class->isFinal()) {
             $mods[] = "final";
         }
         if ($class->isInterface()) {
             $mods[] = "interface";
         } elseif ($class->isTrait()) {
             $mods[] = "trait";
         } else {
             if ($class->isAbstract()) {
                 $mods[] = "abstract";
             }
             $mods[] = "class";
         }
         $info[] = implode(' ', $mods) . " {$class->name} {";
         if ($class->getParentClass()) {
             $info[] = "  extends {$class->getParentClass()->name}";
         }
         foreach ($class->getInterfaceNames() as $interface) {
             $info[] = "  implements {$interface}";
         }
         foreach ($class->getTraitNames() as $trait) {
             $info[] = "  use {$trait}";
         }
         foreach ($class->getConstants() as $constant => $value) {
             $info[] = "  const {$class->name}::{$constant} = " . var_export($value, true);
         }
         foreach ($class->getProperties() as $prop_name => $prop) {
             /** @var ReflectionProperty $prop */
             $mods = implode(' ', Reflection::getModifierNames($prop->getModifiers()));
             if ($prop->class !== $class->name) {
                 $info[] = "  prop {$mods} {$prop->class}::\${$prop->name}";
             } else {
                 $info[] = "  prop {$mods} \${$prop->name}";
             }
         }
         foreach ($class->getMethods() as $method) {
             $info[] = $this->_scanFunction($method, $class->name);
         }
         $info[] = "}";
     }
     echo implode("\n", $info) . "\n";
 }
Example #12
0
<?php

$ext = new ReflectionExtension("standard");
$consts = $ext->getConstants();
var_dump($consts["CONNECTION_NORMAL"]);
# Housekeeping.
error_reporting(E_ALL | E_DEPRECATED | E_STRICT);
ini_set('display_errors', 'On');
date_default_timezone_set('UTC');
$blocks = array('extensions' => array(), 'last-modified' => sprintf('" %s, PHP %s', date('r'), PHP_VERSION));
# Parse the configuration file associated with this script.
$configuration = parse_ini_file(__DIR__ . '/syntax.ini', true);
# Process extensions and generate built-in functions, constants, classes and interfaces.
$extensions = array();
foreach ($configuration['extensions'] as $extensionName => $isEnabled) {
    if (!$isEnabled) {
        continue;
    }
    try {
        $reflect = new ReflectionExtension($extensionName);
        $options = array('name' => $reflect->getName(), 'classes' => array(), 'functions' => array_keys($reflect->getFunctions()), 'constants' => array_diff(array_keys($reflect->getConstants()), array('TRUE', 'FALSE', 'NULL')));
        foreach ($reflect->getClasses() as $extensionClass) {
            $options['classes'][] = $extensionClass->getName();
            $options['constants'] = array_unique(array_merge($options['constants'], array_keys($extensionClass->getConstants())));
        }
        sort($options['classes'], SORT_NATURAL);
        sort($options['functions'], SORT_NATURAL);
        sort($options['constants'], SORT_NATURAL);
        $extensions[$extensionName] = $options;
    } catch (ReflectionException $e) {
        file_put_contents('php://stderr', sprintf('[ERROR] %s: %s.' . PHP_EOL, $extensionName, rtrim($e->getMessage(), ' ?!.')));
    }
}
$blocks['extensions'][] = 'if ! exists("g:php_syntax_extensions_enabled")';
$blocks['extensions'][] = sprintf('    let g:php_syntax_extensions_enabled = ["%s"]', implode('", "', array_map('strtolower', array_keys($extensions))));
$blocks['extensions'][] = 'endif';
Example #14
0
<?php

## Использование отражения библиотеки.
$consts = [];
foreach (get_loaded_extensions() as $name) {
    $ext = new ReflectionExtension($name);
    $consts = array_merge($consts, $ext->getConstants());
}
echo "<pre>" . var_export($consts, true) . "</pre>";
Example #15
0
 /**
  * Get all info about function
  * @param string|function $extensionName Function or function name
  * @return array|bool
  */
 protected static function _getExtension($extensionName)
 {
     if (!extension_loaded($extensionName)) {
         return false;
     }
     $ext = new ReflectionExtension($extensionName);
     $result = array();
     $result['name'] = $ext->name;
     $result['version'] = $ext->getVersion();
     if ($constants = $ext->getConstants()) {
         $result['constants'] = $constants;
     }
     if ($classesName = $ext->getClassNames()) {
         $result['classesName'] = $classesName;
     }
     if ($functions = $ext->getFunctions()) {
         $result['functions'] = $functions;
     }
     if ($dependencies = $ext->getDependencies()) {
         $result['dependencies'] = $dependencies;
     }
     if ($INIEntries = $ext->getINIEntries()) {
         $result['INIEntries'] = $INIEntries;
     }
     $functions = $ext->getFunctions();
     if (is_array($functions) && count($functions) > 0) {
         $result['functions'] = array();
         foreach ($functions as $function) {
             $funcName = $function->getName();
             $result['functions'][$funcName] = self::_getFunction($funcName);
         }
     }
     return $result;
 }
Example #16
0
 * must still be enabled (compiled in or loaded as shared) for these constants to show up.
 */
$extensions = array('core', 'bcmath', 'bz2', 'calendar', 'com_dotnet', 'ctype', 'curl', 'date', 'dba', 'dom', 'enchant', 'ereg', 'exif', 'fileinfo', 'filter', 'ftp', 'gd', 'gettext', 'gmp', 'hash', 'iconv', 'imap', 'intl', 'json', 'ldap', 'libxml', 'mbstring', 'mcrypt', 'mhash', 'mysql', 'mysqli', 'oci8', 'oci8_11g', 'odbc', 'openssl', 'pcntl', 'pcre', 'pdo', 'pgsql', 'phar', 'posix', 'pspell', 'readline', 'recode', 'reflection', 'session', 'shmop', 'simplexml', 'snmp', 'soap', 'sockets', 'spl', 'standard', 'sqlite', 'sqlite3', 'sybase_ct', 'sysvmsg', 'sysvsem', 'sysvshm', 'tidy', 'tokenizer', 'xml', 'xmlreader', 'xmlwriter', 'xmlrpc', 'xsl', 'zip', 'zlib', 'yaf', 'yar', 'taint');
$out_file = 'php_vimgen_out.vim';
// Pick your output file & location.
$out_str = '';
$store = array();
$errors = array();
foreach ($extensions as $ext) {
    echo "Processing extension '{$ext}'." . PHP_EOL;
    try {
        $extension = new ReflectionExtension($ext);
        $ext_info = array();
        $ext_info['name'] = $extension->getName();
        $ext_functions = array_keys($extension->getFunctions());
        $ext_constants = array_keys($extension->getConstants());
        $classes = $extension->getClasses();
        $ext_classes = array();
        foreach ($classes as $class) {
            $ext_classes[] = $class->getName();
            $ext_constants = array_merge($ext_constants, array_keys($class->getConstants()));
        }
        $ext_constants = array_unique($ext_constants);
        if (count($ext_functions)) {
            $ext_info['functions'] = implode(' ', $ext_functions);
        }
        if (count($ext_constants)) {
            $ext_info['constants'] = implode(' ', $ext_constants);
        }
        if (count($ext_classes)) {
            $ext_info['classes'] = implode(' ', $ext_classes);
Example #17
0
<?php

if (!extension_loaded('opencl')) {
    echo "opencl extension is not loaded!\n";
    exit(1);
}
chdir(__DIR__);
$skeleton = file_get_contents('Cl.php.in');
if (!$skeleton) {
    exit(1);
}
$reflector = new ReflectionExtension('opencl');
$constDefinitions = array();
$constExceptions = array('CL_GLOBAL' => 'MEM_TYPE_GLOBAL', 'CL_LOCAL' => 'MEM_TYPE_LOCAL', 'CL_TRUE' => null, 'CL_FALSE' => null, 'CL_VERSION_1_0' => null, 'CL_VERSION_1_1' => null, 'CL_VERSION_1_2' => null);
foreach ($reflector->getConstants() as $name => $value) {
    if (array_key_exists($name, $constExceptions)) {
        $name = $constExceptions[$name];
        if (is_null($name)) {
            continue;
        }
    } else {
        $name = substr($name, 3);
    }
    $constDefinitions[] = sprintf('const %s = %s;', $name, var_export($value, true));
}
$source = str_replace('/* CONSTANTS */', implode("\n    ", $constDefinitions), $skeleton);
file_put_contents('Cl.php', $source);
Example #18
0
 *
 * NOTE: mysqlnd is not included because it exposes no functions, classes, or constants.
 * The pdo_* extensions are not included in the list because they do not expose any
 * functions, classes, or constants themselves. The constants and methods specific
 * to that driver are exposed though the PDO extension itself. The pdo_* extensions
 * must still be enabled (compiled in or loaded as shared) for these constants to show up.
 */
$allowed_extensions = array('bcmath', 'bz2', 'core', 'curl', 'date', 'dom', 'ereg', 'gd', 'gettext', 'hash', 'iconv', 'json', 'libxml', 'mbstring', 'mcrypt', 'mhash', 'mysql', 'mysqli', 'openssl', 'pcre', 'pdo', 'pgsql', 'phar', 'reflection', 'session', 'simplexml', 'soap', 'sockets', 'spl', 'sqlite3', 'standard', 'tokenizer', 'wddx', 'xml', 'xmlreader', 'xmlwriter', 'zip', 'zlib');
$processed = array();
foreach ($allowed_extensions as $extension) {
    try {
        $details = array();
        $options = new ReflectionExtension($extension);
        $classes = array();
        $functions = array_keys($options->getFunctions());
        $constants = array_keys($options->getConstants());
        foreach ($options->getClasses() as $class) {
            $classes[] = $class->getName();
            $constants = array_merge($constants, array_keys($class->getConstants()));
        }
        $constants = array_unique($constants);
        $details['name'] = $options->getName();
        if (sizeof($functions)) {
            $details['functions'] = implode(' ', $functions);
        }
        if (sizeof($constants)) {
            $details['constants'] = implode(' ', $constants);
        }
        if (sizeof($classes)) {
            $details['classes'] = implode(' ', $classes);
        }
Example #19
0
 * and methods provided by mecab extension (use ReflectionExtension)
 * charset=utf-8
 */
require_once dirname(__FILE__) . '/common.inc.php';
$linebreak = PHP_EOL . PHP_EOL;
$reflector = new ReflectionExtension('mecab');
$mapper = create_function('$m', 'return $m->getName();');
border();
echo 'Module dependencies:', $linebreak;
print_r($reflector->getDependencies());
border();
echo 'INI entries:', $linebreak;
print_r($reflector->getINIEntries());
border();
echo 'Constants:', $linebreak;
print_r($reflector->getConstants());
border();
echo 'Functions:', $linebreak;
print_r(array_keys($reflector->getFunctions()));
border();
echo 'Classes:', $linebreak;
$classes = array();
foreach ($reflector->getClasses() as $className => $class) {
    $classes[$className] = array('interfaces' => null, 'constants' => $class->getConstants(), 'properties' => $class->getProperties(), 'methods' => array_map($mapper, $class->getMethods()));
    if (method_exists($class, 'getInterfaceNames')) {
        $classes[$className]['interfaces'] = $class->getInterfaceNames();
    } else {
        $classes[$className]['interfaces'] = array_keys($class->getInterfaces());
    }
}
print_r($classes);
Example #20
0
}
$ext = "http";
$doc = "/home/mike/Development/src/php/phpdoc/en/trunk/reference/{$ext}";
$ref = new ReflectionExtension($ext);
printf("Undocumented INI options:\n");
foreach ($ref->getINIEntries() as $name => $tmp) {
    re("configuration.xml", "#<entry>{$name}</entry>#") or printf("\t%s (%s)\n", $name, $tmp);
}
printf("\n");
printf("Undocumented stream filters:\n");
foreach (preg_grep("/^{$ext}\\./", stream_get_filters()) as $filter) {
    fe(sprintf("streamfilters/%s.xml", substr($filter, 5))) or printf("\t%s\n", $filter);
}
printf("\n");
printf("Undocumented constants:\n");
foreach ($ref->getConstants() as $name => $tmp) {
    re("constants.xml", "#<constant>{$name}</constant>#") or printf("\t%s (%s)\n", $name, $tmp);
}
printf("\n");
printf("Undocumented functions:\n");
foreach ($ref->getFunctions() as $func) {
    /* @var $func ReflectionFunction */
    fg(sprintf("functions/*/%s.xml", strtr($func->getName(), '_', '-'))) or printf("\t%s()\n", $func->getName());
}
printf("\n");
printf("Undocumented classes/members:\n");
foreach ($ref->getClasses() as $class) {
    if (substr($class->getName(), -strlen("Exception")) === "Exception") {
        continue;
    }
    /* @var $class ReflectionClass */
if (version_compare(PHP_VERSION, '5.4', '<')) {
    throw new RuntimeException('php version requires >=5.4');
}
if (!extension_loaded('reflection')) {
    throw new RuntimeException('requires reflection extension');
}
if ($argc == 1) {
    exit(sprintf("Usage: %s EXTENSION_NAME\n", pathinfo(__FILE__, PATHINFO_BASENAME)));
}
$extension = $argv[1];
if (!extension_loaded($extension)) {
    throw new RuntimeException(sprintf('extension %s not found', $extension));
}
$result = "<?php\n";
$ref = new ReflectionExtension($extension);
$constants = $ref->getConstants();
foreach ($constants as $name => $value) {
    $str = getDefineStr($name, $value);
    $result .= "{$str}\n";
}
$functions = $ref->getFunctions();
foreach ($functions as $func) {
    $params = $func->getParameters();
    $paramStrArr = array();
    foreach ($params as $param) {
        $paramStrArr[] = getParamStr($param);
    }
    $result .= sprintf("function %s(%s){}\n", $func->getName(), join(', ', $paramStrArr));
}
$classes = $ref->getClasses();
foreach ($classes as $class) {