-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vitor Mattos <[email protected]>
- Loading branch information
1 parent
1968659
commit 31fc994
Showing
7 changed files
with
73 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ abstract class AbstractIdentifyMethod implements IIdentifyMethod { | |
protected string $codeSentByUser = ''; | ||
protected array $settings = []; | ||
protected bool $willNotify = true; | ||
/** | ||
* @var string[] | ||
*/ | ||
public array $availableSignatureMethods; | ||
/** | ||
* @var AbstractSignatureMethod[] | ||
*/ | ||
|
@@ -89,11 +93,28 @@ public function signatureMethodsToArray(): array { | |
return array_map(function (AbstractSignatureMethod $method) { | ||
return [ | ||
'label' => $method->friendlyName, | ||
'name' => $method->getName(), | ||
'enabled' => $method->isEnabled(), | ||
]; | ||
}, $this->signatureMethods); | ||
} | ||
|
||
public function getEmptyInstanceOfSignatureMethodByName(string $name): AbstractSignatureMethod { | ||
if (!in_array($name, $this->availableSignatureMethods)) { | ||
throw new InvalidArgumentException(sprintf('%s is not a valid signature method of identify method %s', $name, $this->getName())); | ||
} | ||
$className = 'OCA\Libresign\Service\IdentifyMethod\\SignatureMethod\\' . ucfirst($name); | ||
if (!class_exists($className)) { | ||
throw new InvalidArgumentException('Invalid signature method. Set at identify method the list of available signature methdos with right values.'); | ||
} | ||
$signatureMethod = clone \OC::$server->get($className); | ||
$signatureMethod->cleanEntity(); | ||
return $signatureMethod; | ||
} | ||
|
||
/** | ||
* @return AbstractSignatureMethod[] | ||
*/ | ||
public function getSignatureMethods(): array { | ||
return $this->signatureMethods; | ||
} | ||
|
@@ -298,10 +319,15 @@ private function loadSavedSettings(): void { | |
return; | ||
} | ||
foreach ($this->settings['signatureMethods'] as $method => $settings) { | ||
$this->signatureMethods[$method]->setEntity($this->getEntity()); | ||
if (is_object($this->signatureMethods[$method]) && isset($settings['enabled']) && $settings['enabled']) { | ||
$this->signatureMethods[$method]->enable(); | ||
if (!in_array($method, $this->availableSignatureMethods)) { | ||
unset($this->settings['signatureMethods'][$method]); | ||
continue; | ||
} | ||
$signatureMethod = $this->getEmptyInstanceOfSignatureMethodByName($method); | ||
if (isset($settings['enabled']) && $settings['enabled']) { | ||
$signatureMethod->enable(); | ||
} | ||
$this->signatureMethods[$method] = $signatureMethod; | ||
} | ||
} | ||
|
||
|
@@ -334,6 +360,27 @@ private function removeKeysThatDontExists(array $default): void { | |
} | ||
} | ||
|
||
/** | ||
* @author Gajus Kuizinas <[email protected]> | ||
* @version 1.0.0 (2013 03 19) | ||
* | ||
* https://www.php.net/manual/en/function.array-diff-key.php#112558 | ||
*/ | ||
public function arrayDiffKeyRecursive(array $arr1, array $arr2) { | ||
$diff = array_diff_key($arr1, $arr2); | ||
$intersect = array_intersect_key($arr1, $arr2); | ||
foreach ($intersect as $k => $v) { | ||
if (is_array($arr1[$k]) && is_array($arr2[$k])) { | ||
$d = $this->arrayDiffKeyRecursive($arr1[$k], $arr2[$k]); | ||
if ($d) { | ||
$diff[$k] = $d; | ||
} | ||
} | ||
} | ||
|
||
return $diff; | ||
} | ||
|
||
public function validateToRenew(?IUser $user = null): void { | ||
$this->throwIfMaximumValidityExpired(); | ||
$this->throwIfAlreadySigned(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters