Dec 29 2007
One step at a time
Some time ago I wrote about some great plans for writing an or-mapping. Well, today, I actually made some progress!
Before I started to write on this code, I divided it in three parts:
- Creating Objects
- Updating Objects
- Deleting Objects
I finished a test version of the first part today. Basically, this is how it works: There is a class Object that should be extended by every class that has to be in a database. If you create a class extending this one, it will also be created in the database (if it doesn’t exist yet) as a table. For example, see this class:
/**
* foo
* bar
* @table_name=__TEST__
*
*/
class Test extends Object {
/** * @nullable = false */ private $firstname; private $lastname; /** * @type = string(12) * @nullable = false */ private $dateofbirth; private $city; function __construct() { parent::__construct(); } public function getFirstName(){ return $this->firstname; } public function setFirstname($firstname){ $this->firstname = $firstname; } public function getLastname(){ return $this->lastname; } public function setLastname($lastname){ $this->lastname = $lastname; } public function getDateofbirth(){ return $this->dateofbirth; } public function setDateofbirth($dob){ $this->dateofbirth = $dob; } public function getCity(){ return $this->city; } public function setCity($city){ $this->city = $city; } }
Pretty cool, huh? I still have to do some work, but the base is there. As you can see, you can also use some kind of annotations to set the information for the table and the columns in the database, but there are also default settings if they are omitted.
Enough for today, I’m going to celebrate my weekend and “Oud & nieuw”, as we call New Year’s Eve in Holland
Soon more about this!
