# DaoSynchronizer.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2009 by Ivan Y. Khvostishkov                            *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00017     class DaoSynchronizer extends CustomizableDaoSynchronizer
    00018     {
    00022         public static function create()
    00023         {
    00024             return new self;
    00025         }
    00026
    00030         public function setMaster(GenericDAO $master)
    00031         {
    00032             Assert::isInstance($master, 'ProtoDAO');
    00033
    00034             return parent::setMaster($master);
    00035         }
    00036
    00040         public function setSlave(GenericDAO $slave)
    00041         {
    00042             Assert::isInstance($slave, 'ProtoDAO');
    00043
    00044             return parent::setSlave($slave);
    00045         }
    00046
    00047         protected function sync($old, $object)
    00048         {
    00049             $changed = array();
    00050
    00051             foreach (
    00052                 $this->slave->getProtoClass()->
    00053                     getPropertyList() as $property
    00054             ) {
    00055                 $getter = $property->getGetter();
    00056
    00057                 if ($property->getClassName() === null) {
    00058                     if ($old->$getter() != $object->$getter())
    00059                         $changed[$property->getName()] = $property;
    00060
    00061                 } else {
    00062                     if (
    00063                         (
    00064                             is_object($old->$getter())
    00065                             && !$old->$getter()->isEqualTo($object->$getter())
    00066                         )
    00067                         || (!$old->$getter() && $object->$getter())
    00068                     )
    00069                         $changed[$property->getName()] = $property;
    00070                 }
    00071             }
    00072
    00073             if ($changed) {
    00074                 return $this->changed($old, $object, $changed);
    00075             }
    00076
    00077             return false;
    00078         }
    00079
    00080         protected function changed($old, $object, $properties)
    00081         {
    00082             return parent::sync($old, $object);
    00083         }
    00084     }
    00085 ?>