Location: PHPKode > scripts > Class Generator > classgenerator/docs/README.txt
PHP ClassGenerator - V1.0
(C) Rottensteiner Stefan, 2008

The PHP ClassGenerator is smart and simple class to create PHP classes, based
on a simple XML description. It' depends on the standard PHP extension XMLReader.

Look into the file examples/example_001.php and see a demonstration of all
core features.

First I have to confess that I've done a lot in Java over the last year and so
I've learned a lot about patterns, coding conventions and naming of
classes and properies. One of the results of my studies is this class generator.

An example XML class description, used in the example:

<?xml version="1.0" standalone="yes" ?>
<Family xmlns:cgen="http://www.example.com/namespaces#ClassGenerator" cgen:factMethod="getInstance" >
	<Mother name="Heidelinde"  inCome="2501.0" >
		<Child cgen:extends="HumanBeeing" name="Anna" sex="female"/>
		<Child name="Lena" sex="female"/>
	</Mother>
	<Father name="Franz" inCome="2500.0"/>
</Family>

As you can see, it's really simple and nearly self explanory:
There are 4 named classes: "Family", "Mother", "Father" and "Child". All of this
are predefined, except the "Child" class - it will be generated on the fly. The
class "Family" is instantiated with a simply static factory method called
"getInstance". Btw., the generator searches also for an attribute called
"factClass" and will use this. In my example there is no such attribute so the
class "Family" will be used.
In order to create the new class "Child", the generator uses the attribute
"extends". Yes - it's optional.

Property setting strategiy:

1. Use a public or protected setter method "set<elementName>" or "set<attributeName>".
2. Use a public or protected setter method "add<elementName>" or "set<attributeName>".
3. Set a public or protected class member called "<elementName>".

A bad side effect is the fact that the generator sometimes has to create  derivated classes in order to access the properties. Hopefully I can  change this in the next release.
Return current item: Class Generator