From a2bdc8074ff8e78242359c0ddb3807989de5b4e3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 10 Nov 2020 14:06:33 +0100 Subject: [PATCH] Introduce classes `Libraries` and `Library` --- library/Icinga/Application/Libraries.php | 39 +++++++++++++++++++ .../Icinga/Application/Libraries/Library.php | 32 +++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 library/Icinga/Application/Libraries.php create mode 100644 library/Icinga/Application/Libraries/Library.php diff --git a/library/Icinga/Application/Libraries.php b/library/Icinga/Application/Libraries.php new file mode 100644 index 000000000..afbe7fe3e --- /dev/null +++ b/library/Icinga/Application/Libraries.php @@ -0,0 +1,39 @@ +libraries); + } + + /** + * Register a library from the given path + * + * @param string $path + * + * @return Library The registered library + */ + public function registerPath($path) + { + $library = new Library($path); + $this->libraries[] = $library; + + return $library; + } +} diff --git a/library/Icinga/Application/Libraries/Library.php b/library/Icinga/Application/Libraries/Library.php new file mode 100644 index 000000000..9dde7f438 --- /dev/null +++ b/library/Icinga/Application/Libraries/Library.php @@ -0,0 +1,32 @@ +path = $path; + } + + /** + * Register this library's autoloader + * + * @return void + */ + public function registerAutoloader() + { + $autoloaderPath = join(DIRECTORY_SEPARATOR, [$this->path, 'vendor', 'autoload.php']); + if (file_exists($autoloaderPath)) { + require_once $autoloaderPath; + } + } +}