Changeset 13745
- Timestamp:
- 12/04/08 22:40:13 (5 years ago)
- Files:
-
- plugins/sfViewableModelPlugin/trunk/lib/addon/sfViewableModelPropelBehavior.class.php (modified) (1 diff)
- plugins/sfViewableModelPlugin/trunk/lib/util/sfViewableModelToolkit.class.php (modified) (2 diffs)
- plugins/sfViewableModelPlugin/trunk/lib/view/sfViewableModelViewCacheManager.class.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfViewableModelPlugin/trunk/lib/addon/sfViewableModelPropelBehavior.class.php
r13744 r13745 11 11 class sfViewableModelPropelBehavior 12 12 { 13 /** 14 * Extends a model with this behavior. 15 * 16 * @param string $model 17 */ 18 static function extendModel($model) 19 { 20 if (!is_subclass_of($model, 'BaseObject')) 21 { 22 throw new InvalidArgumentException(sprintf('The class "%s" is not a subclass of BaseObject.', $model)); 23 } 24 25 try 26 { 27 sfPropelBehavior::add($model, array('viewable')); 28 } 29 catch (Exception $e) 30 { 31 // behavior has already been added 32 } 33 } 34 13 35 /** 14 36 * Removes the supplied object from the cache. plugins/sfViewableModelPlugin/trunk/lib/util/sfViewableModelToolkit.class.php
r13744 r13745 83 83 { 84 84 case 'propel': 85 return $value instanceof BaseObject; 85 $ret = $value instanceof BaseObject; 86 break; 86 87 case 'doctrine': 87 return $value instanceof Doctrine_Record; 88 $ret = $value instanceof Doctrine_Record; 89 break; 88 90 default: 89 91 throw new LogicException('ORM is neither Propel nor Doctrine. Please connect to "sf_viewable_model_plugin.is_model_object" and add logic for your ORM.'); … … 91 93 } 92 94 93 return false; 95 if ($ret) 96 { 97 self::extendModel($value); 98 } 99 100 return $ret; 101 } 102 103 /** 104 * Extends the supplied model with an ORM behavior. 105 * 106 * @param string|object $model 107 */ 108 static public function extendModel($model) 109 { 110 if (is_object($model)) 111 { 112 $model = get_class($model); 113 } 114 115 $event = sfProjectConfiguration::getActive()->getEventDispatcher()->notifyUntil(new sfEvent($model, 'sf_viewable_model_plugin.extend_model')); 116 if ($event->isProcessed()) 117 { 118 return; 119 } 120 121 switch (sfConfig::get('sf_orm')) 122 { 123 case 'propel': 124 sfViewableModelPropelBehavior::extendModel($model); 125 break; 126 case 'doctrine': 127 throw new Exception('Doctrine version not implemented.'); 128 break; 129 default: 130 throw new LogicException('ORM is neither Propel nor Doctrine. Please connect to "sf_viewable_model_plugin.extend_model" and add logic for your ORM.'); 131 } 94 132 } 95 133 } plugins/sfViewableModelPlugin/trunk/lib/view/sfViewableModelViewCacheManager.class.php
r13744 r13745 30 30 { 31 31 $this->viewableModelCache = include $this->viewableModelCacheFile; 32 } 33 34 // extend cached model classes 35 foreach (array_keys($this->viewableModelCache) as $key) 36 { 37 $parts = explode('//', $key); 38 sfViewableModelToolkit::extendModel($parts[0]); 32 39 } 33 40 … … 139 146 } 140 147 141 $key = get_class($model).' _'.$pk;148 $key = get_class($model).'//'.$pk; 142 149 143 150 return $key;