Coder Social home page Coder Social logo

vscode-php-files's Introduction

PHP Files

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.

A Story Behind

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.

Features

Automatic Namespace Resolution

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.

Files creation

For now you have the following options for creating files from Explorer context menu:

New PHP Class

  1. Select New PHP Class from the context menu inside Explorer.
  2. Enter full PHP Class name (e.g. 'Foo\Bar\Baz') and press enter to proceed or enter escape to discard.
  3. 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.
  4. Enter PHP Interfaces names (can be separated by comma).

php_files_class_creation

New PHP Interface

  1. Select New PHP Interface from the context menu inside Explorer.
  2. Enter full PHP Interface name (e.g. 'Foo\Bar\Baz') and press enter to proceed or enter escape to discard.
  3. Enter PHP Interfaces names (can be separated by comma).

php_files_interface_creation

New PHP Trait

  1. Select New PHP Trait from the context menu inside Explorer.
  2. Enter full PHP Trait name (e.g. 'Foo\Bar\Baz') and press enter to proceed or enter escape to discard.

php_files_trait_creation

Extension Settings

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",
    "{",
    "}"
],

Known Issues

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,

TODO

  • Allow using of commands from the command palette.
  • Implement tests.
  • Implement PHP File Rename
  • Implement PHP File Duplicate

Acknowledgments

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!

vscode-php-files's People

Contributors

mikbox74 avatar sevavietl avatar

Watchers

 avatar

Forkers

coding-liki

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.