Skip to content

Commit

Permalink
akalongman#17 add PHP Object to Array Access conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Twista committed Oct 2, 2016
1 parent 4ca7832 commit a32b581
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
{ "command": "string_utilities_int_ip", "caption": "Insert Internal IP" },
{ "command": "string_utilities_ext_ip", "caption": "Insert External IP" },
{ "caption": "-" },
{ "command": "string_utilities_decode_json", "caption": "Pretify JSON String" }
{ "command": "string_utilities_decode_json", "caption": "Pretify JSON String" },
{ "caption": "-" },
{ "command": "php_object_to_array", "caption": "Convert PHP Object to Array" }

]
},
{ "caption" : "-", "id" : "context-convert-end"}
Expand Down
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
{
"caption": "String Utilities: Decode JSON",
"command": "string_utilities_decode_json"
},
{
"caption": "String Utilities: PHP object to array",
"command": "php_object_to_array"
}
]
32 changes: 32 additions & 0 deletions stringutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,35 @@ def enc(self):
return self.view.settings().get('default_encoding', 'UTF-8')
else:
return self.view.encoding()


class PhpObjectToArrayCommand(sublime_plugin.TextCommand):
"""
convertes PHP Object into PHP Array Access
from $obj->variable into $obj['variable']
"""

def run(self, edit):
for region in self.view.sel():
if not region.empty():
source_text = self.view.substr(region)
if "->" not in source_text:
# nothing to replace
pass

fragments = source_text.split("->")
result = "{}['{}']".format(fragments[0], fragments[1])

self.view.replace(edit, region, result)












0 comments on commit a32b581

Please sign in to comment.