Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Document;
   4  
   5  use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher;
   6  
   7  class 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      public function isSecurityEnabled(): bool
  55      {
  56          return  $this->lockRevision ||
  57                  $this->lockStructure ||
  58                  $this->lockWindows;
  59      }
  60  
  61      public function getLockRevision(): bool
  62      {
  63          return $this->lockRevision;
  64      }
  65  
  66      public function setLockRevision(?bool $locked): self
  67      {
  68          if ($locked !== null) {
  69              $this->lockRevision = $locked;
  70          }
  71  
  72          return $this;
  73      }
  74  
  75      public function getLockStructure(): bool
  76      {
  77          return $this->lockStructure;
  78      }
  79  
  80      public function setLockStructure(?bool $locked): self
  81      {
  82          if ($locked !== null) {
  83              $this->lockStructure = $locked;
  84          }
  85  
  86          return $this;
  87      }
  88  
  89      public function getLockWindows(): bool
  90      {
  91          return $this->lockWindows;
  92      }
  93  
  94      public function setLockWindows(?bool $locked): self
  95      {
  96          if ($locked !== null) {
  97              $this->lockWindows = $locked;
  98          }
  99  
 100          return $this;
 101      }
 102  
 103      public function getRevisionsPassword(): string
 104      {
 105          return $this->revisionsPassword;
 106      }
 107  
 108      /**
 109       * Set RevisionsPassword.
 110       *
 111       * @param string $password
 112       * @param bool $alreadyHashed If the password has already been hashed, set this to true
 113       *
 114       * @return $this
 115       */
 116      public function setRevisionsPassword(?string $password, bool $alreadyHashed = false)
 117      {
 118          if ($password !== null) {
 119              if (!$alreadyHashed) {
 120                  $password = PasswordHasher::hashPassword($password);
 121              }
 122              $this->revisionsPassword = $password;
 123          }
 124  
 125          return $this;
 126      }
 127  
 128      public function getWorkbookPassword(): string
 129      {
 130          return $this->workbookPassword;
 131      }
 132  
 133      /**
 134       * Set WorkbookPassword.
 135       *
 136       * @param string $password
 137       * @param bool $alreadyHashed If the password has already been hashed, set this to true
 138       *
 139       * @return $this
 140       */
 141      public function setWorkbookPassword(?string $password, bool $alreadyHashed = false)
 142      {
 143          if ($password !== null) {
 144              if (!$alreadyHashed) {
 145                  $password = PasswordHasher::hashPassword($password);
 146              }
 147              $this->workbookPassword = $password;
 148          }
 149  
 150          return $this;
 151      }
 152  }