Skip to content

Instantly share code, notes, and snippets.

@seeruk
Created August 29, 2014 08:33
Show Gist options
  • Save seeruk/a99d8be428c5768b1cda to your computer and use it in GitHub Desktop.
Save seeruk/a99d8be428c5768b1cda to your computer and use it in GitHub Desktop.
Sublime Text 3 PSR1/2 Getter and Setter Snippet
<!--
gs
A time-saving device for creating getters & setters in PHP classes
Based on a snippet originall published by @akrabat:
http://akrabat.com/software/sublime-text-2-snippet-for-php-getter-and-setter-generation/
HOW TO USE
In your PHP class, simply type the following:
gs<TAB><name of your property without a $ sign>
Sublime Text will add the getter and setter to your class, and
name them after your property.
For example, if your property is called $connection, you would
go into your class, and type:
gs<TAB>connection
and Sublime Text will create getConnection() and setConnection()
methods for you.
-->
<snippet>
<content><![CDATA[
/**
* ${2:[description here]}
*
* @return ${3:[type]} ${4:[description]}
*/
public function get${1/(.*)/\u$1/:[ Prop name ]}()
{
return \$this->${1:[ Prop name ]};
}
/**
* ${5:[Description]}
*
* @param ${3/(.*)/\u$1/:[type]} \$${1:[ Prop name ]} ${4/(.*)/\u$1/:[description]}
*
* @return Something
*/
public function set${1/(.*)/\u$1/:[ Prop name ]}(\$${1/(.*)/$1/:[ Prop name ]})
{
\$this->${1:[Prop name ]} = \$${1/(.*)/$1/:[ Prop name ]};
return \$this;
}
]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>gs</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.php</scope>
<!-- Optional: Description to show in the menu -->
<description>Create getter and setter methods</description>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment