/**
* Get a renderer instance for the given type
*
* @param string $type The type of renderer to fetch
*
* @return static
*
* @since 4.0.0
* @throws \InvalidArgumentException
*/
public static function getRenderer(string $type)
{
// Build the class name
$class = __NAMESPACE__ . '\\Renderer\\' . ucfirst(strtolower($type)) . 'Renderer';
// First check if an object may exist in the container and prefer that over everything else
if (Factory::getContainer()->has($class)) {
return Factory::getContainer()->get($class);
}
// Next check if a local class exists and use that
if (class_exists($class)) {
return new $class();
}
// 404 Resource Not Found
throw new \InvalidArgumentException(sprintf('There is not an error renderer for the "%s" format.', $type));
}