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
39 protected $modules = self
::INHERIT_VALUE
;
40 protected $language = self
::INHERIT_VALUE
;
41 protected $direction = self
::INHERIT_VALUE
;
42 protected $skin = self
::INHERIT_VALUE
;
43 protected $user = self
::INHERIT_VALUE
;
44 protected $debug = self
::INHERIT_VALUE
;
45 protected $only = self
::INHERIT_VALUE
;
46 protected $version = self
::INHERIT_VALUE
;
47 protected $raw = self
::INHERIT_VALUE
;
48 protected $contentOverrideCallback = self
::INHERIT_VALUE
;
50 public function __construct( ResourceLoaderContext
$context ) {
51 $this->context
= $context;
54 public function getModules() {
55 if ( $this->modules
=== self
::INHERIT_VALUE
) {
56 return $this->context
->getModules();
59 return $this->modules
;
63 * @param string[] $modules
65 public function setModules( array $modules ) {
66 $this->modules
= $modules;
69 public function getLanguage() {
70 if ( $this->language
=== self
::INHERIT_VALUE
) {
71 return $this->context
->getLanguage();
73 return $this->language
;
77 * @param string $language
79 public function setLanguage( $language ) {
80 $this->language
= $language;
81 // Invalidate direction since it is based on language
82 $this->direction
= null;
86 public function getDirection() {
87 if ( $this->direction
=== self
::INHERIT_VALUE
) {
88 return $this->context
->getDirection();
90 if ( $this->direction
=== null ) {
91 $this->direction
= Language
::factory( $this->getLanguage() )->getDir();
93 return $this->direction
;
97 * @param string $direction
99 public function setDirection( $direction ) {
100 $this->direction
= $direction;
104 public function getSkin() {
105 if ( $this->skin
=== self
::INHERIT_VALUE
) {
106 return $this->context
->getSkin();
112 * @param string $skin
114 public function setSkin( $skin ) {
119 public function getUser() {
120 if ( $this->user
=== self
::INHERIT_VALUE
) {
121 return $this->context
->getUser();
127 * @param string|null $user
129 public function setUser( $user ) {
132 $this->userObj
= null;
135 public function getDebug() {
136 if ( $this->debug
=== self
::INHERIT_VALUE
) {
137 return $this->context
->getDebug();
145 public function setDebug( $debug ) {
146 $this->debug
= $debug;
150 public function getOnly() {
151 if ( $this->only
=== self
::INHERIT_VALUE
) {
152 return $this->context
->getOnly();
158 * @param string|null $only
160 public function setOnly( $only ) {
165 public function getVersion() {
166 if ( $this->version
=== self
::INHERIT_VALUE
) {
167 return $this->context
->getVersion();
169 return $this->version
;
173 * @param string|null $version
175 public function setVersion( $version ) {
176 $this->version
= $version;
180 public function getRaw() {
181 if ( $this->raw
=== self
::INHERIT_VALUE
) {
182 return $this->context
->getRaw();
190 public function setRaw( $raw ) {
194 public function getRequest() {
195 return $this->context
->getRequest();
198 public function getResourceLoader() {
199 return $this->context
->getResourceLoader();
202 public function getContentOverrideCallback() {
203 if ( $this->contentOverrideCallback
=== self
::INHERIT_VALUE
) {
204 return $this->context
->getContentOverrideCallback();
206 return $this->contentOverrideCallback
;
210 * @see self::getContentOverrideCallback
212 * @param callable|null|int $callback As per self::getContentOverrideCallback,
213 * or self::INHERIT_VALUE
215 public function setContentOverrideCallback( $callback ) {
216 $this->contentOverrideCallback
= $callback;