PhpCodeGen
PhpCodeGen is a Sublime Text 2 and 3 Plugin that generates Object Oriented Code from a simple shorthand syntax.
Details
Installs
- Total 17K
- Win 11K
- Mac 2K
- Linux 3K
Dec 21 | Dec 20 | Dec 19 | Dec 18 | Dec 17 | Dec 16 | Dec 15 | Dec 14 | Dec 13 | Dec 12 | Dec 11 | Dec 10 | Dec 9 | Dec 8 | Dec 7 | Dec 6 | Dec 5 | Dec 4 | Dec 3 | Dec 2 | Dec 1 | Nov 30 | Nov 29 | Nov 28 | Nov 27 | Nov 26 | Nov 25 | Nov 24 | Nov 23 | Nov 22 | Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- bitbucket.org
PhpCodeGen
PhpCodeGen is a Sublime Text Plugin that generates Object Oriented Code from a simple shorthand syntax.
New: Supports Sublime Text 2 and 3
Before:
After:
Introduction
With PhpCodeGen for Sublime Text, you can generate Object Oriented code with docblocks that are fully customizable extremely fast with just a few lines of code. With PhpCodeGen, you can generate hundreds of properly formatted stubs for classes, interfaces, properties, constants, and methods.
Install From Package Control:
- Search for PhpCodeGen
Install Manually:
- Create a folder in the packages directory called “PhpCodeGen”
- Download the latest tag, unzip and place the files in the “PhpCodeGen” directory.
Auto Complete:
Set the syntax mode to php and start typing '@' and suggestions will start to populate.
Video Tutorial:
I made a brief video on how to use the plugin and uploaded it to youtube. http://www.youtube.com/watch?v=WV_NhVxrYwY
Warnings
All commands must have no spaces or tabs before them to be parsed. PhpCodeGen will automatically indent the commands output appropriately.
This is correct and will be parsed:
@class test
This is incorrect and will not be parsed:
@class test
If an option takes an argument, make sure there is a space before the option's argument:
This is correct:
@class -tag MyTagGroupName
This is incorrect:
@class -tagMyTagGroupName
Default Settings
PhpCodeGen comes with the following default settings:
{
"docblockTagGroup": {
},
"debugMode": true,
"autoGenerateDockBlocks": true,
"numberOfSpaces": 0,
"newLinesAfterClassDeclaration": 0,
"newLinesBeforeClassClosingBrace": 1,
"newLinesAfterMethodDeclaration": 2,
"newLinesBeforeMethodClosingBrace": 2,
"newLinesAboveClassDocBlock": 1,
"newLinesBelowClassDocBlock": 1,
"newLinesAboveConstantDockBlock": 1,
"newLinesBelowConstantDockBlock": 1,
"newLinesAbovePropertyDockBlock": 1,
"newLinesBelowPropertyDockBlock": 1,
"newLinesAboveMethodDockBlock": 2,
"newLinesBelowMethodDockBlock": 1,
"defaultMethodVisibility": "public",
"defaultPropertyVisibility": "protected",
"openingCurlyBraceOnSameLine": true
}
Commands API
@ class | @ c
Generates a class. The last argument is the class name.
Basic Example:
@class MyClass
Output:
/**
* MyClass documentation goes here...
*/
class MyClass {
Options
Abstract Class
-a
Tag group:
Applies user defined tags to the docblock
-tag
Class extends other class
-e ExtendedClassName
Implements interface(s). You may specify multiple interfaces by using a ',' as shown below. However there cannot be any space between multiple interfaces.
-i Interface1,Interface2
Example:
@class -a -e ExtendedClass -i Interface1,Interface2 MyClass
Output:
/**
* MyClass
*/
abstract class MyClass extends ExtendedClass implements Interface1, Interface2 {
@ endClass | @ ec
Ends the class declaration and creates the closing curly brace
@ interface | @ i
Generates an interface. You may specify multiple inheritance of interfaces by using a ',' as shown below. However there cannot be any space between multiple interfaces.
Options
Applies user defined tags to the docblock
-tag
Extended Interfaces
-e
Example:
@interface -e InterfaceA,InterfaceB MyInterface
Output:
/**
* MyInterface documentation goes here...
*/
interface MyInterface extends InterfaceA, InterfaceB {
@ endInterface | @ ei
Ends the interface declaration and creates the closing curly brace
@ const
Creates a constant
Basic Example:
@const AGE 15
Output:
/**
* AGE
*/
const AGE = 15;
Options
Wrap constant value in quotes
-q
Example:
@const -q NAME JOE SHMO
Quote Output:
/**
* NAME
*/
const NAME = 'JOE SHMO';
Applies user defined tags to the docblock
-tag
@ property | @ p
Creates a property or class variable. The visibility of the property will default to what is defined in your settings.
Basic Example:
@property strName
Output:
/**
* strName
* @var datatype
*/
protected $strName;
Options
Visibility: public | protected | private
-v
Applies user defined tags to the docblock
-tag
Return type
-t
Static Property
-s
Generate Setter method for property
-set
Generate Getter method for property
-get
Advanced Example:
@property -v private -t int -set -get myAge
Output:
/**
* myAge
* @var int
*/
private $myAge;
/**
* setMyAge
* @param int $value
* @return void
*/
public function setMyAge(int $value) {
$this->myAge = $value;
}
/**
* getMyAge
* @return int
*/
public function getMyAge() {
return $this->myAge;
}
@ method | @ m
Creates a class method
Basic Example:
@method init
Output:
/**
* init
* @return void
*/
public function init() {
}
Visibility: public | protected | private
-v
Applies user defined tags to the docblock
-tag
Static Method
-s
Abstract Method
-a
Final Method
-f
Specify the return type for the Docblock
-r
Method Parameters: See How to use use -p in @ method and @ function command
-p
Advanced Example:
@method -s -v protected -f -p {DataObject:data = null} init
Output:
/**
* init
* @param DataObject $data = null
* @return void
*/
final protected static function init(DataObject $data = null) {
}
@ function | @ f
Creates a standard function
Basic Example:
@function myFunc
Output:
/**
* test
* @return void
*/
function test() {
}
Advance Example:
@function -p {User:objUser = null} -r object initWithUser
Output:
/**
* initWithUser
* @param User $objUser = null
* @return object
*/
function initWithUser(User $objUser = null) {
}
Specify the return type for the Docblock
-r
Applies user defined tags to the docblock
-tag
Static Method
-s
Function Parameters: See How to use use -p in @ method and @ function command
-p
@ php
Creates an opening php tag
@endPhp
Creates a closing php tag
Settings API
DO NOT MODIFY THE DEFAULT SETTINGS! ONLY MAKE CHANGES IN THE USER SETTINGS
The majority of the settings have to deal with the code generation template. Feel free to copy these settings into your user settings and modify them to your liking.
Many of the settings are self explanatory. Discussed below are the ones that can be a little confusing as to what they do.
debugMode - logs debugging information to the console
numberOfSpaces - used for constants and properties. It refers to the space between docblock and constant/property declaration.
docblockTagGroup - Defines user defined tags to apply to a docblock for a command. See How to Use -tag
How to use use -p in @ method and @ function commands
This option is used to generate parameters for your method or function. The parameters must be within curly braces and each parameter must be separated by a comma.
Type hinting and default values are supported. If you do not include the '$' for the parameter value, PhpCodeGen will automatically add it.
Example:
@method -p {TypeHint:localVar, $localVar2, localVar3='default value'} init
Output:
/**
* init
* @param TypeHint $localVar
* @param $localVar2
* @param $localVar3 = 'default value'
* @return void
*/
public function init(TypeHint $localVar, $localVar2, $localVar3 = 'default value') {
}
How to use -tag
The tag option allows you to inject custom docblock tags into the docblock for a command. This is used in conjunction with “docblockTagGroup” in the user settings. The tag option can be applied to all of the commands except:
- @ php
- @ endPhp
The -tag takes a single argument and that is a key within the docblockTagGroup.
You can only apply one docblock tag group per command.
Define your custom tag groups in PhpCodeGen User Settings under the “docblockTagGroup” object.
Example:
"docblockTagGroup": {
"author":
[
{
"tag": "@package",
"value": "MyPackage"
},
{
"tag": "@author",
"value": "Your Name <yourname@yoursite.com>"
}
],
"method":
[
{
"tag": "@since",
"value": "beta"
}
]
}
Here we have two docblock tag groups: “author” and “method”
If you wanted to add an extra dockblock tag group to a command you would do so like this:
@class -tag author MyClass
Output:
/**
* MyClass
* @package Mecdata
* @author Your Name <yourname@yoursite.com>
*/
class MyClass {
Create a shortcut key for PhpCodeGen
- Open Sublime Text
- Goto Preferences->Key Bindings->User
- Add the shortcut to your key bindings:
Example:
{"keys": ["ctrl+t"], "command": "php_code_gen"},
Check out my other plugin: