/**
* Method to get an image filter instance of a specified type.
*
* @param string $type The image filter type to get.
*
* @return ImageFilter
*
* @since 2.5.0
* @throws \RuntimeException
*/
protected function getFilterInstance($type)
{
// Sanitize the filter type.
$type = strtolower(preg_replace('#[^A-Z0-9_]#i', '', $type));
// Verify that the filter type exists.
$className = 'JImageFilter' . ucfirst($type);
if (!class_exists($className)) {
$className = __NAMESPACE__ . '\\Filter\\' . ucfirst($type);
if (!class_exists($className)) {
throw new \RuntimeException('The ' . ucfirst($type) . ' image filter is not available.');
}
}
// Instantiate the filter object.
$instance = new $className($this->getHandle());
// Verify that the filter type is valid.
if (!$instance instanceof ImageFilter) {
throw new \RuntimeException('The ' . ucfirst($type) . ' image filter is not valid.');
}
return $instance;
}