本文整理汇总了PHP中ResourceLoaderContext::getVariant方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoaderContext::getVariant方法的具体用法?PHP ResourceLoaderContext::getVariant怎么用?PHP ResourceLoaderContext::getVariant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceLoaderContext
的用法示例。
在下文中一共展示了ResourceLoaderContext::getVariant方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImageData
/**
* Get actual image data for this image. This can be saved to a file or sent to the browser to
* produce the converted image.
*
* Call getExtension() or getMimeType() with the same $format argument to learn what file type the
* returned data uses.
*
* @param ResourceLoaderContext $context Image context, or any context if $variant and $format
* given.
* @param string|null $variant Variant to get the data for. Optional; if given, overrides the data
* from $context.
* @param string $format Format to get the data for, 'original' or 'rasterized'. Optional; if
* given, overrides the data from $context.
* @return string|false Possibly binary image data, or false on failure
* @throws MWException If the image file doesn't exist
*/
public function getImageData(ResourceLoaderContext $context, $variant = false, $format = false)
{
if ($variant === false) {
$variant = $context->getVariant();
}
if ($format === false) {
$format = $context->getFormat();
}
$path = $this->getPath($context);
if (!file_exists($path)) {
throw new MWException("File '{$path}' does not exist");
}
if ($this->getExtension() !== 'svg') {
return file_get_contents($path);
}
if ($variant && isset($this->variants[$variant])) {
$data = $this->variantize($this->variants[$variant], $context);
} else {
$data = file_get_contents($path);
}
if ($format === 'rasterized') {
$data = $this->rasterize($data);
if (!$data) {
wfDebugLog('ResourceLoaderImage', __METHOD__ . " failed to rasterize for {$path}");
}
}
return $data;
}