本文整理汇总了PHP中ResourceLoader::formatException方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoader::formatException方法的具体用法?PHP ResourceLoader::formatException怎么用?PHP ResourceLoader::formatException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceLoader
的用法示例。
在下文中一共展示了ResourceLoader::formatException方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInlineScript
/**
* Get contents of a javascript file for inline use.
*
* Roughly based MediaWiki core methods:
* - ResourceLoader::filter()
* - ResourceLoaderFileModule::readScriptFiles()
*
* @param string $name Path to file relative to /modules/inline/
* @return string Minified script
* @throws Exception If file doesn't exist
*/
protected static function getInlineScript($name)
{
// Get file
$filePath = __DIR__ . '/../../modules/inline/' . $name;
if (!file_exists($filePath)) {
throw new Exception(__METHOD__ . ": file not found: \"{$filePath}\"");
}
$contents = file_get_contents($filePath);
// Try minified from cache
$key = wfMemcKey('centralauth', 'minify-js', md5($contents));
$cache = wfGetCache(CACHE_ANYTHING);
$cacheEntry = $cache->get($key);
if (is_string($cacheEntry)) {
return $cacheEntry;
}
// Compute new value
$result = '';
try {
$result = JavaScriptMinifier::minify($contents) . "\n/* cache key: {$key} */";
$cache->set($key, $result);
} catch (Exception $e) {
MWExceptionHandler::logException($e);
wfDebugLog('CentralAuth', __METHOD__ . ": minification failed for {$name}: {$e}");
$result = ResourceLoader::formatException($e) . "\n" . $contents;
}
return $result;
}
示例2: getCSS
/**
* Get the raw vector CSS, flipping if needed
*
* @todo Possibly get rid of this function and use ResourceLoader in the manner it was
* designed to be used in, rather than just grabbing a list of filenames from it,
* and not properly handling such details as media types in module definitions.
*
* @param string $dir 'ltr' or 'rtl'
* @return String
*/
public function getCSS($dir)
{
// All CSS files these modules reference will be concatenated in sequence
// and loaded as one file.
$moduleNames = array('mediawiki.legacy.shared', 'skins.common.interface', 'skins.vector.styles', 'mediawiki.legacy.config');
$prepend = '';
$css = '';
$resourceLoader = new ResourceLoader();
foreach ($moduleNames as $moduleName) {
/** @var ResourceLoaderFileModule $module */
$module = $resourceLoader->getModule($moduleName);
$cssFileNames = $module->getAllStyleFiles();
wfSuppressWarnings();
foreach ($cssFileNames as $cssFileName) {
if (!file_exists($cssFileName)) {
$prepend .= ResourceLoader::makeComment("Unable to find {$cssFileName}.");
continue;
}
if (!is_readable($cssFileName)) {
$prepend .= ResourceLoader::makeComment("Unable to read {$cssFileName}. " . "Please check file permissions.");
continue;
}
try {
if (preg_match('/\\.less$/', $cssFileName)) {
// Run the LESS compiler for *.less files (bug 55589)
$compiler = ResourceLoader::getLessCompiler();
$cssFileContents = $compiler->compileFile($cssFileName);
} else {
// Regular CSS file
$cssFileContents = file_get_contents($cssFileName);
}
if ($cssFileContents) {
// Rewrite URLs, though don't bother embedding images. While static image
// files may be cached, CSS returned by this function is definitely not.
$cssDirName = dirname($cssFileName);
$css .= CSSMin::remap($cssFileContents, $cssDirName, '..' . str_replace(array($GLOBALS['IP'], DIRECTORY_SEPARATOR), array('', '/'), $cssDirName), false);
} else {
$prepend .= ResourceLoader::makeComment("Unable to read {$cssFileName}.");
}
} catch (Exception $e) {
$prepend .= ResourceLoader::formatException($e);
}
$css .= "\n";
}
wfRestoreWarnings();
}
$css = $prepend . $css;
if ($dir == 'rtl') {
$css = CSSJanus::transform($css, true);
}
return $css;
}