NetBeans的插件,用于创建类模板

I am looking for plugin for NetBeans PHP (or it can be some external tool) that would do something like that:

  • When run it asks for a class name and the names of private attributes (and their types) of this class
  • Then it generates this class with:
    • all listed attributes with types in vdoc format,
    • constructor that takes all the attributes as parameters and initialize class attributes with those values,
    • default getters and setters.

I know it's not difficult to write such tool, but maybe it already exists.

Netbeans has some built-in functionality similar to this already. In any PHP project, create a new PHP Class (right click a folder in the project, New -> PHP Class). Enter your properties, such as:

class user
{
    private $id;
    private $username;
    private $email;
    private $firstname;

    | <-- position the cursor here and press Alt+Insert
}

Alt+Insert will bring up a menu that allows you to generate a constructor, getters, and setters to assign values to your properties.

If you want to do more, you can look at this Netbeans article on code generation.

There's not such plugin for NetBEans (AFAIK), but it's not the job for it anyway. Such classes can be created automatically from YAML/XML/database schema meta data. ORMs usually have tools for that, but creating your own should not be difficult either.