Miscellaneous
|
|
|
|
#!/usr/bin/perl
# Quick-n-Easy PHP class generator.
# Stephan Beal. Dec 28, '99
# Released into the Public Domain
# Change the FLDS list and CLASSNAME, below, or pass
# class name and all fields on the command line, to make a PHP
# class from that list of fields. If passed on the command line,
# the first parameter is assumed to be
# the class name, and all other args are variables.
@FLDS = ( "foo", "bar" );
$CLASSNAME = "MyClass";
if ( $ARGV[0] ) {
$CLASSNAME=$ARGV[0];
}
$i = 1;
if ( $ARGV[$i] ) {
@FLDS = ();
}
while( $ARGV[$i] ) {
push( @FLDS, $ARGV[$i] );
++$i;
}
print "<?nclass $CLASSNAME {nn";
foreach $f ( @FLDS ) {
print "var $$f;n";
}
print << "_END_";
function $CLASSNAME() {
}
_END_
foreach $f ( @FLDS ) {
print "##########n# $fn";
print "function get$f() { return $this->$f; }n";
print "function set$f( $v ) { $this->$f = $v; }nn";
}
print "nn} # end class $CLASSNAMEn?>n";
|
|
|
Usage Example
|
perl makePHPClass ClassName field1 field2 field3...
|
|
|
Rate This Script
|
|
|
|