mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
parent
d7c283a48f
commit
5f5af894ab
|
@ -69,6 +69,11 @@ class InstalledSite implements SiteInterface
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Flarum\Extend\ExtenderInterface[]
|
||||||
|
*/
|
||||||
|
protected $extenders = [];
|
||||||
|
|
||||||
public function __construct($basePath, $publicPath, array $config)
|
public function __construct($basePath, $publicPath, array $config)
|
||||||
{
|
{
|
||||||
$this->basePath = $basePath;
|
$this->basePath = $basePath;
|
||||||
|
@ -100,6 +105,17 @@ class InstalledSite implements SiteInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Flarum\Extend\ExtenderInterface[] $extenders
|
||||||
|
* @return InstalledSite
|
||||||
|
*/
|
||||||
|
public function extendWith(array $extenders): self
|
||||||
|
{
|
||||||
|
$this->extenders = $extenders;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function bootLaravel(): Application
|
protected function bootLaravel(): Application
|
||||||
{
|
{
|
||||||
$laravel = new Application($this->basePath, $this->publicPath);
|
$laravel = new Application($this->basePath, $this->publicPath);
|
||||||
|
@ -156,6 +172,10 @@ class InstalledSite implements SiteInterface
|
||||||
|
|
||||||
$laravel->boot();
|
$laravel->boot();
|
||||||
|
|
||||||
|
foreach ($this->extenders as $extension) {
|
||||||
|
$extension($laravel);
|
||||||
|
}
|
||||||
|
|
||||||
return $laravel;
|
return $laravel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,11 @@ class Site
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
if (static::hasConfigFile($paths['base'])) {
|
if (static::hasConfigFile($paths['base'])) {
|
||||||
return new InstalledSite(
|
return (new InstalledSite(
|
||||||
$paths['base'],
|
$paths['base'],
|
||||||
$paths['public'],
|
$paths['public'],
|
||||||
static::loadConfig($paths['base'])
|
static::loadConfig($paths['base'])
|
||||||
);
|
))->extendWith(static::loadExtenders($paths['base']));
|
||||||
} else {
|
} else {
|
||||||
return new UninstalledSite($paths['base'], $paths['public']);
|
return new UninstalledSite($paths['base'], $paths['public']);
|
||||||
}
|
}
|
||||||
|
@ -60,4 +60,15 @@ class Site
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function loadExtenders($basePath): array
|
||||||
|
{
|
||||||
|
$extenderFile = "$basePath/extend.php";
|
||||||
|
|
||||||
|
if (!file_exists($extenderFile)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_flatten(require $extenderFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user