PHP Getters and Setters
generare getters and setters for php classes
Details
Installs
- Total 57K
- Win 30K
- Mac 12K
- Linux 14K
Mar 30 | Mar 29 | Mar 28 | Mar 27 | Mar 26 | Mar 25 | Mar 24 | Mar 23 | Mar 22 | Mar 21 | Mar 20 | Mar 19 | Mar 18 | Mar 17 | Mar 16 | Mar 15 | Mar 14 | Mar 13 | Mar 12 | Mar 11 | Mar 10 | Mar 9 | Mar 8 | Mar 7 | Mar 6 | Mar 5 | Mar 4 | Mar 3 | Mar 2 | Mar 1 | Feb 28 | Feb 27 | Feb 26 | Feb 25 | Feb 24 | Feb 23 | Feb 22 | Feb 21 | Feb 20 | Feb 19 | Feb 18 | Feb 17 | Feb 16 | Feb 15 | Feb 14 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 7 | 0 | 2 | 0 | 0 | 2 | 1 | 0 | 2 | 1 | 2 | 1 | 2 | 1 | 1 | 0 | 1 | 2 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 3 | 1 | 2 | 0 | 0 | 0 | 1 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
Linux | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
Readme
- Source
- raw.githubusercontent.com
PHP Getters and Setters
With PHP Getters and Setters you can automatically generate Getters and Setters for your php classes.
Features:
- Generate Getters, Setters or Both
- Can be applied to all class properties or just to a single one
- Description, Type and Type Hinting automatically discovered from the variable docblock
- fully customizable templates
Usage Instruction:
Generate PHP code
class test { /** * foo container * * @var AbcClass */ private $foo; }
Go to Tools -> PHP Getters and Setter
Getter and Setter will be generated:
class test { /** * foo container * * @var AbcClass */ private $foo; /** * Gets the foo container. * * @return AbcClass */ public function getFoo() { return $this->foo; } /** * Sets the foo container. * * @param AbcClass $foo the foo */ private function _setFoo(AbcClass $foo) { $this->foo = $foo; return $this; } }
As you can see if get to trouble of commenting your variables, the generated functions can be used without modification.
This is an huge time saver!
Usage
Commands available are:
- Generate Getters and Setters
- Generate Getter
- Generate Setter
- Generate Getter for…
- Generate Setter for…
These can be accesed via the context menu (right click on the source of any open PHP file) or the command pallette. The currently open file must be a PHP file.
Settings Reference
ignore_visibility
type : boolean
default : false
description: ignore visibilty for setters generation
registerTemplates
type : array
default: []
description: the user templates to load
template
type : string
default: camelCaseFluent
description: the template to use
type_hint_ignore
type: list of strings
default: [“mixed”, “int”,“integer”, “double”, “float”, “number”, “string”, “boolean”, “bool”, “numeric”, “unknown”]
description: if the property has one of the types listed type hinting will not be used
setter_before_getter
type: boolean
default: false
description: Set to true to generate setter code before getters
Creating your own template
[package-dir] is your package directory.
- Make a directory called
[package-dir]/PHP Getters and Setters
. Put the following in a file at
[package-dir]/PHP Getters and Setters/user_templates.py
. “ class myTemplate(object): name = "myTemplate” style = 'camelCase' # can also be snakeCase getter = “”“ /**- Gets the %(description)s. *
- @return %(type)s */ public function get%(normalizedName)s() { return $this->%(name)s; } ”“”
setter = “”“ /** * Sets the %(description)s. * * @param %(type)s $%(name)s the %(humanName)s * * @return self */ public function set%(normalizedName)s(%(typeHint)s $%(name)s) { $this->%(name)s = $%(name)s; } ”“”
* Edit the parts between setter and getter how you want.
* Edit your user settings for this package. On OSX that's ```Preferences | Package Settings | PHP Getters and Setters | Settings - User```.
* Add the following settings
// user defined templates to load
"registerTemplates" : [ "myTemplate" ],
// the template used to generate code
"template" : "myTemplate",
* restart sublime to use the new template