[TASK] Add more fixers for php-cs-fixer
[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 use TYPO3\CMS\Core\Registry;
18
19 /**
20 * Registry service
21 */
22 class RegistryService
23 {
24 /**
25 * @var \TYPO3\CMS\Core\Registry
26 */
27 protected $registry;
28
29 /**
30 * @var string
31 */
32 protected $namespaceIdentifier = 'TYPO3\\CMS\\Lang';
33
34 /**
35 * @param \TYPO3\CMS\Core\Registry $registry
36 */
37 public function injectRegistry(Registry $registry)
38 {
39 $this->registry = $registry;
40 }
41
42 /**
43 * Set namespace
44 *
45 * @param string $namespace The namespace
46 * @return void
47 */
48 public function setNamespace($namespace)
49 {
50 $this->namespaceIdentifier = $namespace;
51 }
52
53 /**
54 * Get namespace
55 *
56 * @return string The namespace
57 */
58 public function getNamespace()
59 {
60 return $this->namespaceIdentifier;
61 }
62
63 /**
64 * Check for existing registry entry
65 *
66 * @param string $name Registry entry name
67 * @param string $namespace Optional namespace
68 * @return bool TRUE if exists
69 */
70 public function has($name, $namespace = null)
71 {
72 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
73 $value = $this->registry->get($namespace, $name, '__NOTFOUND__');
74 return $value !== '__NOTFOUND__';
75 }
76
77 /**
78 * Get registry entry
79 *
80 * @param string $name Registry entry name
81 * @param string $namespace Optional namespace
82 * @return mixed Registry content
83 */
84 public function get($name, $namespace = null)
85 {
86 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
87 return $this->registry->get($namespace, $name);
88 }
89
90 /**
91 * Add / override registry entry
92 *
93 * @param string $name Registry entry name
94 * @param mixed $value The value
95 * @param string $namespace Optional namespace
96 * @return void
97 */
98 public function set($name, $value, $namespace = null)
99 {
100 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
101 $this->registry->set($namespace, $name, $value);
102 }
103
104 /**
105 * Remove registry entry
106 *
107 * @param string $name Registry entry name
108 * @param string $namespace Optional namespace
109 * @return void
110 */
111 public function remove($name, $namespace = null)
112 {
113 $namespace = (is_string($namespace) ? $namespace : $this->namespaceIdentifier);
114 $this->registry->remove($namespace, $name);
115 }
116 }