CoreFiles by mySites.guru
DocumentAwareTrait.php61 lines, 1,249 bytes, from Joomla_5.2.3-Stable-Full_Package.zip
Raw History Compare with 5.2.2
md5
388e5d38b534aec7d84ac19695c76f5f
sha1
8a40cedbb0c21092d373626b62cebeb46ca49f37
sha256
10a80c9840a364072d437fe091c3b4bb5cd326b387038fc9413c0cd5a949b47f
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Document;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Defines the trait for a document aware class.
 *
 * @since  4.4.0
 */
trait DocumentAwareTrait
{
    /**
     * Document
     *
     * @var    Document
     * @since  4.4.0
     */
    private $document;

    /**
     * Get the Document.
     *
     * @return  Document
     *
     * @since   4.4.0
     * @throws  \UnexpectedValueException May be thrown if the document has not been set.
     */
    protected function getDocument(): Document
    {
        if ($this->document) {
            return $this->document;
        }

        throw new \UnexpectedValueException('Document not set in ' . __CLASS__);
    }

    /**
     * Set the document to use.
     *
     * @param   Document  $document  The document to use
     *
     * @return  void
     *
     * @since   4.4.0
     */
    public function setDocument(Document $document): void
    {
        $this->document = $document;
    }
}

The same content is in 190 releases, Joomla 4.4.0-alpha2 to 6.2.1-rc1. See them all, or every version of this file.