resourceloader: Use -1 instead of null in DerivativeResourceLoaderContext
[lhc/web/wiklou.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
1 <?php
2 /**
3 * Derivative context for resource loader modules.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author Kunal Mehta
22 */
23
24 /**
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by DerivativeContext.
27 *
28 * @since 1.24
29 */
30 class DerivativeResourceLoaderContext extends ResourceLoaderContext {
31 const INHERIT_VALUE = -1;
32
33 /**
34 * @var ResourceLoaderContext
35 */
36 private $context;
37
38 protected $modules = self::INHERIT_VALUE;
39 protected $language = self::INHERIT_VALUE;
40 protected $direction = self::INHERIT_VALUE;
41 protected $skin = self::INHERIT_VALUE;
42 protected $user = self::INHERIT_VALUE;
43 protected $debug = self::INHERIT_VALUE;
44 protected $only = self::INHERIT_VALUE;
45 protected $version = self::INHERIT_VALUE;
46 protected $raw = self::INHERIT_VALUE;
47
48 public function __construct( ResourceLoaderContext $context ) {
49 $this->context = $context;
50 }
51
52 public function getModules() {
53 if ( $this->modules === self::INHERIT_VALUE ) {
54 return $this->context->getModules();
55 }
56 return $this->modules;
57 }
58
59 /**
60 * @param string[] $modules
61 */
62 public function setModules( array $modules ) {
63 $this->modules = $modules;
64 }
65
66 public function getLanguage() {
67 if ( $this->language === self::INHERIT_VALUE ) {
68 return $this->context->getLanguage();
69 }
70 return $this->language;
71 }
72
73 /**
74 * @param string $language
75 */
76 public function setLanguage( $language ) {
77 $this->language = $language;
78 // Invalidate direction since it is based on language
79 $this->direction = self::INHERIT_VALUE;
80 $this->hash = null;
81 }
82
83 public function getDirection() {
84 if ( $this->direction === self::INHERIT_VALUE ) {
85 return $this->context->getDirection();
86 }
87 return $this->direction;
88 }
89
90 /**
91 * @param string $direction
92 */
93 public function setDirection( $direction ) {
94 $this->direction = $direction;
95 $this->hash = null;
96 }
97
98 public function getSkin() {
99 if ( $this->skin === self::INHERIT_VALUE ) {
100 return $this->context->getSkin();
101 }
102 return $this->skin;
103 }
104
105 /**
106 * @param string $skin
107 */
108 public function setSkin( $skin ) {
109 $this->skin = $skin;
110 $this->hash = null;
111 }
112
113 public function getUser() {
114 if ( $this->user === self::INHERIT_VALUE ) {
115 return $this->context->getUser();
116 }
117 return $this->user;
118 }
119
120 /**
121 * @param string $user
122 */
123 public function setUser( $user ) {
124 $this->user = $user;
125 $this->hash = null;
126 $this->userObj = null;
127 }
128
129 public function getDebug() {
130 if ( $this->debug === self::INHERIT_VALUE ) {
131 return $this->context->getDebug();
132 }
133 return $this->debug;
134 }
135
136 /**
137 * @param bool $debug
138 */
139 public function setDebug( $debug ) {
140 $this->debug = $debug;
141 $this->hash = null;
142 }
143
144 public function getOnly() {
145 if ( $this->only === self::INHERIT_VALUE ) {
146 return $this->context->getOnly();
147 }
148 return $this->only;
149 }
150
151 /**
152 * @param string|null $only
153 */
154 public function setOnly( $only ) {
155 $this->only = $only;
156 $this->hash = null;
157 }
158
159 public function getVersion() {
160 if ( $this->version === self::INHERIT_VALUE ) {
161 return $this->context->getVersion();
162 }
163 return $this->version;
164 }
165
166 /**
167 * @param string|null $version
168 */
169 public function setVersion( $version ) {
170 $this->version = $version;
171 $this->hash = null;
172 }
173
174 public function getRaw() {
175 if ( $this->raw === self::INHERIT_VALUE ) {
176 return $this->context->getRaw();
177 }
178 return $this->raw;
179 }
180
181 /**
182 * @param bool $raw
183 */
184 public function setRaw( $raw ) {
185 $this->raw = $raw;
186 }
187
188 public function getRequest() {
189 return $this->context->getRequest();
190 }
191
192 public function getResourceLoader() {
193 return $this->context->getResourceLoader();
194 }
195
196 }