ObjectSetter.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 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 
00012     final class ObjectSetter extends PrototypedSetter
00013     {
00014         private $getter = null;
00015         
00016         public function set($name, $value)
00017         {
00018             $setter = 'set'.ucfirst($name);
00019             $dropper = 'drop'.ucfirst($name);
00020             
00021             if (
00022                 $value === null
00023                 && method_exists($this->object, $dropper)
00024             )
00025                 $method = $dropper;
00026             elseif (method_exists($this->object, $setter))
00027                 $method = $setter;
00028             else
00029                 throw new WrongArgumentException(
00030                     "cannot find mutator for '$name' in class "
00031                     .get_class($this->object)
00032                 );
00033             
00034             return $this->object->$method($value);
00035         }
00036         
00040         public function getGetter()
00041         {
00042             if (!$this->getter) {
00043                 $this->getter = new ObjectGetter($this->proto, $this->object);
00044             }
00045             
00046             return $this->getter;
00047         }
00048     }
00049 ?>