1
0
mirror of https://github.com/flarum/core.git synced 2025-07-17 23:01:17 +02:00

Load per-site extenders, if available

Closes #1559.
This commit is contained in:
Franz Liedke
2018-09-01 16:16:03 +02:00
parent e8c779fcf4
commit c655f11d43
2 changed files with 33 additions and 2 deletions

View File

@@ -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;
} }

View File

@@ -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);
}
} }