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
- 3. PHP自动生成salaryslip
- 4. php __autoload():自动生成类
- 5. Excel VBA自动生成的php表格由php生成
- 6. 自动生成
- 7. 如何将Komodo Edit 7自动完成C?
- 8. Komodo编辑10自动完成不显示选项的列表
- 9. 用PHP自动生成图库
- 10. 从文件夹中自动生成PHP
- 11. 在php中自动生成用户名
- 12. PHP自动生成在同一文件
- 13. PHP自动生成新页面
- 14. 自动生成表单字段在PHP
- 15. 自动生成PHP代码的策略?
- 16. PHP自动生成PDF文件?
- 17. 自动从PHP类生成类图吗?
- 18. 在PHP中自动生成META标记
- 19. PHP自动生成链接每月
- 20. 自动生成ID
- 21. 自动生成HTML
- 22. 自动生成.net
- 23. 生成NSManagedObjectSubclass自动
- 24. 自动生成头
- 25. 生成自动ID
- 26. 自动生成ID
- 27. 自动生成WebControls
- 28. 自动生成angularjs
- 29. etags自动生成
- 30. 自动生成guis?
等等,Eclipse是否这样做?或者你的意思是Zend Studio? – 2010-08-12 17:27:35
我应该澄清一下 - Eclipse是为Java做的。 – ashurexm 2010-08-12 21:10:33