bootstrap: Load external libraries
This commit is contained in:
parent
a2bdc8074f
commit
a60f511cfc
|
@ -3,6 +3,7 @@
|
|||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use DirectoryIterator;
|
||||
use ErrorException;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
|
@ -62,7 +63,7 @@ abstract class ApplicationBootstrap
|
|||
protected $vendorDir;
|
||||
|
||||
/**
|
||||
* Library directory
|
||||
* Icinga library directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
@ -89,6 +90,20 @@ abstract class ApplicationBootstrap
|
|||
*/
|
||||
protected $storageDir;
|
||||
|
||||
/**
|
||||
* External library paths
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $libraryPaths;
|
||||
|
||||
/**
|
||||
* Loaded external libraries
|
||||
*
|
||||
* @var Libraries
|
||||
*/
|
||||
protected $libraries;
|
||||
|
||||
/**
|
||||
* Icinga class loader
|
||||
*
|
||||
|
@ -176,6 +191,20 @@ abstract class ApplicationBootstrap
|
|||
$canonical = realpath($storageDir);
|
||||
$this->storageDir = $canonical ? $canonical : $storageDir;
|
||||
|
||||
if ($this->libraryPaths === null) {
|
||||
$libraryPaths = getenv('ICINGAWEB_LIBDIR');
|
||||
if ($libraryPaths !== false) {
|
||||
$this->libraryPaths = array_filter(array_map(
|
||||
'realpath',
|
||||
explode(':', $libraryPaths)
|
||||
), 'is_dir');
|
||||
} else {
|
||||
$this->libraryPaths = is_dir('/usr/share/php-icinga')
|
||||
? ['/usr/share/php-icinga']
|
||||
: [];
|
||||
}
|
||||
}
|
||||
|
||||
set_include_path(
|
||||
implode(
|
||||
PATH_SEPARATOR,
|
||||
|
@ -197,6 +226,16 @@ abstract class ApplicationBootstrap
|
|||
*/
|
||||
abstract protected function bootstrap();
|
||||
|
||||
/**
|
||||
* Get loaded external libraries
|
||||
*
|
||||
* @return Libraries
|
||||
*/
|
||||
public function getLibraries()
|
||||
{
|
||||
return $this->libraries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for module manager
|
||||
*
|
||||
|
@ -499,6 +538,26 @@ abstract class ApplicationBootstrap
|
|||
return @file_exists($this->config->resolvePath('setup.token'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load external libraries
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function loadLibraries()
|
||||
{
|
||||
$this->libraries = new Libraries();
|
||||
foreach ($this->libraryPaths as $libraryPath) {
|
||||
foreach (new DirectoryIterator($libraryPath) as $path) {
|
||||
if (! $path->isDot() && is_dir($path->getRealPath())) {
|
||||
$this->libraries->registerPath($path->getPathname())
|
||||
->registerAutoloader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup default logging
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ class Cli extends ApplicationBootstrap
|
|||
$this->assertRunningOnCli();
|
||||
$this->setupLogging()
|
||||
->setupErrorHandling()
|
||||
->loadLibraries()
|
||||
->loadConfig()
|
||||
->setupTimezone()
|
||||
->setupInternationalization()
|
||||
|
|
|
@ -65,6 +65,7 @@ class EmbeddedWeb extends ApplicationBootstrap
|
|||
return $this
|
||||
->setupZendAutoloader()
|
||||
->setupErrorHandling()
|
||||
->loadLibraries()
|
||||
->loadConfig()
|
||||
->setupLogging()
|
||||
->setupLogger()
|
||||
|
|
|
@ -83,6 +83,7 @@ class Web extends EmbeddedWeb
|
|||
->setupZendAutoloader()
|
||||
->setupLogging()
|
||||
->setupErrorHandling()
|
||||
->loadLibraries()
|
||||
->loadConfig()
|
||||
->setupLogger()
|
||||
->setupRequest()
|
||||
|
|
Loading…
Reference in New Issue