Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
    private bool $lockRevision = false;
13
 
14
    /**
15
     * LockStructure.
16
     */
17
    private bool $lockStructure = false;
18
 
19
    /**
20
     * LockWindows.
21
     */
22
    private bool $lockWindows = false;
23
 
24
    /**
25
     * RevisionsPassword.
26
     */
27
    private string $revisionsPassword = '';
28
 
29
    /**
30
     * WorkbookPassword.
31
     */
32
    private string $workbookPassword = '';
33
 
34
    /**
35
     * Create a new Document Security instance.
36
     */
37
    public function __construct()
38
    {
39
    }
40
 
41
    /**
42
     * Is some sort of document security enabled?
43
     */
44
    public function isSecurityEnabled(): bool
45
    {
46
        return $this->lockRevision
47
                || $this->lockStructure
48
                || $this->lockWindows;
49
    }
50
 
51
    public function getLockRevision(): bool
52
    {
53
        return $this->lockRevision;
54
    }
55
 
56
    public function setLockRevision(?bool $locked): self
57
    {
58
        if ($locked !== null) {
59
            $this->lockRevision = $locked;
60
        }
61
 
62
        return $this;
63
    }
64
 
65
    public function getLockStructure(): bool
66
    {
67
        return $this->lockStructure;
68
    }
69
 
70
    public function setLockStructure(?bool $locked): self
71
    {
72
        if ($locked !== null) {
73
            $this->lockStructure = $locked;
74
        }
75
 
76
        return $this;
77
    }
78
 
79
    public function getLockWindows(): bool
80
    {
81
        return $this->lockWindows;
82
    }
83
 
84
    public function setLockWindows(?bool $locked): self
85
    {
86
        if ($locked !== null) {
87
            $this->lockWindows = $locked;
88
        }
89
 
90
        return $this;
91
    }
92
 
93
    public function getRevisionsPassword(): string
94
    {
95
        return $this->revisionsPassword;
96
    }
97
 
98
    /**
99
     * Set RevisionsPassword.
100
     *
101
     * @param bool $alreadyHashed If the password has already been hashed, set this to true
102
     *
103
     * @return $this
104
     */
105
    public function setRevisionsPassword(?string $password, bool $alreadyHashed = false): static
106
    {
107
        if ($password !== null) {
108
            if (!$alreadyHashed) {
109
                $password = PasswordHasher::hashPassword($password);
110
            }
111
            $this->revisionsPassword = $password;
112
        }
113
 
114
        return $this;
115
    }
116
 
117
    public function getWorkbookPassword(): string
118
    {
119
        return $this->workbookPassword;
120
    }
121
 
122
    /**
123
     * Set WorkbookPassword.
124
     *
125
     * @param bool $alreadyHashed If the password has already been hashed, set this to true
126
     *
127
     * @return $this
128
     */
129
    public function setWorkbookPassword(?string $password, bool $alreadyHashed = false): static
130
    {
131
        if ($password !== null) {
132
            if (!$alreadyHashed) {
133
                $password = PasswordHasher::hashPassword($password);
134
            }
135
            $this->workbookPassword = $password;
136
        }
137
 
138
        return $this;
139
    }
140
}