2 /***************************************************************
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * An identity mapper to map nodes to objects
32 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
33 * @see \F3\TYPO3CR\FLOW3\Persistence\DataMapper, \F3\TYPO3CR\FLOW3\Persistence\Backend
35 class Tx_Extbase_Persistence_IdentityMap
{
38 * @var Tx_Extbase_Persistence_ObjectStorage
45 protected $uuidMap = array();
48 * Constructs a new Identity Map
50 * @author Karsten Dambekalns <karsten@typo3.org>
52 public function __construct() {
53 $this->objectMap
= new Tx_Extbase_Persistence_ObjectStorage();
57 * Checks whether the given object is known to the identity map
59 * @param object $object
61 * @author Karsten Dambekalns <karsten@typo3.org>
63 public function hasObject($object) {
64 return $this->objectMap
->contains($object);
68 * Checks whether the given UUID is known to the identity map
71 * @param string $className
74 public function hasIdentifier($uuid, $className) {
75 if (is_array($this->uuidMap
[$className])) {
76 return array_key_exists($uuid, $this->uuidMap
[$className]);
83 * Returns the object for the given UUID
86 * @param string $className
89 public function getObjectByIdentifier($uuid, $className) {
90 return $this->uuidMap
[$className][$uuid];
94 * Returns the node identifier for the given object
96 * @param object $object
98 * @author Karsten Dambekalns <karsten@typo3.org>
100 public function getIdentifierByObject($object) {
101 if (!is_object($object)) throw new InvalidArgumentException('Object expected, ' . gettype($object) . ' given.', 1246892972);
102 if (!isset($this->objectMap
[$object])) {
103 throw new Tx_Extbase_Persisitence_Exception_UnknownObjectException('The given object (class: ' . get_class($object) . ') is not registered in this Identity Map.', 1246892970);
105 return $this->objectMap
[$object];
109 * Register a node identifier for an object
111 * @param object $object
112 * @param string $uuid
113 * @author Karsten Dambekalns <karsten@typo3.org>
115 public function registerObject($object, $uuid) {
116 $this->objectMap
[$object] = $uuid;
117 $this->uuidMap
[get_class($object)][$uuid] = $object;
121 * Unregister an object
123 * @param string $object
125 * @author Karsten Dambekalns <karsten@typo3.org>
127 public function unregisterObject($object) {
128 unset($this->uuidMap
[get_class($object)][$this->objectMap
[$object]]);
129 $this->objectMap
->detach($object);