Introduce classes `Libraries` and `Library`
This commit is contained in:
parent
ea5329236b
commit
a2bdc8074f
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2020 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use Icinga\Application\Libraries\Library;
|
||||
|
||||
class Libraries implements IteratorAggregate
|
||||
{
|
||||
/** @var Library[] */
|
||||
protected $libraries = [];
|
||||
|
||||
/**
|
||||
* Iterate over registered libraries
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2020 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Application\Libraries;
|
||||
|
||||
class Library
|
||||
{
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Create a new Library
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue