. //============================================================================ /** * @copyright Francois Laupretre * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 * @category phool * @package phool */ //============================================================================ namespace Phool; //============================================================================ /** * This abstract class allows to know whether an object has been modified or not * since it was created or read from persistent storage * * Each time a property is modified, the descendant class must call the * {@link setModified()} method. * * When it is saved, {@link clearModified()} must be called * * The current state can be retrieved via the {@link modified()} method. * * When the instance is created, the state is set to 'not-modified' */ abstract class Modifiable { /** @var boolean True if the object was modified since creation/load/save */ private $modified_flag=false; //---------------------------------------------------------------------------- /** * Class constructor * * Ensures that the instance is in 'non-modified' state at creation time * * @return void */ protected function __construct() { $this->clearModified(); } //---------------------------------------------------------------------------- /** * Set the 'modified' state depending on an input toggle * * The input toggle allows to pass a boolean return code as argument * * @param boolean $toggle If true, set the state, if false, do nothing * @return void */ protected function setModified($toggle=true) { if ($toggle) $this->modified_flag=true; } //---------------------------------------------------------------------------- /** * Set the 'not-modified' state * Should be called only when the instance is transferred to persistent storage * @return void */ protected function clearModified() { $this->modified_flag=false; } //---------------------------------------------------------------------------- /** * Returns the modified state * * @return boolean the current state */ public function modified() { return $this->modified_flag; } //---------------------------------------------------------------------------- } // End of class ?>