Zend - The PHP Company




Miscellaneous

Add Code


Quick-n-Easy PHP classes  

Type: application
Added by: Stephan
Entered: 03/03/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 5758
A PERL app to quickly create complete PHP classes from the command line.


#!/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





Search



This Category All Categories