- md5
- 9dcc3067cb9cdfcf7eaeb89bd0cb4166
- sha1
- 71e7780b26f44d290c5f7ef96fd08f7f27f1e2ff
- sha256
- da0a8072b27ae41ac6b66b90bda5e3c9301f4923cffe31e066b1ef01cdd5b925
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\MVC\Model;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Trait which supports state behavior
*
* @since 4.0.0
*/
trait StateBehaviorTrait
{
/**
* Indicates if the internal state has been set
*
* @var boolean
* @since 4.0.0
*/
protected $__state_set = null;
/**
* A state object
*
* @var State
* @since 4.0.0
*/
protected $state = null;
/**
* Method to get state variables.
*
* @param string $property Optional parameter name
* @param mixed $default Optional default value
*
* @return mixed The property where specified, the state object where omitted
*
* @since 4.0.0
*/
public function getState($property = null, $default = null)
{
if ($this->state === null) {
$this->state = new State();
}
if (!$this->__state_set) {
// Protected method to auto-populate the state
$this->populateState();
// Set the state set flag to true.
$this->__state_set = true;
}
return $property === null ? $this->state : $this->state->get($property, $default);
}
/**
* Method to set state variables.
*
* @param string $property The name of the property
* @param mixed $value The value of the property to set or null
*
* @return mixed The previous value of the property or null if not set
*
* @since 4.0.0
*/
public function setState($property, $value = null)
{
if ($this->state === null) {
$this->state = new State();
}
return $this->state->set($property, $value);
}
/**
* Method to auto-populate the state.
*
* This method should only be called once per instantiation and is designed
* to be called on the first call to the getState() method unless the
* configuration flag to ignore the request is set.
*
* @return void
*
* @note Calling getState in this method will result in recursion.
* @since 4.0.0
*/
protected function populateState()
{
}
}
The same content is in 67 releases, Joomla 5.0.0-alpha1 to 5.3.0. See them all, or every version of this file.