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
;
48 public function __construct( ResourceLoaderContext
$context ) {
49 $this->context
= $context;
52 public function getModules() {
53 if ( $this->modules
=== self
::INHERIT_VALUE
) {
54 return $this->context
->getModules();
56 return $this->modules
;
60 * @param string[] $modules
62 public function setModules( array $modules ) {
63 $this->modules
= $modules;
66 public function getLanguage() {
67 if ( $this->language
=== self
::INHERIT_VALUE
) {
68 return $this->context
->getLanguage();
70 return $this->language
;
74 * @param string $language
76 public function setLanguage( $language ) {
77 $this->language
= $language;
78 // Invalidate direction since it is based on language
79 $this->direction
= null;
83 public function getDirection() {
84 if ( $this->direction
=== self
::INHERIT_VALUE
) {
85 return $this->context
->getDirection();
87 if ( $this->direction
=== null ) {
88 $this->direction
= Language
::factory( $this->getLanguage() )->getDir();
90 return $this->direction
;
94 * @param string $direction
96 public function setDirection( $direction ) {
97 $this->direction
= $direction;
101 public function getSkin() {
102 if ( $this->skin
=== self
::INHERIT_VALUE
) {
103 return $this->context
->getSkin();
109 * @param string $skin
111 public function setSkin( $skin ) {
116 public function getUser() {
117 if ( $this->user
=== self
::INHERIT_VALUE
) {
118 return $this->context
->getUser();
124 * @param string $user
126 public function setUser( $user ) {
129 $this->userObj
= null;
132 public function getDebug() {
133 if ( $this->debug
=== self
::INHERIT_VALUE
) {
134 return $this->context
->getDebug();
142 public function setDebug( $debug ) {
143 $this->debug
= $debug;
147 public function getOnly() {
148 if ( $this->only
=== self
::INHERIT_VALUE
) {
149 return $this->context
->getOnly();
155 * @param string|null $only
157 public function setOnly( $only ) {
162 public function getVersion() {
163 if ( $this->version
=== self
::INHERIT_VALUE
) {
164 return $this->context
->getVersion();
166 return $this->version
;
170 * @param string|null $version
172 public function setVersion( $version ) {
173 $this->version
= $version;
177 public function getRaw() {
178 if ( $this->raw
=== self
::INHERIT_VALUE
) {
179 return $this->context
->getRaw();
187 public function setRaw( $raw ) {
191 public function getRequest() {
192 return $this->context
->getRequest();
195 public function getResourceLoader() {
196 return $this->context
->getResourceLoader();