wiki.techinc.nl/includes/resourceloader/ResourceLoaderFilePath.php
Roan Kattouw 2890bca27d resourceloader: Allow packageFiles callbacks to return a file
If a callback for a virtual file returns a ResourceLoaderFilePath
object, we will load that file from disk and use it in that file's
place. This enables us to port modules that use languageScripts or
skinScripts, by writing a virtual file callback that returns a
ResourceLoaderFilePath pointing to different files depending on the
language/skin.

This also makes the base path parameters to the ResourceLoaderFilePath
constructor optional. Callbacks would construct a ResourceLoaderFilePath
with only one parameter (the file path, but no base paths), and the
RL infrastructure ignores the object's base paths anyway, in favor of
the module's base paths.

Bug: T239371
Change-Id: I8e24f667b4e1944c20f3354a9f7382d5c486055e
2019-12-17 14:23:43 +01:00

90 lines
2.2 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
/**
* An object to represent a path to a JavaScript/CSS file, along with a remote
* and local base path, for use with ResourceLoaderFileModule.
*
* @ingroup ResourceLoader
* @since 1.17
*/
class ResourceLoaderFilePath {
/** @var string Local base path */
protected $localBasePath;
/** @var string Remote base path */
protected $remoteBasePath;
/**
* @var string Path to the file
*/
protected $path;
/**
* @param string $path Path to the file.
* @param string $localBasePath Base path to prepend when generating a local path.
* @param string $remoteBasePath Base path to prepend when generating a remote path.
*/
public function __construct( $path, $localBasePath = '', $remoteBasePath = '' ) {
$this->path = $path;
$this->localBasePath = $localBasePath;
$this->remoteBasePath = $remoteBasePath;
}
/**
* @return string
*/
public function getLocalPath() {
return $this->localBasePath === '' ?
$this->path :
"{$this->localBasePath}/{$this->path}";
}
/**
* @return string
*/
public function getRemotePath() {
return $this->remoteBasePath === '' ?
$this->path :
"{$this->remoteBasePath}/{$this->path}";
}
/**
* @return string
*/
public function getLocalBasePath() {
return $this->localBasePath;
}
/**
* @return string
*/
public function getRemoteBasePath() {
return $this->remoteBasePath;
}
/**
* @return string
*/
public function getPath() {
return $this->path;
}
}