Skip to content

Instantly share code, notes, and snippets.

@V13Axel
Created August 6, 2015 13:39
Show Gist options
  • Save V13Axel/e4f1b4d3f004b62e0580 to your computer and use it in GitHub Desktop.
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
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