1<?php 2 3namespace PhpOffice\PhpSpreadsheet\Document; 4 5use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher; 6 7class Security 8{ 9 /** 10 * LockRevision. 11 * 12 * @var bool 13 */ 14 private $lockRevision = false; 15 16 /** 17 * LockStructure. 18 * 19 * @var bool 20 */ 21 private $lockStructure = false; 22 23 /** 24 * LockWindows. 25 * 26 * @var bool 27 */ 28 private $lockWindows = false; 29 30 /** 31 * RevisionsPassword. 32 * 33 * @var string 34 */ 35 private $revisionsPassword = ''; 36 37 /** 38 * WorkbookPassword. 39 * 40 * @var string 41 */ 42 private $workbookPassword = ''; 43 44 /** 45 * Create a new Document Security instance. 46 */ 47 public function __construct() 48 { 49 } 50 51 /** 52 * Is some sort of document security enabled? 53 * 54 * @return bool 55 */ 56 public function isSecurityEnabled() 57 { 58 return $this->lockRevision || 59 $this->lockStructure || 60 $this->lockWindows; 61 } 62 63 /** 64 * Get LockRevision. 65 * 66 * @return bool 67 */ 68 public function getLockRevision() 69 { 70 return $this->lockRevision; 71 } 72 73 /** 74 * Set LockRevision. 75 * 76 * @param bool $pValue 77 * 78 * @return Security 79 */ 80 public function setLockRevision($pValue) 81 { 82 $this->lockRevision = $pValue; 83 84 return $this; 85 } 86 87 /** 88 * Get LockStructure. 89 * 90 * @return bool 91 */ 92 public function getLockStructure() 93 { 94 return $this->lockStructure; 95 } 96 97 /** 98 * Set LockStructure. 99 * 100 * @param bool $pValue 101 * 102 * @return Security 103 */ 104 public function setLockStructure($pValue) 105 { 106 $this->lockStructure = $pValue; 107 108 return $this; 109 } 110 111 /** 112 * Get LockWindows. 113 * 114 * @return bool 115 */ 116 public function getLockWindows() 117 { 118 return $this->lockWindows; 119 } 120 121 /** 122 * Set LockWindows. 123 * 124 * @param bool $pValue 125 * 126 * @return Security 127 */ 128 public function setLockWindows($pValue) 129 { 130 $this->lockWindows = $pValue; 131 132 return $this; 133 } 134 135 /** 136 * Get RevisionsPassword (hashed). 137 * 138 * @return string 139 */ 140 public function getRevisionsPassword() 141 { 142 return $this->revisionsPassword; 143 } 144 145 /** 146 * Set RevisionsPassword. 147 * 148 * @param string $pValue 149 * @param bool $pAlreadyHashed If the password has already been hashed, set this to true 150 * 151 * @return Security 152 */ 153 public function setRevisionsPassword($pValue, $pAlreadyHashed = false) 154 { 155 if (!$pAlreadyHashed) { 156 $pValue = PasswordHasher::hashPassword($pValue); 157 } 158 $this->revisionsPassword = $pValue; 159 160 return $this; 161 } 162 163 /** 164 * Get WorkbookPassword (hashed). 165 * 166 * @return string 167 */ 168 public function getWorkbookPassword() 169 { 170 return $this->workbookPassword; 171 } 172 173 /** 174 * Set WorkbookPassword. 175 * 176 * @param string $pValue 177 * @param bool $pAlreadyHashed If the password has already been hashed, set this to true 178 * 179 * @return Security 180 */ 181 public function setWorkbookPassword($pValue, $pAlreadyHashed = false) 182 { 183 if (!$pAlreadyHashed) { 184 $pValue = PasswordHasher::hashPassword($pValue); 185 } 186 $this->workbookPassword = $pValue; 187 188 return $this; 189 } 190 191 /** 192 * Implement PHP __clone to create a deep clone, not just a shallow copy. 193 */ 194 public function __clone() 195 { 196 $vars = get_object_vars($this); 197 foreach ($vars as $key => $value) { 198 if (is_object($value)) { 199 $this->$key = clone $value; 200 } else { 201 $this->$key = $value; 202 } 203 } 204 } 205} 206