[TASK] Make TYPO3 Core PSR-2 standard compliant
[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 {
37 $this->registry = $registry;
38 }
39
40 /**
41 * Set namespace
42 *
43 * @param string $namespace The namespace
44 * @return void
45 */
46 public function setNamespace($namespace)
47 {
48 $this->namespaceIdentifier = $namespace;
49 }
50
51 /**
52 * Get namespace
53 *
54 * @return string The namespace
55 */
56 public function getNamespace()
57 {
58 return $this->namespaceIdentifier;
59 }
60
61 /**
62 * Check for existing registry entry
63 *
64 * @param string $name Registry entry name
65 * @param string $namespace Optional namespace
66 * @return bool TRUE if exists
67 */
68 public function has($name, $namespace = null)
69 {
70 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
71 $value = $this->registry->get($namespace, $name, '__NOTFOUND__');
72 return ($value !== '__NOTFOUND__');
73 }
74
75 /**
76 * Get registry entry
77 *
78 * @param string $name Registry entry name
79 * @param string $namespace Optional namespace
80 * @return mixed Registry content
81 */
82 public function get($name, $namespace = null)
83 {
84 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
85 return $this->registry->get($namespace, $name);
86 }
87
88 /**
89 * Add / override registry entry
90 *
91 * @param string $name Registry entry name
92 * @param mixed $value The value
93 * @param string $namespace Optional namespace
94 * @return void
95 */
96 public function set($name, $value, $namespace = null)
97 {
98 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
99 $this->registry->set($namespace, $name, $value);
100 }
101
102 /**
103 * Remove registry entry
104 *
105 * @param string $name Registry entry name
106 * @param string $namespace Optional namespace
107 * @return void
108 */
109 public function remove($name, $namespace = null)
110 {
111 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
112 $this->registry->remove($namespace, $name);
113 }
114 }