- md5
- 960b700326bb96e3a50a13c1e1f5682f
- sha1
- 111b3e0fd9700d18da69514f91c83439184e9108
- sha256
- 4dc3e78a5779c6715f34b3395943bfd521787d73f36dab684c3540458781c395
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Document;
defined('_JEXEC') or die;
/**
* Default factory for creating Document objects
*
* @since 4.0.0
*/
class Factory implements FactoryInterface
{
/**
* Creates a new Document object for the requested format.
*
* @param string $type The document type to instantiate
* @param array $attributes Array of attributes
*
* @return Document
*
* @since 4.0.0
*/
public function createDocument(string $type = 'html', array $attributes = []): Document
{
$type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
$ntype = null;
$class = __NAMESPACE__ . '\\' . ucfirst($type) . 'Document';
if (!class_exists($class))
{
$class = 'JDocument' . ucfirst($type);
}
if (!class_exists($class))
{
$ntype = $type;
$class = RawDocument::class;
}
// Inject this factory into the document unless one was provided
if (!isset($attributes['factory']))
{
$attributes['factory'] = $this;
}
/** @var Document $instance */
$instance = new $class($attributes);
if (!is_null($ntype))
{
// Set the type to the Document type originally requested
$instance->setType($ntype);
}
return $instance;
}
/**
* Creates a new renderer object.
*
* @param Document $document The Document instance to attach to the renderer
* @param string $type The renderer type to instantiate
*
* @return RendererInterface
*
* @since 4.0.0
*/
public function createRenderer(Document $document, string $type): RendererInterface
{
// Determine the path and class
$class = __NAMESPACE__ . '\\Renderer\\' . ucfirst($document->getType()) . '\\' . ucfirst($type) . 'Renderer';
if (!class_exists($class))
{
$class = 'JDocumentRenderer' . ucfirst($document->getType()) . 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);
}
}
No other release has this exact content. See every version of this file.