[ Index ] |
PHP Cross Reference of phool |
[Summary view] [Print] [Text view]
1 <?php 2 //============================================================================ 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Lesser General Public License (LGPL) as 5 // published by the Free Software Foundation, either version 3 of the License, 6 // or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Lesser General Public License for more details. 12 // 13 // You should have received a copy of the GNU Lesser General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 //============================================================================ 16 /** 17 * @copyright Francois Laupretre <phool@tekwire.net> 18 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 19 * @category phool 20 * @package phool 21 */ 22 //============================================================================ 23 24 namespace Phool; 25 26 //============================================================================ 27 /** 28 * This abstract class allows to know whether an object has been modified or not 29 * since it was created or read from persistent storage 30 * 31 * Each time a property is modified, the descendant class must call the 32 * {@link setModified()} method. 33 * 34 * When it is saved, {@link clearModified()} must be called 35 * 36 * The current state can be retrieved via the {@link modified()} method. 37 * 38 * When the instance is created, the state is set to 'not-modified' 39 */ 40 41 abstract class Modifiable 42 { 43 /** @var boolean True if the object was modified since creation/load/save */ 44 45 private $modified_flag=false; 46 47 //---------------------------------------------------------------------------- 48 /** 49 * Class constructor 50 * 51 * Ensures that the instance is in 'non-modified' state at creation time 52 * 53 * @return void 54 */ 55 56 protected function __construct() 57 { 58 $this->clearModified(); 59 } 60 61 //---------------------------------------------------------------------------- 62 /** 63 * Set the 'modified' state depending on an input toggle 64 * 65 * The input toggle allows to pass a boolean return code as argument 66 * 67 * @param boolean $toggle If true, set the state, if false, do nothing 68 * @return void 69 */ 70 71 protected function setModified($toggle=true) 72 { 73 if ($toggle) $this->modified_flag=true; 74 } 75 76 //---------------------------------------------------------------------------- 77 /** 78 * Set the 'not-modified' state 79 * Should be called only when the instance is transferred to persistent storage 80 * @return void 81 */ 82 83 protected function clearModified() 84 { 85 $this->modified_flag=false; 86 } 87 88 //---------------------------------------------------------------------------- 89 /** 90 * Returns the modified state 91 * 92 * @return boolean the current state 93 */ 94 95 public function modified() 96 { 97 return $this->modified_flag; 98 } 99 100 //---------------------------------------------------------------------------- 101 } // End of class 102 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jun 4 19:17:11 2015 | Cross-referenced by PHPXref 0.7.1 |