There are some attempts to build type safe php objects, but they all have lacks on working with eaccelarator, when they check against phpdoc comments as type safety validation notation.
E.g. POPO (plain old php objects) from http://jan.kneschke.de/projects/typesafe-objects-in-php validates
against the doc comment of the reflected object. But when the object is bytecoded by eAccelarator all comments
are removed from the source. Means: "type safe" properties loose their information and the object does not work any more.
This class set is an attempt to fix this lack.
Look at the sample (auto-generated db model struct class file) and see how it works.
All object properties have their own dynamic getters and setters. So, if you have a db column named caption, then you can set a value by simply writing (when the object is instantiated): $o->setCaption("my value").
Properties of a model class do only need a type prefix in front of the property name. Supported type prefixes for now:
- string (varchar, char, text, etc.)
- float (real,decimal,float)
- integer (int,smallint,bigint,etc.)
- bool (tinyint,bool)
- array (enum)
How do I insert a value?
Valid setValue sample:
$clsObject = new Model_Objects_Countries;
$clsObject->setContinent("Asia");
Invalid setValue sample:
$clsObject = new Model_Objects_Countries;
$clsObject->setContinent(true);
If you try to set an invalid value then an exception will thrown
How do I get a value?
$clsObject = new Model_Objects_Countries;
$clsObject->getContinent();
Once an object is filled, you can use the SerializeTypeStruct class
to convert your object into different output formats.
SerializeTypeStruct provides only two formats for giving you
an image of what can be done.
You can implement any kind of output format (CSV, PDF, XLS and so on), but you have to write it on your own.
Regards Tom
|