The creator and first maintainer of this project is Vsevolod Vietluzhskykh
Extension that adds naive IDE-like file creation.
!IMPORTANT! For now tested only under *nix and Windows 7.
I like using Visual Studio Code. But I was not satisfied with the process of creating PHP files. It always involves at least two steps: creation of the file and creation of the content. Even if you use snippets or templates you have to provide name twice. Even further, if you follow PSR-4 (and nowadays you should try to always follow it) you have to add namespace yourself.
For now this feature is available to you if you place .php-files.json
to the root of your project:
{
"namespaces": {
"Foo": "src"
}
}
I'm going to provide the ability to retrieve namespaces from composer.json
.
For now you have the following options for creating files from Explorer context menu:
- Select
New PHP Class
from the context menu inside Explorer. - Enter full PHP Class name (e.g. 'Foo\Bar\Baz') and press enter to proceed or enter escape to discard.
- Enter parent PHP Class name. You can leave it empty and press enter to proceed to the implements, or short-exit with escape to create class without extends or implements.
- Enter PHP Interfaces names (can be separated by comma).
- Select
New PHP Interface
from the context menu inside Explorer. - Enter full PHP Interface name (e.g. 'Foo\Bar\Baz') and press enter to proceed or enter escape to discard.
- Enter PHP Interfaces names (can be separated by comma).
- Select
New PHP Trait
from the context menu inside Explorer. - Enter full PHP Trait name (e.g. 'Foo\Bar\Baz') and press enter to proceed or enter escape to discard.
This extension contributes the following settings:
// Template for PHP Class
"php-files.templates.PHPClass": [
"<?php",
"class PHPClass",
"{",
"}"
],
// Template for PHP Interface
"php-files.templates.PHPInterface": [
"<?php",
"interface PHPInterface",
"{",
"}"
],
// Template for PHP Trait
"php-files.templates.PHPTrait": [
"<?php",
"trait PHPTrait",
"{",
"}"
],
When you create new files a bunch of new lines created in the end of it. I will investigate this. As a temporary solution you can set file of the vscode itself to remove them on save settings:
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
- Allow using of commands from the command palette.
- Implement tests.
- Implement
PHP File Rename
- Implement
PHP File Duplicate
All the hardcore PHP AST staff is done by php_writer, which itself uses following great libraries:
I cannot thank the creators and contributers of those packages enough!