Implement file import

This commit is contained in:
Dennis Eichhorn 2018-12-01 22:27:10 +01:00
parent d4bc7a66bf
commit c126670789

View File

@ -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
*