11311_v2.patch

Pascal Jungblut, 2010-12-07 03:27

Download (4.6 kB)

 
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php (working copy)
88 88
	protected $objectManager;
89 89

  
90 90
	/**
91
	 * @var Tx_Extbase_Object_Container_Container
92
	 */
93
	protected $objectContainer;
94

  
95
	/**
91 96
	 * Injects the identity map
92 97
	 *
93 98
	 * @param Tx_Extbase_Persistence_IdentityMap $identityMap
......
155 160
	}
156 161

  
157 162
	/**
163
	 * Inject the object container
164
	 *
165
	 * @param Tx_Extbase_Object_Container_Container $objectContainer
166
	 * @return void
167
	 */
168
	public function injectObjectContainer(Tx_Extbase_Object_Container_Container $objectContainer) {
169
		$this->objectContainer = $objectContainer;
170
	}
171

  
172
	/**
158 173
	 * Maps the given rows on objects
159 174
	 *
160 175
	 * @param string $className The name of the class
......
221 236
		// Note: The class_implements() function also invokes autoload to assure that the interfaces
222 237
		// and the class are loaded. Would end up with __PHP_Incomplete_Class without it.
223 238
		if (!in_array('Tx_Extbase_DomainObject_DomainObjectInterface', class_implements($className))) throw new Tx_Extbase_Object_Exception_CannotReconstituteObject('Cannot create empty instance of the class "' . $className . '" because it does not implement the Tx_Extbase_DomainObject_DomainObjectInterface.', 1234386924);
224
		$object = unserialize('O:' . strlen($className) . ':"' . $className . '":0:{};');
239
		$object = $this->objectContainer->getEmptyObject($className);
225 240
		return $object;
226 241
	}
227 242

  
typo3/sysext/extbase/Classes/Property/Mapper.php (working copy)
74 74
	protected $persistenceManager;
75 75

  
76 76
	/**
77
	 * @var Tx_Extbase_Object_ObjectManagerInterface
78
	 */
79
	protected $objectManager;
80

  
81
	/**
77 82
	 * @var Tx_Extbase_Persistence_QueryFactory
78 83
	 */
79 84
	protected $queryFactory;
......
114 119
	}
115 120

  
116 121
	/**
122
	 * Injects the Object Manager
123
	 *
124
	 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
125
	 * @return void
126
	 */
127
	public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
128
		$this->objectManager = $objectManager;
129
	}
130

  
131
	/**
117 132
	 * Maps the given properties to the target object and validates the properties according to the defined
118 133
	 * validators. If the result object is not valid, the operation will be undone (the target object remains
119 134
	 * unchanged) and this method returns FALSE.
......
267 282
				$propertyValue = NULL;
268 283
			} else {
269 284
				try {
270
					$propertyValue = new $targetType($propertyValue);
285
					$propertyValue = $this->objectManager->create($targetType, $propertyValue);
271 286
				} catch (Exception $e) {
272 287
					$propertyValue = NULL;
273 288
				}
......
294 309
						}
295 310
					}
296 311
				} else {
297
					$newObject = new $targetType;
312
					$newObject = $this->objectManager->create($targetType);
298 313
					if ($this->map(array_keys($propertyValue), $propertyValue, $newObject)) {
299 314
						$propertyValue = $newObject;
300 315
					} else {
typo3/sysext/extbase/Classes/Object/Container/Container.php (working copy)
118 118
	}
119 119

  
120 120
	/**
121
	 * get an empty object
122
	 *
123
	 * @param string $className
124
	 * @return object
125
	 */
126
	public function getEmptyObject($className) {
127
		$className = $this->getClassName($className);
128
		$classInfo = $this->getClassInfo($className);
129
		$object = unserialize('O:' . strlen($className) . ':"' . $className . '":0:{};');
130
		if ($classInfo->hasInjectMethods()) {
131
			$this->setterInjectionRegistry[]=array($object, $classInfo->getInjectMethods(), 0);
132
		}
133
		$this->processSetterInjectionRegistry();
134

  
135
		return $object;
136
	}
137

  
138
	/**
121 139
	 * register a classname that should be used if a dependency is required.
122 140
	 * e.g. used to define default class for a interface
123 141
	 *
......
246 264
	 */
247 265
	private function getClassInfo($className) {
248 266
			// we also need to make sure that the cache is returning a vaild object
249
			// in case something went wrong with unserialization etc.. 
267
			// in case something went wrong with unserialization etc..
250 268
		if (!$this->cache->has($className) || !is_object($this->cache->get($className))) {
251 269
			$this->cache->set($className, $this->classInfoFactory->buildClassInfoFromClassName($className));
252 270
		}