Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDE autocomplete for PhalconPHP [closed]

Is there exist any kind of skeleton for PhalconPHP framework, which I can use in my Netbeans IDE for autocompletion purposes?

All I need is a heap of files with class/interface declarations, like this:

namespace \Phalcon;

class Tag {

    /**
     * bla bla bla
     * ...
     */
    public static function setTitle( $title ) {}

    ...

}
like image 658
Eugene Manuilov Avatar asked Apr 04 '13 10:04

Eugene Manuilov


2 Answers

Maybe you're looking for this? Phalcon DevTools https://github.com/phalcon/phalcon-devtools/tree/master/ide

like image 100
Sergey Ilin Avatar answered Oct 12 '22 14:10

Sergey Ilin


You can distill the interfaces with my InterfaceDistiller:

namespace com\github\gooh\InterfaceDistiller;
include __DIR__ . '/../src/autoload.php';

var_dump( extension_loaded('phalcon') ); // should be true

$phalconClasses = new \RegexIterator(
    new \ArrayIterator(get_declared_classes()),
    '/^Phalcon/'
);

foreach ($phalconClasses as $phalconClass)
{
    $reflector = new \ReflectionClass($phalconClass);
    $methodIterator = new \ArrayIterator($reflector->getMethods());

    $distillate = new Distillate;
    $distillate->setInterfaceName($reflector->getNamespaceName());
    $distillate->setExtendingInterfaces(
        implode(',', $reflector->getInterfaceNames())
    );

    foreach ($methodIterator as $method) {
        $distillate->addMethod($method);
    }

    $file = new \SplTempFileObject(-1);
    $writer = new Distillate\Writer($file);
    $writer->writeToFile($distillate);
    $file->rewind();
    $file->fpassthru();
}

This will then produce the following output:

<?php
interface Phalcon
{
    public function __clone();
    public function __construct($message /* = unresolvable */, $code /* = unresolvable */, $previous /* = unresolvable */);
    public function getMessage();
    public function getCode();
    public function getFile();
    public function getLine();
    public function getTrace();
    public function getPrevious();
    public function getTraceAsString();
    public function __toString();
}

// this continues for all classes in the extension

See full file holding all distilled interfaces of Phalcon

Note that the InterfaceDistiller can only produce Interfaces. So you won't get a mix of class skeletons and interface, but just Interfaces.

Another gotcha is that the interface methods will all be public because, well, interface methods should be public. You can either tweak the writer to use the real visibility. Or you can limit which methods the Distiller will distill.

As you can see some parts of the API cannot be resolved. This is because InterfaceDistiller uses Reflection to distill the Interface from the classes and some values are not just available this way. Consider filling in the unresolvable values by hand.

While not perfect for your UseCase, it should give you a great headstart though.

If you decide to adapt and complete the file so it's fully usable, consider sending a Pull Request with the entire file to the Phalcon folks

like image 37
Gordon Avatar answered Oct 12 '22 14:10

Gordon