Mailinglisten-Archive |
Seong-Min Kang schrieb:
> Hi Ronny,
>
> Ronny Finster schrieb:
>> War nur eine Idee mittels StdClass eine Standardobjekt zu erzeugen und
>> dieses dann z.B. nach Kunde zu casten.
>
> witzig, dass du das hier ansprichst. Ich habe unser Framework soeben um
> ORM Funktionen erweitert ;)
>
> Hier ein paar Ideen, die dir vielleicht weiterhelfen:
>
> Dabei müssen bei mir alle properties, die Spalten darstellen, protected
> sein. Vielleicht gibt es bessere Unterscheidungsmöglichkeiten.
>
> abstract class OneMap
> {
> protected $self;
>
> private $_cols = array();
>
> public function __construct($data = false)
> {
> $R = new ReflectionObject($this);
> $this->self = new ReflectionClass($R->name);
>
> $this->_reflect();
Warum all dieses Reflection?
Nur um die Eigenschaften der Kind-Klasse nocheinmal in dem array _cols zu haben?
> if ($data instanceof stdClass) {
> $this->loadProperties($data);
> }
> }
>
> public function __call($name, $args)
> {
> // musst du noch implementieren
> $val = PFunctions::decamelize(substr($name, 3));
> if (!in_array($val, $this->_cols))
> return false;
> if (substr($name, 0, 3) == 'set') {
> $this->$val = $args[0];
> return true;
> } elseif (substr($name, 0, 3) == 'get') {
> return $this->$val;
> }
> return false;
> }
>
> ...
>
> protected function loadProperties(stdClass $data)
> {
> foreach ($this->_cols as $col) {
> if (!isset($data->$col))
> continue;
> $method = 'set'.ucfirst(PFunctions::camelize($col));
> if (!call_user_method_array($method, &$this,
> array($data->$col)))
Warnung
The call_user_method_array() function is deprecated as of PHP 4.1.0, use the
call_user_func_array() variety with the array(&$obj, "method_name") syntax
instead.
> throw new PException('Could not set property "'.$col.'"');
> }
> }
> }
>
> class Kunde extends OneMap
> {
> protected $id;
> protected $first_name;
>
> public function __construct($data = false)
> {
> parent::__construct($data);
> }
> }
Warum machst du das?
parent::__construct() wird doch automatisch aufgerufen wenn kein eigener
Konstruktor existiert.
--
Sebastian Mendel
www.sebastianmendel.de
php::bar PHP Wiki - Listenarchive