Raised DBAL version from 1.1.5 to 1.1.6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Object / TransientRegistry.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
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.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * A transient Object Object Cache which provides a transient memory-based
30 * registry of objects.
31 *
32 * @package Extbase
33 * @subpackage Object
34 * @version $Id: TransientRegistry.php 1729 2009-11-25 21:37:20Z stucki $
35 */
36 class Tx_Extbase_Object_TransientRegistry implements Tx_Extbase_Object_RegistryInterface {
37
38 /**
39 * @var array Location where objects are stored
40 */
41 protected $objects = array();
42
43 /**
44 * Returns an object from the registry. If an instance of the required
45 * object does not exist yet, an exception is thrown.
46 *
47 * @param string $objectName Name of the object to return an object of
48 * @return object The object
49 */
50 public function getObject($objectName) {
51 if (!$this->objectExists($objectName)) throw new RuntimeException('Object "' . $objectName . '" does not exist in the object registry.', 1167917198);
52 return $this->objects[$objectName];
53 }
54
55 /**
56 * Put an object into the registry.
57 *
58 * @param string $objectName Name of the object the object is made for
59 * @param object $object The object to store in the registry
60 * @return void
61 */
62 public function putObject($objectName, $object) {
63 if (!is_string($objectName) || strlen($objectName) === 0) throw new RuntimeException('No valid object name specified.', 1167919564);
64 if (!is_object($object)) throw new RuntimeException('$object must be of type Object', 1167917199);
65 $this->objects[$objectName] = $object;
66 }
67
68 /**
69 * Remove an object from the registry.
70 *
71 * @param string objectName Name of the object to remove the object for
72 * @return void
73 */
74 public function removeObject($objectName) {
75 if (!$this->objectExists($objectName)) throw new RuntimeException('Object "' . $objectName . '" does not exist in the object registry.', 1167917200);
76 unset ($this->objects[$objectName]);
77 }
78
79 /**
80 * Checks if an object of the given object already exists in the object registry.
81 *
82 * @param string $objectName Name of the object to check for an object
83 * @return boolean TRUE if an object exists, otherwise FALSE
84 */
85 public function objectExists($objectName) {
86 return isset($this->objects[$objectName]);
87 }
88
89 }
90
91 ?>