Eclipse通过将PHP的所有函数名和代码提示放入一个名为standard.php
的文件中并将其作为库(?)关联到一个项目来完成PHP函数/方法提示。只要CTRL + Click
任意php函数就可以打开
在standard.php
中,有所有PHP函数的参考参考,如…
/**
* Find whether the type of a variable is integer
* @link http://www.php.net/manual/en/function.is-int.php
* @param var mixed <p>
* The variable being evaluated.
* </p>
* @return bool true if var is an integer,
* false otherwise.
*/
function is_int ($var) {}
我希望能够为我的程序员提供类似于覆盖我们自己的应用程序的东西,以便我可以限制对我们实际软件源代码的访问,但仍然给他们提供代码提示支持和文档的好处。
问题:在Eclipse中是否有一种方法可以导出或自动生成类似的函数引用,能够服务于standard.php
中PHP的相同目的?
EDIT:我们正处于创建一个实用程序的早期阶段,一旦它足够远,我们将把它放在GitHub上。
我们暂时在Github上为它创建了一个空的repo,所以如果你有兴趣在它上升时获得一个副本,请在那里标记它。该回购可以在这里找到:https://github.com/ecommunities/Code-Hint-Aggregator
UPDATE:这花了一点时间,但是上面引用的GitHub项目现在已经启动并运行了,我们现在可以解析整个项目并输出它的整个命名空间/类/方法结构的映射。仅供参考,它仍在Alpha阶段,但值得一看。:)
你可以使用Zend Framework的反射包,看看这里http://framework.zend.com/apidoc/2.1/namespaces/Zend.Code.html
基本上你需要做像
这样的事情<?php
use ZendCodeReflectionFileReflection;
use ZendCodeGeneratorMethodGenerator;
$path ='test/TestClass.php';
include_once $path;
$reflection = new FileReflection($path);
foreach ($reflection->getClasses() as $class) {
$namespace = $class->getNamespaceName();
$className = $class->getShortName();
foreach ($class->getMethods() as $methodReflection) {
$output = '';
$method = MethodGenerator::fromReflection($methodReflection);
$docblock = $method->getDocblock();
if ($docblock) {
$output .= $docblock->generate();
}
$params = implode(', ', array_map(function($item) {
return $item->generate();
}, $method->getParameters()));
$output .= $namespace . ' ' . $className . '::' . $method->getName() . '(' . $params . ')';
echo $output;
echo PHP_EOL . PHP_EOL;
}
}
当我在测试类上运行这个代码时,它看起来像这样:
<?php
class TestClass
{
/**
* Lorem ipsum dolor sit amet
*
* @param string $foo kung-foo
* @param array $bar array of mars bars
*
* @return void
*/
public function foo($foo, array $bar)
{
}
public function bar($foo, $bar)
{
}
}
我得到这样的输出:
➜ reflection php bin/parser.php
/**
* Lorem ipsum dolor sit amet
*
* @param string $foo kung-foo
* @param array $bar array of mars bars
*
* @return void
*
*/
TestClass::foo($foo, array $bar)
TestClass::bar($foo, $bar)
我认为这是你想要的。