Created
August 6, 2015 13:52
-
-
Save V13Axel/e6a09be8a59cfde2a982 to your computer and use it in GitHub Desktop.
(Naively) Simplifies injecting a property into the constructer as a property, setting it in the constructor, and defining the class property in PHP using Sublime Text. Add {"keys": ["ctrl+i"], "command": "insert_property"} to your sublime keymap, then simply place your cursor on a constructor variable and hit "Ctrl+I"! In-action: http://i.imgur.…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
class InsertPropertyCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
beginningOfClass = self.view.find_all(r"<\?php(.*\n)*class(.*\n*)\{")[0].end() | |
constructorFirstLinePos = self.view.find_all(r"__construct(.*\n*).*\{")[0] | |
constructorPos = self.view.find_all(r"__construct(.*\n*){1,10}?\}")[0] | |
selectionWordPosition = self.view.word(self.view.sel()[0]) | |
constructorFirstLineStr = self.view.substr(constructorFirstLinePos) | |
constructorStr = self.view.substr(constructorPos) | |
symbol = self.view.substr(selectionWordPosition) | |
# nextchar = self.view.substr(constructorFirstLinePos.end()) | |
if symbol in constructorFirstLineStr and ("$" + symbol + ";" not in constructorStr): | |
self.view.insert(edit, constructorFirstLinePos.end(), "\n\t\t$this->" + symbol + " = $" + symbol + ';') | |
self.view.insert(edit, beginningOfClass, "\n\n\tprotected $" + symbol + ";") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment