From c12667078968e6156f322020b9647629778faa20 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 1 Dec 2018 22:27:10 +0100 Subject: [PATCH] Implement file import --- Event/EventManager.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Event/EventManager.php b/Event/EventManager.php index 5ed6a53c4..e76b350b6 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -69,6 +69,35 @@ final class EventManager }; } + /** + * Add events from file. + * + * @param string $path Hook file path + * + * @return bool + * + * @since 1.0.0 + */ + public function importFromFile(string $path) : bool + { + if (!\file_exists($path)) { + return false; + } + + /** @noinspection PhpIncludeInspection */ + $hooks = include $path; + + foreach ($hooks as $group => $hook) { + foreach ($hook['callback'] as $callbacks) { + foreach ($callbacks as $callback) { + $this->attach($group, $callback, $hook['remove'] ?? false, $hook['reset'] ?? true); + } + } + } + + return true; + } + /** * Attach new event *