Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manticorp/5216944 to your computer and use it in GitHub Desktop.
Save manticorp/5216944 to your computer and use it in GitHub Desktop.
This gist turns doctrine vars in zend framework to their respective set and get function. Just put your column definitions into a #content container and the returned functions will be put in the #result container. Working jsfiddle: http://jsfiddle.net/Manticorp/Sm5PM/11/
var str = $("#content").html();
var search = /\/\**[\n\r*\*\w @(=}{",)]*\*\/[\r\n\t ]*private *\$(\w*)[ ="\w]*;/g;
$("#content").html("");
var result = str.match(search);
var getFunc;
var setFunc;
while (result = search.exec(str)) {
getFunc = "\tpublic function set" + capFLet(result[1]) + "($var){\n\t\t$this->" + result[1] + " = $var;\n\t}\n\n";
setFunc = "\tpublic function get" + capFLet(result[1]) + "(){\n\t\treturn $this->" + result[1] + ";\n\t}\n\n";
$("#result").append(getFunc);
$("#result").append(setFunc);
}
function capFLet(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment