Lock.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
13 /**
14  * Lock represents a lock on an object.
15  *
16  * @author ingo herwig <ingo@wemove.com>
17  */
18 class Lock {
19 
20  const TYPE_OPTIMISTIC = 'optimistic';
21  const TYPE_PESSIMISTIC = 'pessimistic'; // pessimistic write lock
22 
23  private $_objectId = null;
24  private $_login = "";
25  private $_created = "";
26  private $_currentState = null;
27 
28  /**
29  * Creates a lock on a given object.
30  * @param $type One of the Lock::Type constants
31  * @param $oid ObjectId of the object to lock
32  * @param $login Login name of the user who holds the lock
33  * @param $created Creation date of the lock. If omitted the current date will be taken.
34  */
35  public function __construct($type, $oid, $login, $created='') {
36  $this->_type = $type;
37  $this->_objectId = $oid;
38  $this->_login = $login;
39  if ($created == '') {
40  $this->_created = date("Y-m-d H:i:s");
41  }
42  else {
43  $this->_created = $created;
44  }
45  }
46 
47  /**
48  * Get the type of the lock.
49  * @return One of the Lock::Type constants.
50  */
51  public function getType() {
52  return $this->_type;
53  }
54 
55  /**
56  * Get the oid of the locked object.
57  * @return ObjectId of the locked object.
58  */
59  public function getObjectId() {
60  return $this->_objectId;
61  }
62 
63  /**
64  * Get the login of the user who holds the lock.
65  * @return The login of the user.
66  */
67  public function getLogin() {
68  return $this->_login;
69  }
70 
71  /**
72  * Get the creation date/time of the lock.
73  * @return The creation date/time of the lock.
74  */
75  public function getCreated() {
76  return $this->_created;
77  }
78 
79  /**
80  * Set the original state of the object in case of an
81  * optimistic lock.
82  * @param $currentState PersistentObject instance or null
83  */
84  public function setCurrentState($currentState) {
85  $this->_currentState = serialize($currentState);
86  }
87 
88  /**
89  * Get the original state of the object in case of an
90  * optimistic lock.
91  * @return PersistentObject instance or null
92  */
93  public function getCurrentState() {
94  return unserialize($this->_currentState);
95  }
96 }
97 ?>
getObjectId()
Get the oid of the locked object.
Definition: Lock.php:59
setCurrentState($currentState)
Set the original state of the object in case of an optimistic lock.
Definition: Lock.php:84
Lock represents a lock on an object.
Definition: Lock.php:18
__construct($type, $oid, $login, $created='')
Creates a lock on a given object.
Definition: Lock.php:35
getCurrentState()
Get the original state of the object in case of an optimistic lock.
Definition: Lock.php:93
getCreated()
Get the creation date/time of the lock.
Definition: Lock.php:75
getLogin()
Get the login of the user who holds the lock.
Definition: Lock.php:67
getType()
Get the type of the lock.
Definition: Lock.php:51