- md5
- fa12a56a3bd5acbb169dd1b88c32b8ee
- sha1
- 2799043e1e5d494b4c6a08c4e29e74aacd80349d
- sha256
- 0f6931a7800fd686d4ec5835e2ba0046352099d7b4e7f61fff33938af3f3d7c3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
<?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\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(\JText::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME'), 500);
}
$this->name = str_replace(['\\', 'model'], '', strtolower($r[1]));
}
return $this->name;
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha8. See them all, or every version of this file.