|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OCA\Encryption\Panels; |
|
4
|
|
|
|
|
5
|
|
|
use OCP\Encryption\Keys\IStorage; |
|
6
|
|
|
use OCP\IConfig; |
|
7
|
|
|
use OCP\IL10N; |
|
8
|
|
|
use OCP\ILogger; |
|
9
|
|
|
use OCP\ISession; |
|
10
|
|
|
use OCP\IUserManager; |
|
11
|
|
|
use OCP\IUserSession; |
|
12
|
|
|
use OCP\Settings\ISettings; |
|
13
|
|
|
use OCP\Template; |
|
14
|
|
|
|
|
15
|
|
|
class Personal implements ISettings { |
|
16
|
|
|
|
|
17
|
|
|
/** @var ILogger */ |
|
18
|
|
|
protected $logger; |
|
19
|
|
|
/** @var IUserSession */ |
|
20
|
|
|
protected $userSession; |
|
21
|
|
|
/** @var IConfig */ |
|
22
|
|
|
protected $config; |
|
23
|
|
|
/** @var IL10N */ |
|
24
|
|
|
protected $l; |
|
25
|
|
|
/** @varIUserManager */ |
|
26
|
|
|
protected $userManager; |
|
27
|
|
|
/** @var ISession */ |
|
28
|
|
|
protected $session; |
|
29
|
|
|
/** @var IStorage */ |
|
30
|
|
|
protected $encKeyStorage; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct( |
|
33
|
|
|
ILogger $logger, |
|
34
|
|
|
IUserSession $userSession, |
|
35
|
|
|
IConfig $config, |
|
36
|
|
|
IL10N $l, |
|
37
|
|
|
IUserManager $userManager, |
|
38
|
|
|
ISession $session, |
|
39
|
|
|
IStorage $encKeyStorage) { |
|
40
|
|
|
$this->logger = $logger; |
|
41
|
|
|
$this->userSession = $userSession; |
|
42
|
|
|
$this->config = $config; |
|
43
|
|
|
$this->l = $l; |
|
44
|
|
|
$this->userManager = $userManager; |
|
45
|
|
|
$this->session = $session; |
|
46
|
|
|
$this->encKeyStorage = $encKeyStorage; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getPriority() { |
|
50
|
|
|
return 0; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getSectionID() { |
|
54
|
|
|
return 'encryption'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getPanel() { |
|
58
|
|
|
$session = new \OCA\Encryption\Session($this->session); |
|
59
|
|
|
$template = new Template('encryption', 'settings-personal'); |
|
60
|
|
|
$crypt = new \OCA\Encryption\Crypto\Crypt( |
|
61
|
|
|
$this->logger, |
|
62
|
|
|
$this->userSession, |
|
63
|
|
|
$this->config, |
|
64
|
|
|
$this->l); |
|
65
|
|
|
|
|
66
|
|
|
$util = new \OCA\Encryption\Util( |
|
67
|
|
|
new \OC\Files\View(), |
|
68
|
|
|
$crypt, |
|
69
|
|
|
$this->logger, |
|
70
|
|
|
$this->userSession, |
|
71
|
|
|
$this->config, |
|
72
|
|
|
$this->userManager); |
|
73
|
|
|
|
|
74
|
|
|
$user = $this->userSession->getUser()->getUID(); |
|
75
|
|
|
$privateKeySet = $session->isPrivateKeySet(); |
|
76
|
|
|
|
|
77
|
|
|
// did we tried to initialize the keys for this session? |
|
78
|
|
|
$initialized = $session->getStatus(); |
|
79
|
|
|
$recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled'); |
|
80
|
|
|
$recoveryEnabledForUser = $util->isRecoveryEnabledForUser($user); |
|
81
|
|
|
if ($recoveryAdminEnabled || !$privateKeySet) { |
|
82
|
|
|
$template->assign('recoveryEnabled', $recoveryAdminEnabled); |
|
83
|
|
|
$template->assign('recoveryEnabledForUser', $recoveryEnabledForUser); |
|
84
|
|
|
$template->assign('privateKeySet', $privateKeySet); |
|
85
|
|
|
$template->assign('initialized', $initialized); |
|
86
|
|
|
return $template; |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
return null; |
|
89
|
|
|
} |
|
90
|
|
|
} |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.