2015-02-24 13:05:19 -05:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2015-02-24 13:05:19 -05:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Encryption;
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\Hooks\Contracts\IHook;
|
|
|
|
|
|
|
|
|
|
class HookManager {
|
2020-08-14 09:10:48 -04:00
|
|
|
/** @var IHook[] */
|
2015-02-24 13:05:19 -05:00
|
|
|
private $hookInstances = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array|IHook $instances
|
|
|
|
|
* - This accepts either a single instance of IHook or an array of instances of IHook
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function registerHook($instances) {
|
|
|
|
|
if (is_array($instances)) {
|
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
|
if (!$instance instanceof IHook) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->hookInstances[] = $instance;
|
|
|
|
|
}
|
2015-04-01 04:19:07 -04:00
|
|
|
} elseif ($instances instanceof IHook) {
|
|
|
|
|
$this->hookInstances[] = $instances;
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function fireHooks() {
|
|
|
|
|
foreach ($this->hookInstances as $instance) {
|
|
|
|
|
/**
|
2015-03-24 17:29:10 -04:00
|
|
|
* Fire off the add hooks method of each instance stored in cache
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
|
|
|
|
$instance->addHooks();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|