Back to Factory class

Method createRenderer

public \Joomla\CMS\Document\RendererInterface
createRenderer
(\Joomla\CMS\Document\Document $document, string $type, string $docType = '')
Creates a new renderer object.
Parameters
  • \Joomla\CMS\Document\Document $document The Document instance to attach to the renderer
  • string $type The renderer type to instantiate
  • string $docType The document type the renderer is part of
Returns
  • \Joomla\CMS\Document\RendererInterface
Since
  • 4.0.0
Class: Factory
Project: Joomla

Method createRenderer - Source code

/**
 * Creates a new renderer object.
 *
 * @param   Document  $document  The Document instance to attach to the renderer
 * @param   string    $type      The renderer type to instantiate
 * @param   string    $docType   The document type the renderer is part of
 *
 * @return  RendererInterface
 *
 * @since   4.0.0
 */
public function createRenderer(Document $document, string $type, string $docType = '') : RendererInterface
{
    $docType = $docType ? ucfirst($docType) : ucfirst($document->getType());
    // Determine the path and class
    $class = __NAMESPACE__ . '\\Renderer\\' . $docType . '\\' . ucfirst($type) . 'Renderer';
    if (!class_exists($class)) {
        $class = 'JDocumentRenderer' . $docType . ucfirst($type);
    }
    if (!class_exists($class)) {
        // "Legacy" class name structure
        $class = '\\JDocumentRenderer' . $type;
        if (!class_exists($class)) {
            throw new \RuntimeException(sprintf('Unable to load renderer class %s', $type), 500);
        }
    }
    return new $class($document);
}