Bug 182655 - Extend autocompletion in PHP editor for custom frameworks, which do not use new... for class instanciation
Extend autocompletion in PHP editor for custom frameworks, which do not use n...
Status: NEW
Product: php
Classification: Unclassified
Component: Editor
6.x
PC Mac OS X
: P2 with 23 votes (vote)
: TBD
Assigned To: Ondrej Brejla
issues@php
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-03-24 10:59 UTC by skurfuerst
Modified: 2017-02-17 15:49 UTC (History)
4 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description skurfuerst 2010-03-24 10:59:40 UTC
I was curious if it is possible to extend the autocompletion of PHP via a custom NetBeans module. The main reason is the following:

In our framework (TYPO3 / FLOW3), we do not use the new-Keyword to create new classes, but we use a static utility class t3lib_div::makeInstance('nameOfClass'); respectively $objectManager->create('NameOfClass');
However, right now, it is not possible to have autocompletion for these classes available, as of course NetBeans does not know about the type, and it does not know that the first parameter to these methods are actually class names.

Yesterday, I stumbled about a great eclipse wiki page, which describes that the autocompletion and type-inference mechanisms can be extended in the upcoming PDT 2.2: http://wiki.eclipse.org/Extending_PDT_2.2 .

It'd be cool to have a similar feature available in NetBeans as well. I think it consists of two parts:
- Tell the framework that (f.e.) t3lib_div::makeInstance('... should yield a list of class names for autocompletion
- When doing $variable = t3lib_div::makeInstance(...), use the class name from the first parameter as type hint for $variable, so autocompletion on $variable will work.

Greets,
Sebastian
PS: I have looked at http://blogs.sun.com/netbeansphp/entry/code_completion_for_a_class  and others, and I know that one can use /** @var ... */ annotations in front of such a "new" statement, to tell NetBeans the class. However, for us, this is not an option as we already have a huge codebase and this would conflict with out coding guidelines.
Comment 1 pcdinh 2010-05-30 13:03:07 UTC
Why not use an interface to represent the return type?

Your requirement is too Typo3 design specific so I don't think it is doable without making things complicated. However I am not a NB developer. So I think we need to wait for the feedback from the core team
Comment 2 karsten 2010-05-31 12:05:06 UTC
(In reply to comment #1)
> Why not use an interface to represent the return type?

Because those methods return whatever you ask them for. There is an interface for the FLOW3 object manager, but the create method has "@return object" for that reason.

> Your requirement is too Typo3 design specific so I don't think it is doable
> without making things complicated.

It is perfectly possible with PDT now (see http://www.twitvid.com/RIU0N and http://github.com/skurfuerst/org.typo3.eclipse.extender), and I dare to say they don't give a damn about TYPO3. This would be useful for any factory code that is capable of creating more than one type. FLOW3 and TYPO3 are certainly not the only one's doing that.
Comment 3 Filip Zamboj 2010-09-15 12:31:04 UTC
batch reassigning
Comment 4 masi 2010-10-05 14:28:31 UTC
Magento (the shop system) has a Mage::getModel('module/class') method. So TYPO3 isn't the only system the uses a "magic factory".
Comment 5 fmntf 2012-03-06 22:27:29 UTC
I confirm this is widely used. A very common example is DI containers.
Comment 6 junichi11 2013-03-06 12:19:52 UTC
I would like to run code completion like this issue with plugin.
e.g. In the following case of CakePHP Framework, $post is Post class:
class SomeController extends AppController {
    public function index(){
        $post = ClassRegistry::init('Post');
    }
}

But NetBeans will not be able to recognize it as a post class within class methods.I don't know how to implement it with plugin.
If this feature is implemented, many NetBeans users will be more happy!
I strongly hope it.

Thanks!
Comment 7 Xenos 2017-02-17 15:49:17 UTC
And what about using a PHPDoc comment like

        /* @var $post \Post */
        $post = ClassRegistry::init('Post');

?

This would avoid you the pain on writing *and maintaining* a plugin. 

Setup a code template (Tools/Options/Editor/Code Templates in NB8.2) if you want to avoid the "pain" of writing these two lines every time.

Such code template will be WAY easier to do than a plugin and core changes.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo