3 * Derivative context for ResourceLoader 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
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by DerivativeContext.
30 class DerivativeResourceLoaderContext
extends ResourceLoaderContext
{
31 const INHERIT_VALUE
= -1;
34 * @var ResourceLoaderContext
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 protected $contentOverrideCallback = self
::INHERIT_VALUE
;
49 public function __construct( ResourceLoaderContext
$context ) {
50 $this->context
= $context;
53 public function getModules() {
54 if ( $this->modules
=== self
::INHERIT_VALUE
) {
55 return $this->context
->getModules();
57 // @phan-suppress-next-line PhanTypeMismatchReturn
58 return $this->modules
;
62 * @param string[] $modules
64 public function setModules( array $modules ) {
65 $this->modules
= $modules;
68 public function getLanguage() {
69 if ( $this->language
=== self
::INHERIT_VALUE
) {
70 return $this->context
->getLanguage();
72 return $this->language
;
76 * @param string $language
78 public function setLanguage( $language ) {
79 $this->language
= $language;
80 // Invalidate direction since it is based on language
81 $this->direction
= null;
85 public function getDirection() {
86 if ( $this->direction
=== self
::INHERIT_VALUE
) {
87 return $this->context
->getDirection();
89 if ( $this->direction
=== null ) {
90 $this->direction
= Language
::factory( $this->getLanguage() )->getDir();
92 return $this->direction
;
96 * @param string $direction
98 public function setDirection( $direction ) {
99 $this->direction
= $direction;
103 public function getSkin() {
104 if ( $this->skin
=== self
::INHERIT_VALUE
) {
105 return $this->context
->getSkin();
111 * @param string $skin
113 public function setSkin( $skin ) {
118 public function getUser() {
119 if ( $this->user
=== self
::INHERIT_VALUE
) {
120 return $this->context
->getUser();
126 * @param string|null $user
128 public function setUser( $user ) {
131 $this->userObj
= null;
134 public function getDebug() {
135 if ( $this->debug
=== self
::INHERIT_VALUE
) {
136 return $this->context
->getDebug();
144 public function setDebug( $debug ) {
145 $this->debug
= $debug;
149 public function getOnly() {
150 if ( $this->only
=== self
::INHERIT_VALUE
) {
151 return $this->context
->getOnly();
157 * @param string|null $only
159 public function setOnly( $only ) {
164 public function getVersion() {
165 if ( $this->version
=== self
::INHERIT_VALUE
) {
166 return $this->context
->getVersion();
168 return $this->version
;
172 * @param string|null $version
174 public function setVersion( $version ) {
175 $this->version
= $version;
179 public function getRaw() {
180 if ( $this->raw
=== self
::INHERIT_VALUE
) {
181 return $this->context
->getRaw();
189 public function setRaw( $raw ) {
193 public function getRequest() {
194 return $this->context
->getRequest();
197 public function getResourceLoader() {
198 return $this->context
->getResourceLoader();
201 public function getContentOverrideCallback() {
202 if ( $this->contentOverrideCallback
=== self
::INHERIT_VALUE
) {
203 return $this->context
->getContentOverrideCallback();
205 return $this->contentOverrideCallback
;
209 * @see self::getContentOverrideCallback
211 * @param callable|null|int $callback As per self::getContentOverrideCallback,
212 * or self::INHERIT_VALUE
214 public function setContentOverrideCallback( $callback ) {
215 $this->contentOverrideCallback
= $callback;