[TASK] Replace @inject with inject methods in other extensions
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / Service / RegistryService.php
1 <?php
2 namespace TYPO3\CMS\Lang\Service;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Registry service
19 */
20 class RegistryService {
21
22 /**
23 * @var \TYPO3\CMS\Core\Registry
24 */
25 protected $registry;
26
27 /**
28 * @var string
29 */
30 protected $namespaceIdentifier = 'TYPO3\\CMS\\Lang';
31
32 /**
33 * @param \TYPO3\CMS\Core\Registry $registry
34 */
35 public function injectRegistry(\TYPO3\CMS\Core\Registry $registry) {
36 $this->registry = $registry;
37 }
38
39 /**
40 * Set namespace
41 *
42 * @param string $namespace The namespace
43 * @return void
44 */
45 public function setNamespace($namespace) {
46 $this->namespaceIdentifier = $namespace;
47 }
48
49 /**
50 * Get namespace
51 *
52 * @return string The namespace
53 */
54 public function getNamespace() {
55 return $this->namespaceIdentifier;
56 }
57
58 /**
59 * Check for existing registry entry
60 *
61 * @param string $name Registry entry name
62 * @param string $namespace Optional namespace
63 * @return bool TRUE if exists
64 */
65 public function has($name, $namespace = NULL) {
66 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
67 $value = $this->registry->get($namespace, $name, '__NOTFOUND__');
68 return ($value !== '__NOTFOUND__');
69 }
70
71 /**
72 * Get registry entry
73 *
74 * @param string $name Registry entry name
75 * @param string $namespace Optional namespace
76 * @return mixed Registry content
77 */
78 public function get($name, $namespace = NULL) {
79 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
80 return $this->registry->get($namespace, $name);
81 }
82
83 /**
84 * Add / override registry entry
85 *
86 * @param string $name Registry entry name
87 * @param mixed $value The value
88 * @param string $namespace Optional namespace
89 * @return void
90 */
91 public function set($name, $value, $namespace = NULL) {
92 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
93 $this->registry->set($namespace, $name, $value);
94 }
95
96 /**
97 * Remove registry entry
98 *
99 * @param string $name Registry entry name
100 * @param string $namespace Optional namespace
101 * @return void
102 */
103 public function remove($name, $namespace = NULL) {
104 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
105 $this->registry->remove($namespace, $name);
106 }
107
108 }