CoreFiles by mySites.guru
BaseModel.php97 lines, 1,960 bytes, from Joomla_4.0.0-alpha9-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha8
md5
cf7f093ac28234620d440a435aed1706
sha1
96fd1f2ee1591ba8c23cb06de854b83e4d672a83
sha256
ce8c4f4cf3bce30aaf10f902b9f2a101772d7c15717c2e17dac27000436c0122
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\MVC\Model;

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;

/**
 * Base class for a Joomla Model
 *
 * @since  4.0.0
 */
abstract class BaseModel extends CMSObject implements ModelInterface, StatefulModelInterface
{
	use StateBehaviorTrait;
	use LeagcyModelLoaderTrait;

	/**
	 * The model (base) name
	 *
	 * @var    string
	 * @since  4.0.0
	 */
	protected $name;

	/**
	 * Constructor
	 *
	 * @param   array  $config  An array of configuration options (name, state, ignore_request).
	 *
	 * @since   4.0.0
	 * @throws  \Exception
	 */
	public function __construct($config = array())
	{
		// Set the view name
		if (empty($this->name))
		{
			if (array_key_exists('name', $config))
			{
				$this->name = $config['name'];
			}
			else
			{
				$this->name = $this->getName();
			}
		}

		// Set the model state
		if (array_key_exists('state', $config))
		{
			$this->state = $config['state'];
		}

		// Set the internal state marker - used to ignore setting state from the request
		if (!empty($config['ignore_request']))
		{
			$this->__state_set = true;
		}
	}

	/**
	 * Method to get the model name
	 *
	 * The model name. By default parsed using the classname or it can be set
	 * by passing a $config['name'] in the class constructor
	 *
	 * @return  string  The name of the model
	 *
	 * @since   4.0.0
	 * @throws  \Exception
	 */
	public function getName()
	{
		if (empty($this->name))
		{
			$r = null;

			if (!preg_match('/Model(.*)/i', get_class($this), $r))
			{
				throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME'), 500);
			}

			$this->name = str_replace(['\\', 'model'], '', strtolower($r[1]));
		}

		return $this->name;
	}
}

The same content is in 3 releases, Joomla 4.0.0-alpha9 to 4.0.0-alpha11. See them all, or every version of this file.