This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Automatically add namespace to a new PHP class | ||
---|---|---|---|
Product: | php | Reporter: | Monomachus |
Component: | Project | Assignee: | Tomas Mysik <tmysik> |
Status: | VERIFIED FIXED | ||
Severity: | normal | CC: | kanakmar, naitsirch, ppisl, tmysik, vriha |
Priority: | P2 | ||
Version: | 7.2 | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: | |
Bug Depends on: | 226157 | ||
Bug Blocks: | |||
Attachments: | Screenshot of the "new file wizard" and a newly created file. |
Description
Monomachus
2012-03-10 04:08:10 UTC
Well, the problem here is - where to get the namespace? From the wizard (for the new file)? Thanks for reporting. That would be a great feature! Maybe Netbeans could look in the folder where the file should be created or in it's parent folders and guess the namespace from the classes there, when the wizard (for the new file) is opened. In a text field the guessed namespace could be outputed. A further idea would be to set a "default" namespace in the folders (maybe in the wizard, too). In this case the same guessing could be used as mentioned above. Thanks for your great work! (to all NB developers) > A further idea would be to set a "default" namespace in the folders (maybe
> in the wizard, too). In this case the same guessing could be used as
> mentioned above.
A little bit clearer: The default namespace could be a property of the folder guessed and editable in the 'New Folder' wizard.
Yeah like naitsirch said we need to have the guessed namespace in the File Wizard, so if user don't like it he could change it. That would be the first step to do. Than we could have an autocompletion (or something like 10 recently used namespaces) from all the namespaces already used in the projects files, so the user could choose from there. But again the first step would need to be done first, and than we could do something further. Namespace could be guessed from the folder structure, as defined in PHP's PSR-0 standard (see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md ). At least if the folder, where a new class/file is created, already contains other PHP files with namespace, Netbeans could guess that the newly created class will be in the same namespace. +1 for PSR0 support for namespaces I will try to look at it for the next release. Thanks. *** Bug 152507 has been marked as a duplicate of this bug. *** Minor improvement. http://hg.netbeans.org/web-main/rev/0fa171a946e5 Integrated into 'main-golden', will be available in build *201302152300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/13c832aff786 User: Tomas Mysik <tmysik@netbeans.org> Log: #209402 - Automatically add namespace to a new PHP class How is it resolved, now? Is the namespace added automatically to the new PHP file or do one have to include some special code to the file templates? (In reply to comment #12) > How is it resolved, now? > Is the namespace added automatically to the new PHP file or do one have to > include some special code to the file templates? Try it in the dev build; the new file wizard has been improved. Thanks. Created attachment 131882 [details]
Screenshot of the "new file wizard" and a newly created file.
Hi. In the wizard the namespace has been detected correctly, but the created file does not contain the namespace declaration. How can I achieve that? Do I have to add something to the PHP Code Templates?
Great work so far ;)
@naitsirch: You have your own template; recreate it from the bundled one (it contains code for namespace). Thanks. > recreate it from the bundled one (it contains code for namespace).
I see. Now it works :)
Maybe this could be documented anywhere. Otherwise people won't see this great feature, when they install the new version and Netbeans copies the templates from an earlier NetBeans installation.
This is the directive to insert the guessed namespace in the PHP file template:
<#if namespace?? && namespace?length > 0>
namespace ${namespace};
</#if>
(In reply to comment #16) > Maybe this could be documented anywhere. Frankly, nearly nobody reads documentation... Moreover, it is perfectly OK that NetBeans will _not_ change any custom (user defined) template. Thanks. The most correct way how to inform users is to blog about it ;) (In reply to comment #18) > The most correct way how to inform users is to blog about it ;) Agreed, and this is going to happen soon ;) Verified, if target folder contains classes with some namespaces, these are offered in New File wizard Product Version: NetBeans IDE Dev (Build 201303112300) Java: 1.7.0_15; Java HotSpot(TM) Client VM 23.7-b01 Runtime: Java(TM) SE Runtime Environment 1.7.0_15-b03 System: Linux version 3.2.0-38-generic-pae running on i386; UTF-8; en_US (nb) |