PopoDriver.php

Go to the documentation of this file.
00001 <?php
00002 
00032 class Robo47_Doctrine_Hydrator_PopoDriver extends Doctrine_Hydrator_ArrayDriver
00033 {
00034 
00042     protected static $_typename = '__type';
00043 
00051     protected static $_classname = 'Robo47_Popo';
00052 
00053 
00061     protected static $_containerClassname = 'array';
00062 
00067     public static function setDefaultClassname($classname)
00068     {
00069         if (!is_string($classname))  {
00070             $message = 'Invalid type for $classname: ' .
00071                 Robo47_Core::getType($classname);
00072             throw new Robo47_Doctrine_Hydrator_Exception($message);
00073         }
00074         $instance = new $classname;
00075         if (!$instance instanceof ArrayAccess) {
00076             throw new Robo47_Doctrine_Hydrator_Exception('Type does not implement ArrayAccess: ' . Robo47_Core::getType($instance));
00077         }
00078         self::$_classname = $classname;
00079     }
00080 
00085     public static function setDefaultContainerClassname($classname)
00086     {
00087         if (!is_string($classname))  {
00088             $message = 'Invalid type for $classname: ' .
00089                 Robo47_Core::getType($classname);
00090             throw new Robo47_Doctrine_Hydrator_Exception($message);
00091         }
00092         if (strtolower($classname) != 'array') {
00093             $instance = new $classname;
00094             if (!$instance instanceof ArrayAccess) {
00095                 throw new Robo47_Doctrine_Hydrator_Exception('Type does not implement ArrayAccess: ' . Robo47_Core::getType($instance));
00096             }
00097         }
00098         self::$_containerClassname = $classname;
00099     }
00100 
00105     public static function setDefaultTypename($typename)
00106     {
00107         if(null !== $typename && !is_string($typename)) {
00108             $message = 'Invalid type for $typename: ' .
00109                 Robo47_Core::getType($typename);
00110             throw new Robo47_Doctrine_Hydrator_Exception($message);
00111         }
00112         self::$_typename = $typename;
00113     }
00114 
00118     public static function getDefaultContainerClassname()
00119     {
00120         return self::$_containerClassname;
00121     }
00122 
00126     public static function getDefaultTypename()
00127     {
00128         return self::$_typename;
00129     }
00130 
00134     public static function getDefaultClassname()
00135     {
00136         return self::$_classname;
00137     }
00138 
00145     public function getElement(array $data, $component)
00146     {
00147         $classname = self::getDefaultClassname();
00148 
00149         $popo = new $classname;
00150 
00151         foreach ($data as $key => $value) {
00152             $popo[$key] = $value;
00153         }
00154 
00155         $typename = self::getDefaultTypename();
00156 
00157         if (null !== $typename) {
00158             $popo[$typename] = $component;
00159         }
00160 
00161         return $popo;
00162     }
00163 
00169     public function getElementCollection($component)
00170     {
00171         $containerClass = self::getDefaultContainerClassname();
00172         if ($containerClass == 'array') {
00173             $container = array();
00174         } else {
00175             $container = new $containerClass;
00176         }
00177         return $container;
00178     }
00179 }