[TYPO3-ect] domainLayer for lib/div?
Joerg Schoppet
joerg at schoppet.de
Tue Aug 14 10:12:25 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I my last self developed framework I integrated a so called
"domainLayer". And I just want to ask, if it is interesting for lib/div?
A domain-object represents a real-life object like a user, article,
banana ...
Each domain-object provides methods to automatically retrieves and saves
itself to the database:
e.g.:
$user = tx_myext_domain_user::getByUid(10);
// creates an user-object of the user with the uid 10
$userArr = tx_myext_domain_user::getByField(array(array('username',
'LIKE', '%test$')));
// returns an array with user-objects, where the username contains 'test'
$userObj->save();
// automatically saves the record to the database
With the magic-method __call() it will also be possible to easily change
the return-values of individual members.
e.g.
$user->tstampGet();
// The method tstampGet() does not exists, so the magic-method __call()
is called. This method looks if the last three letters equals "Get" and
then looks if the member-var exists, if yes it simple returns the value.
$user->tstampGet('human');
// The method tstampGet() exists and look like the following:
public function tstampGet($mode='') {
switch ($mode) {
case 'human':
return date('d.m.Y', $this->tstampGet());
break;
default:
return $this->tstamp;
}
}
With the help of the decorator-pattern, it can be possible to easily
extend this mechanism in the future e.g. include additional fields
and/or methods to a domain-object (LDAP-field mapping for user-object),
or implement a custom logging function each time a record is saved.
An additional step can be to also include the activeRecord-pattern, so
that datatype-conversion can be done automatically by the save-method
(e.g. tstamp is an integer).
What do you think?
Regards
Joerg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGwWPpq5Me6rRDqPURAs8hAJ9chpEQacdt4yM0uMIbWL6WTpwpPQCeLMd0
r1cAghYZfNQuJ9wKUQ8vL5o=
=GMF2
-----END PGP SIGNATURE-----
More information about the TYPO3-team-extension-coordination
mailing list