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 return $this->modules
;
61 * @param string[] $modules
63 public function setModules( array $modules ) {
64 $this->modules
= $modules;
67 public function getLanguage() {
68 if ( $this->language
=== self
::INHERIT_VALUE
) {
69 return $this->context
->getLanguage();
71 return $this->language
;
75 * @param string $language
77 public function setLanguage( $language ) {
78 $this->language
= $language;
79 // Invalidate direction since it is based on language
80 $this->direction
= null;
84 public function getDirection() {
85 if ( $this->direction
=== self
::INHERIT_VALUE
) {
86 return $this->context
->getDirection();
88 if ( $this->direction
=== null ) {
89 $this->direction
= Language
::factory( $this->getLanguage() )->getDir();
91 return $this->direction
;
95 * @param string $direction
97 public function setDirection( $direction ) {
98 $this->direction
= $direction;
102 public function getSkin() {
103 if ( $this->skin
=== self
::INHERIT_VALUE
) {
104 return $this->context
->getSkin();
110 * @param string $skin
112 public function setSkin( $skin ) {
117 public function getUser() {
118 if ( $this->user
=== self
::INHERIT_VALUE
) {
119 return $this->context
->getUser();
125 * @param string|null $user
127 public function setUser( $user ) {
130 $this->userObj
= null;
133 public function getDebug() {
134 if ( $this->debug
=== self
::INHERIT_VALUE
) {
135 return $this->context
->getDebug();
143 public function setDebug( $debug ) {
144 $this->debug
= $debug;
148 public function getOnly() {
149 if ( $this->only
=== self
::INHERIT_VALUE
) {
150 return $this->context
->getOnly();
156 * @param string|null $only
158 public function setOnly( $only ) {
163 public function getVersion() {
164 if ( $this->version
=== self
::INHERIT_VALUE
) {
165 return $this->context
->getVersion();
167 return $this->version
;
171 * @param string|null $version
173 public function setVersion( $version ) {
174 $this->version
= $version;
178 public function getRaw() {
179 if ( $this->raw
=== self
::INHERIT_VALUE
) {
180 return $this->context
->getRaw();
188 public function setRaw( $raw ) {
192 public function getRequest() {
193 return $this->context
->getRequest();
196 public function getResourceLoader() {
197 return $this->context
->getResourceLoader();
200 public function getContentOverrideCallback() {
201 if ( $this->contentOverrideCallback
=== self
::INHERIT_VALUE
) {
202 return $this->context
->getContentOverrideCallback();
204 return $this->contentOverrideCallback
;
208 * @see self::getContentOverrideCallback
210 * @param callable|null|int $callback As per self::getContentOverrideCallback,
211 * or self::INHERIT_VALUE
213 public function setContentOverrideCallback( $callback ) {
214 $this->contentOverrideCallback
= $callback;