Please add the default namespace to the PHP templates, so a user would have the namespace already in the file. I've chosen Symfony2 framework here because it seems more... guessable what to namespace to have in a new framework, but in general this option would very nice play with PHP.
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.
*** Bug 152507 has been marked as a duplicate of this bug. ***
Integrated into 'main-golden', will be available in build *201302152300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: Tomas Mysik <email@example.com>
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.
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).
> 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>
(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.
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)