PHP 10.0 Blog

What if…

Adding new extensions to Zend Studio

Posted by Stas on September 8, 2010

I am using Zend Studio for my everyday PHP work, and I like it. I know many others do too, or use PDT. It has one very cool – though not widely known – feature that allows you you to add unknown extensions to code completion. I.e., if you have some extension, create stub file with PHPDOC descriptions – i.e. something like this:

/**
 * Do stuff
 * @param string $arg
 * @return array
 */
 function dostuff($arg) {}

for each extension function, Studio will know to pick it up. You can put this file into Studio’s prototypes directory – easiest way to find it is just write something like chdir() anywhere, select the name and press F3, the directory of the file that you’ll get is the one you need.

However, the problem is how to create this file. E.g., I’m doing some work with MongoDB lately, and PHP has great Mongo extension – which Studio doesn’t know yet. So how do I create those stubs? Obviously, I am too lazy to manually write them. I went to look for a tool that would allow me to make one – and found none. At least not in 15 minutes I spent looking, so I decided to write my own.

What came out is the Reflector. It uses PHP reflection and PHP’s manual XML sources in order to generate stub file (see example mongo.php on git to check what comes out). Right now it’s not very smart and handles only classes/methods, not functions (probably will fix that soon), but maybe it will be useful to somebody.

Or maybe somebody points me to a tool that does that even better in comments :)

Update: Roy Ganor (who is leading the Zend Studio project) in comments pointed me to the source of the Studio generator script. It will generate stubs for all extensions you have, as I can see. Try it out. Thanks, Roy!

About these ads

10 Responses to “Adding new extensions to Zend Studio”

  1. Bookmarked.

    Thanks :)

  2. Roy Ganor said

    Good point, we should have document it somewhere…
    Anyway, use the following php script to generate stub files for your favorite extensions: http://bit.ly/9UdAYY

    • Stas said

      Your script is much more advanced, but I see the idea is the same. Maybe you could ship it with Studio? :)
      The recipe for adding stubs I found on Zend forums, but generator script was not mentioned anywhere. I think I’ll add an update.

    • Good old times :) I remember these days when Michael & me discussed how to build this script…

      • Michael Spector said

        Yea, it was a good time… The bad thing is that PHP documentation doesn’t have a specification, that’s why this script is a bit ugly :-)

  3. Thanks, I’d been wondering about something like this, also through working with MongoDB lately.

    I wouldn’t encourage people to click on shortened URLs in blog comments, though. What’s wrong with the real URL?

  4. Muc said

    Hi:

    I have tried the generate.php script, but I can’t get anything generated :(

    Here is the output I got:


    PHP Notice: Undefined variable: functionsDoc in /var/www/SolrTest/generate.php on line 256
    PHP Stack trace:
    PHP 1. {main}() /var/www/SolrTest/generate.php:0
    PHP 2. parse_phpdoc_functions() /var/www/SolrTest/generate.php:45
    PHP Notice: Undefined variable: classesDoc in /var/www/SolrTest/generate.php on line 352
    PHP Stack trace:
    PHP 1. {main}() /var/www/SolrTest/generate.php:0
    PHP 2. parse_phpdoc_classes() /var/www/SolrTest/generate.php:46
    PHP Notice: Undefined variable: constantsDoc in /var/www/SolrTest/generate.php on line 385
    PHP Stack trace:
    PHP 1. {main}() /var/www/SolrTest/generate.php:0
    PHP 2. parse_phpdoc_constants() /var/www/SolrTest/generate.php:47
    PHP Notice: Undefined index: internal in /var/www/SolrTest/generate.php on line 88
    PHP Stack trace:
    PHP 1. {main}() /var/www/SolrTest/generate.php:0

    I run using the following command:

    php generate.php -split ~/Downloads/docs/
    

    Thanks!

  5. Zend Studio is pretty awesome!

  6. MrWonderful said

    The generator link appears to be out of date due to eclipse moving from cvs to git. Is there an updated link? thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: