8

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
  • 4,271
  • 8
  • 32
  • 48

3 Answers3

23

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

Sergey Ilin
  • 246
  • 1
  • 2
4

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

Gordon
  • 312,688
  • 75
  • 539
  • 559
  • 1
    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 Apr 04 '13 at 11:34
4

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

Community
  • 1
  • 1
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67