PHP getter/setter macro
Submitted by Thursday, 7 October, 2004 - 16:53
on
Hey Folks.
Over the weekend I started working on a new project and was laying the infrastructure/groundwork out for everything .. doing up the class libs and what not .. I used DB_DataObject a lot in the past to generate my db class object code, but I decided to use my own rolled DbObject class and found myself writting millions of getters/setters for my class files.
Anyway, I got bored of that and found a macro someone wrote (and is posted somewhere on the site) which generates getters/setters for a c or java file and figured, what the heck, let's tweak that for php.
So I did ... and have it working for me somehow ok .. you just highlite the vars, run the macro and it whips them out, you can even select to use javadoc style comments or not.
The original author did a great job, kudos to him/her, wherever they are ... if anyone is interested in using this hacked-for-php version, I can post it somewhere here .. there are a few idiosincrosies I guess that make it work the way I work, but it's a start at least. For instance, for some reason I my db variables/columns use_this_approach to var naming ... when I code, I use studlyCaps, so my class files look like this.
hah ... interesting, eh? Don't know why I do that, but anyway ... that's how "my" .bsh macro does the getters/setters, but you can hack it pretty easily to work like you do (in a php4 style too, if necessary)... there's more work to be done to make the macro more helpful/slick but if anyone might find it helpful for now, I'll throw her up somewhere ...
-steve
Anyway, I got bored of that and found a macro someone wrote (and is posted somewhere on the site) which generates getters/setters for a c or java file and figured, what the heck, let's tweak that for php.
So I did ... and have it working for me somehow ok .. you just highlite the vars, run the macro and it whips them out, you can even select to use javadoc style comments or not.
The original author did a great job, kudos to him/her, wherever they are ... if anyone is interested in using this hacked-for-php version, I can post it somewhere here .. there are a few idiosincrosies I guess that make it work the way I work, but it's a start at least. For instance, for some reason I my db variables/columns use_this_approach to var naming ... when I code, I use studlyCaps, so my class files look like this.
class Something { protected $first_var; // <-- this is how it's named in the db // and the getter/setter for that looks like // {{{ Getters /** * javadoc */ public function getFirstVar($first_var) { $this->first_var = $first_var; } // }}} End Getters // {{{ Setters /** * javadoc */ public function getFirstVar() { return $this->first_var; } // }}} End setters } // class
hah ... interesting, eh? Don't know why I do that, but anyway ... that's how "my" .bsh macro does the getters/setters, but you can hack it pretty easily to work like you do (in a php4 style too, if necessary)... there's more work to be done to make the macro more helpful/slick but if anyone might find it helpful for now, I'll throw her up somewhere ...
-steve