|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de> 00006 * All rights reserved 00007 * 00008 * This class is a backport of the corresponding class of FLOW3. 00009 * All credits go to the v5 team. 00010 * 00011 * This script is part of the TYPO3 project. The TYPO3 project is 00012 * free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * The GNU General Public License can be found at 00018 * http://www.gnu.org/copyleft/gpl.html. 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 /** 00029 * An identity mapper to map nodes to objects 00030 * 00031 * @version $Id: IdentityMap.php 1814 2010-02-06 20:25:48Z jocrau $ 00032 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00033 * @see \F3\TYPO3CR\FLOW3\Persistence\DataMapper, \F3\TYPO3CR\FLOW3\Persistence\Backend 00034 */ 00035 class Tx_Extbase_Persistence_IdentityMap implements t3lib_Singleton { 00036 00037 /** 00038 * @var Tx_Extbase_Persistence_ObjectStorage 00039 */ 00040 protected $objectMap; 00041 00042 /** 00043 * @var array 00044 */ 00045 protected $uuidMap = array(); 00046 00047 /** 00048 * Constructs a new Identity Map 00049 * 00050 * @author Karsten Dambekalns <karsten@typo3.org> 00051 */ 00052 public function __construct() { 00053 $this->objectMap = new Tx_Extbase_Persistence_ObjectStorage(); 00054 } 00055 00056 /** 00057 * Checks whether the given object is known to the identity map 00058 * 00059 * @param object $object 00060 * @return boolean 00061 * @author Karsten Dambekalns <karsten@typo3.org> 00062 */ 00063 public function hasObject($object) { 00064 return $this->objectMap->contains($object); 00065 } 00066 00067 /** 00068 * Checks whether the given UUID is known to the identity map 00069 * 00070 * @param string $uuid 00071 * @param string $className 00072 * @return boolean 00073 */ 00074 public function hasIdentifier($uuid, $className) { 00075 if (is_array($this->uuidMap[$className])) { 00076 return array_key_exists($uuid, $this->uuidMap[$className]); 00077 } else { 00078 return FALSE; 00079 } 00080 } 00081 00082 /** 00083 * Returns the object for the given UUID 00084 * 00085 * @param string $uuid 00086 * @param string $className 00087 * @return object 00088 */ 00089 public function getObjectByIdentifier($uuid, $className) { 00090 return $this->uuidMap[$className][$uuid]; 00091 } 00092 00093 /** 00094 * Returns the node identifier for the given object 00095 * 00096 * @param object $object 00097 * @return string 00098 * @author Karsten Dambekalns <karsten@typo3.org> 00099 */ 00100 public function getIdentifierByObject($object) { 00101 if (!is_object($object)) throw new InvalidArgumentException('Object expected, ' . gettype($object) . ' given.', 1246892972); 00102 if (!isset($this->objectMap[$object])) { 00103 throw new Tx_Extbase_Persistence_Exception_UnknownObject('The given object (class: ' . get_class($object) . ') is not registered in this Identity Map.', 1246892970); 00104 } 00105 return $this->objectMap[$object]; 00106 } 00107 00108 /** 00109 * Register a node identifier for an object 00110 * 00111 * @param object $object 00112 * @param string $uuid 00113 * @author Karsten Dambekalns <karsten@typo3.org> 00114 */ 00115 public function registerObject($object, $uuid) { 00116 $this->objectMap[$object] = $uuid; 00117 $this->uuidMap[get_class($object)][$uuid] = $object; 00118 } 00119 00120 /** 00121 * Unregister an object 00122 * 00123 * @param string $object 00124 * @return void 00125 * @author Karsten Dambekalns <karsten@typo3.org> 00126 */ 00127 public function unregisterObject($object) { 00128 unset($this->uuidMap[get_class($object)][$this->objectMap[$object]]); 00129 $this->objectMap->detach($object); 00130 } 00131 00132 } 00133 ?>
1.8.0