Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
blob5784f2a0b09a36242b2fae6fe49cf6c4fe015967
1 <?php
2 /**
3 * Derivative context for resource loader modules.
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.
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.
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
20 * @file
21 * @author Kunal Mehta
24 /**
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by DerivativeContext.
28 * @since 1.24
30 class DerivativeResourceLoaderContext extends ResourceLoaderContext {
32 /**
33 * @var ResourceLoaderContext
35 private $context;
36 protected $modules;
37 protected $language;
38 protected $direction;
39 protected $skin;
40 protected $user;
41 protected $debug;
42 protected $only;
43 protected $version;
44 protected $hash;
45 protected $raw;
47 public function __construct( ResourceLoaderContext $context ) {
48 $this->context = $context;
51 public function getModules() {
52 if ( !is_null( $this->modules ) ) {
53 return $this->modules;
54 } else {
55 return $this->context->getModules();
59 /**
60 * @param string[] $modules
62 public function setModules( array $modules ) {
63 $this->modules = $modules;
66 public function getLanguage() {
67 if ( !is_null( $this->language ) ) {
68 return $this->language;
69 } else {
70 return $this->context->getLanguage();
74 /**
75 * @param string $language
77 public function setLanguage( $language ) {
78 $this->language = $language;
79 $this->direction = null; // Invalidate direction since it might be based on language
80 $this->hash = null;
83 public function getDirection() {
84 if ( !is_null( $this->direction ) ) {
85 return $this->direction;
86 } else {
87 return $this->context->getDirection();
91 /**
92 * @param string $direction
94 public function setDirection( $direction ) {
95 $this->direction = $direction;
96 $this->hash = null;
99 public function getSkin() {
100 if ( !is_null( $this->skin ) ) {
101 return $this->skin;
102 } else {
103 return $this->context->getSkin();
108 * @param string $skin
110 public function setSkin( $skin ) {
111 $this->skin = $skin;
112 $this->hash = null;
115 public function getUser() {
116 if ( !is_null( $this->user ) ) {
117 return $this->user;
118 } else {
119 return $this->context->getUser();
124 * @param string $user
126 public function setUser( $user ) {
127 $this->user = $user;
128 $this->hash = null;
129 $this->userObj = null;
132 public function getDebug() {
133 if ( !is_null( $this->debug ) ) {
134 return $this->debug;
135 } else {
136 return $this->context->getDebug();
141 * @param bool $debug
143 public function setDebug( $debug ) {
144 $this->debug = $debug;
145 $this->hash = null;
148 public function getOnly() {
149 if ( !is_null( $this->only ) ) {
150 return $this->only;
151 } else {
152 return $this->context->getOnly();
157 * @param string $only
159 public function setOnly( $only ) {
160 $this->only = $only;
161 $this->hash = null;
164 public function getVersion() {
165 if ( !is_null( $this->version ) ) {
166 return $this->version;
167 } else {
168 return $this->context->getVersion();
173 * @param string $version
175 public function setVersion( $version ) {
176 $this->version = $version;
177 $this->hash = null;
180 public function getRaw() {
181 if ( !is_null( $this->raw ) ) {
182 return $this->raw;
183 } else {
184 return $this->context->getRaw();
189 * @param bool $raw
191 public function setRaw( $raw ) {
192 $this->raw = $raw;
195 public function getRequest() {
196 return $this->context->getRequest();
199 public function getResourceLoader() {
200 return $this->context->getResourceLoader();