IDE autocomplete for PhalconPHP

19,294

Solution 1

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

Solution 2

I am not sure about Netbeans and its compatibility with regards to files that offer autocomplete in other IDEs but there is already support available for PHPStorm

How do I use phalcon-devtools\ide\phpstorm in phpstorm?

There is also support for Volt in Sublime Text

https://github.com/phalcon/volt-sublime-textmate

Solution 3

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

Share:
19,294
Eugene Manuilov
Author by

Eugene Manuilov

Updated on July 27, 2022

Comments

  • Eugene Manuilov
    Eugene Manuilov almost 2 years

    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 ) {}
    
        ...
    
    }
    
  • Eugene Manuilov
    Eugene Manuilov about 11 years
    Thanks Gordon for starting point. If nobody gives better answer, will mark yours as correct in a couple of days, but now take an upvote from me.
  • Eugene Manuilov
    Eugene Manuilov about 11 years
    Thank you very much! This is what I was looking for!!!
  • Patrioticcow
    Patrioticcow about 10 years
    in the External Libraries add a path to phalcon-devtools\ide\1.3.1\Phalcon
  • JREAM
    JREAM about 7 years
    For version 3 I added my global path: /usr/local/share/composer/vendor/phalcon-devtools/ide