如何从.dll文件生成.php文件以完成代码


How to generate .php files from .dll files for code completion?

基本上我已经成功地安装了MongoDB和它的PHP扩展。我想在我的IDE中使用MongoDB php库的代码完成,最接近我得到的答案是关于Eclipse的PDT的一些东西。

好了,经过大量的搜索,我发现一些代码可以帮助我做到这一点!我将在这里包含代码,以供其他人在git仓库发生问题时使用。您所要做的就是将您想要存根的类和函数写入到这些数组$functions = array();中以完成代码$classes = array(); https://gist.github.com/ralphschindler/4757829

<?php
define('T', '    ');
define('N', PHP_EOL);
$functions = array();
$classes = array();
$constant_prefix = 'X_';
$php = '<?php' . N;
$php .= '/**' . N . ' * Generated stub file for code completion purposes' . N . ' */';
$php .= N . N;
foreach (get_defined_constants() as $cname => $cvalue) {
    if (strpos($cname, $constant_prefix) === 0) {
        $php .= 'define(''' . $cname . ''', ' . $cvalue . ');' . N;
    }
}
$php .= N;
foreach ($functions as $function) {
    $refl = new ReflectionFunction($function);
    $php .= 'function ' . $refl->getName() . '(';
    foreach ($refl->getParameters() as $i => $parameter) {
        if ($i >= 1) {
            $php .= ', ';
        }
        if ($typehint = $parameter->getClass()) {
            $php .= $typehint->getName() . ' ';
        }
        $php .= '$' . $parameter->getName();
        if ($parameter->isDefaultValueAvailable()) {
            $php .= ' = ' . $parameter->getDefaultValue();
        }
    }
    $php .= ') {}' . N;
}
$php .= N;
foreach ($classes as $class) {
    $refl = new ReflectionClass($class);
    $php .= 'class ' . $refl->getName();
    if ($parent = $refl->getParentClass()) {
        $php .= ' extends ' . $parent->getName();
    }
    $php .= N . '{' . N;
    foreach ($refl->getProperties() as $property) {
        $php .= T . '$' . $property->getName() . ';' . N;
    }
    foreach ($refl->getMethods() as $method) {
        if ($method->isPublic()) {
            if ($method->getDocComment()) {
                $php .= T . $method->getDocComment() . N;                
            }
            $php .= T . 'public function ';
            if ($method->returnsReference()) {
                $php .= '&';
            }
            $php .= $method->getName() . '(';
            foreach ($method->getParameters() as $i => $parameter) {
                if ($i >= 1) {
                    $php .= ', ';
                }
                if ($parameter->isArray()) {
                    $php .= 'array ';
                }
                if ($typehint = $parameter->getClass()) {
                    $php .= $typehint->getName() . ' ';
                }
                $php .= '$' . $parameter->getName();
                if ($parameter->isDefaultValueAvailable()) {
                    $php .= ' = ' . $parameter->getDefaultValue();
                }
            }
            $php .= ') {}' . N;
        }
    }
    $php .= '}';
}
echo $php . N;