Created
August 6, 2015 13:39
-
-
Save V13Axel/e4f1b4d3f004b62e0580 to your computer and use it in GitHub Desktop.
Simplifies injecting a property into the constructer as a property, setting it in the constructor, and defining the class property. I add
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