2017-02-22 04:10:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Core\Manifest;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module manifest holder
|
|
|
|
*/
|
|
|
|
class ModuleLoader
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var self
|
|
|
|
*/
|
|
|
|
private static $instance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ModuleManifest[] Module manifests
|
|
|
|
*/
|
|
|
|
protected $manifests = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return self
|
|
|
|
*/
|
2017-05-19 04:38:06 +02:00
|
|
|
public static function inst()
|
2017-02-22 04:10:28 +01:00
|
|
|
{
|
2017-06-22 12:50:45 +02:00
|
|
|
return self::$instance ? self::$instance : self::$instance = new static();
|
2017-02-22 04:10:28 +01:00
|
|
|
}
|
|
|
|
|
2017-03-23 21:58:54 +01:00
|
|
|
/**
|
|
|
|
* Get module by name from the current manifest.
|
2017-05-19 04:38:06 +02:00
|
|
|
* Alias for ::inst()->getManifest()->getModule()
|
2017-03-23 21:58:54 +01:00
|
|
|
*
|
|
|
|
* @param string $module
|
|
|
|
* @return Module
|
|
|
|
*/
|
|
|
|
public static function getModule($module)
|
|
|
|
{
|
2017-05-19 04:38:06 +02:00
|
|
|
return static::inst()->getManifest()->getModule($module);
|
2017-03-23 21:58:54 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 04:10:28 +01:00
|
|
|
/**
|
|
|
|
* Returns the currently active class manifest instance that is used for
|
|
|
|
* loading classes.
|
|
|
|
*
|
|
|
|
* @return ModuleManifest
|
|
|
|
*/
|
|
|
|
public function getManifest()
|
|
|
|
{
|
|
|
|
return $this->manifests[count($this->manifests) - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this class loader has a manifest.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasManifest()
|
|
|
|
{
|
|
|
|
return (bool)$this->manifests;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pushes a module manifest instance onto the top of the stack.
|
|
|
|
*
|
|
|
|
* @param ModuleManifest $manifest
|
|
|
|
*/
|
|
|
|
public function pushManifest(ModuleManifest $manifest)
|
|
|
|
{
|
|
|
|
$this->manifests[] = $manifest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ModuleManifest
|
|
|
|
*/
|
|
|
|
public function popManifest()
|
|
|
|
{
|
|
|
|
return array_pop($this->manifests);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check number of manifests
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function countManifests()
|
|
|
|
{
|
|
|
|
return count($this->manifests);
|
|
|
|
}
|
2017-06-22 12:50:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the module loader
|
|
|
|
*
|
|
|
|
* @param bool $includeTests
|
|
|
|
* @param bool $forceRegen
|
|
|
|
*/
|
|
|
|
public function init($includeTests = false, $forceRegen = false)
|
|
|
|
{
|
|
|
|
foreach ($this->manifests as $manifest) {
|
|
|
|
$manifest->init($includeTests, $forceRegen);
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 04:10:28 +01:00
|
|
|
}
|