Komodo是否支持getter/setter自動生成NetBeans或Eclipse?如果是這樣,我該如何使用它?我似乎無法找到它。PHP Komodo getter/setter自動生成
4
A
回答
1
我不認爲科莫多[編輯/打開]支持它,不確定科莫多IDE。
0
0
這是沒有辦法完全或成品,但這裏有一個科莫多6兼容蟒蛇宏腳本我寫的自動生成一個完整的PHP類制定者/吸氣。
from xpcom import components
import re
viewSvc = components.classes["@activestate.com/koViewService;1"]\
.getService(components.interfaces.koIViewService)
view = viewSvc.currentView.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz
sm.currentPos # current position in the editor
sm.text # editor text
sm.selText # the selected text
#sm.text = "Hello World!"
output = u"\n"
setterTemplate = """
function set%s($value){
$this->%s = $value;
}
"""
getterTemplate = """
/**
*@return string
*/
function get%s(){
return $this->%s;
}
"""
propertyTemplate = """
%s
%s
"""
prefixSize = len(u"private $")
def formalName(rawName):
return u"%s" % "".join([part.title() for part in rawName.split("_")])
#todo find a better way to split lines, what if its Mac or Windows format?
for line in sm.text.split("\n"):
if line.strip().startswith("private $"):
#trim of the private $ and trailing semi-colon
realName = line.strip()[prefixSize:-1]
output += propertyTemplate % (setterTemplate %(formalName(realName), realName), getterTemplate % (formalName(realName), realName))
sm.insertText(sm.currentPos, output)
給喜歡用類酒吧foo.php作爲目前
class Bar {
private $id;
private $name_first;
}
唯一一個文件中,它注入
function setId($value){
$this->id = $value;
}
/**
*@return string
*/
function getId(){
return $this->id;
}
function setNameFirst($value){
$this->name_first = $value;
}
/**
*@return string
*/
function getNameFirst(){
return $this->name_first;
}
這對我的使用不夠好(我可以雷泰一切很快),但我會更新這個答案,如果我在腳本上大大提高。
1
這是大衛的代碼修改後的版本,並用正確的行結束工作:
from xpcom import components
import re
viewSvc = components.classes["@activestate.com/koViewService;1"]\
.getService(components.interfaces.koIViewService)
view = viewSvc.currentView.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz
sm.currentPos # current position in the editor
sm.text # editor text
sm.selText # the selected text
output = u"\n"
setterTemplate = """
function set%s($value){
$this->%s = $value;
}
"""
getterTemplate = """
/**
*@return string
*/
function get%s(){
return $this->%s;
}
"""
propertyTemplate = """
%s
%s
"""
prefixSize = len(u"private $")
def formalName(rawName):
return u"%s" % "".join([part.title() for part in rawName.split("_")])
eol = u"\n" #UNIX \n (default) sm.eOLMode == 2
if sm.eOLMode == 0: #DOS/Windows \r\n
eol = u"\r\n"
elif sm.eOLMode == 1: #Mac Classic \r
eol = u"\r"
for line in sm.text.split(eol):
if line.strip().startswith("private $"):
#trim of the private $ and trailing semi-colon
realName = line.strip()[prefixSize:-1]
output += propertyTemplate % (setterTemplate %(formalName(realName), realName), getterTemplate % (formalName(realName), realName))
output = output.replace("\n", eol)
sm.insertText(sm.currentPos, output)
4
這是修改/改進的版本有一個更可讀的代碼。也會從屬性聲明中刪除默認值,如在public $prop = array();
from xpcom import components
import re
viewSvc = components.classes["@activestate.com/koViewService;1"]\
.getService(components.interfaces.koIViewService)
view = viewSvc.currentView.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz
sm.currentPos # current position in the editor
sm.text # editor text
# sm.selText # the selected text
output = u"\n"
setterTemplate = """
/**
* Sets %s
*
* @param mixed $value
* @return $this
*/
public function set%s($value) {
$this->%s = $value;
return $this;
}"""
getterTemplate = """
/**
* Gets %s
*
* @return string
*/
public function get%s() {
return $this->%s;
}
"""
propertyTemplate = """%s
%s"""
prefixSizePv = len(u"private $")
prefixSizePu = len(u"public $")
prefixSizePr = len(u"protected $")
def formalName(rawName):
return u"%s%s" % (rawName[0:1].upper(), rawName[1:])
#todo find a better way to split lines, what if its Mac or Windows format?
for line in sm.text.split("\n"):
tmpLine = line.strip()
hasPriv = tmpLine.startswith("private $")
hasPublic = tmpLine.startswith("public $")
hasProt = tmpLine.startswith('protected $')
if hasPriv or hasPublic or hasProt:
if hasPriv:
realName = tmpLine[prefixSizePv:-1]
elif hasPublic:
realName = tmpLine[prefixSizePu:-1]
else:
realName = tmpLine[prefixSizePr:-1]
realName = re.sub('\s?=.*', '', realName);
formal = formalName(realName)
output += propertyTemplate % (setterTemplate %(realName, formal, realName), getterTemplate % (realName, formal, realName))
sm.insertText(sm.currentPos, output)
+0
的受保護變量令人驚歎,謝謝 – Tom 2014-06-02 10:28:59
相關問題
- 1. 自動生成PHP
- 2. php __autoload():自動生成類
- 3. Excel VBA自動生成的php表格由php生成
- 4. Komodo編輯10自動完成不顯示選項的列表
- 5. 在php中自動生成用戶名
- 6. PHP自動生成在同一文件
- 7. 自動從PHP類生成類圖嗎?
- 8. 在PHP中自動生成META標記
- 9. 自動生成PHP代碼的策略?
- 10. 自動生成頭
- 11. 自動生成ID
- 12. 生成NSManagedObjectSubclass自動
- 13. 自動生成ID
- 14. 自動生成HTML
- 15. 生成自動ID
- 16. 自動生成WebControls
- 17. 自動生成.net
- 18. Gettext自動評論生成
- 19. 自動生成文件生成命令
- 20. 自動生成註釋
- 21. 自動完成動態生成的div
- 22. 使用php,codeigniter自動生成醫生單位ID!
- 23. Makefile bash自動完成問題與PHP生成的目標
- 24. jquery自動完成與PHP foreach生成結果
- 25. php:動態生成JNLP?
- 26. 生成腳本自動
- 27. WCF自動生成FaultContracts
- 28. 防止ID自動生成
- 29. 自動生成列空值
- 30. 管理自動生成
等等,Eclipse是否這樣做?或者你的意思是Zend Studio? – 2010-08-12 17:27:35
我應該澄清一下 - Eclipse是爲Java做的。 – ashurexm 2010-08-12 21:10:33