diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index c811e32cf..3aa8ca415 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -69,6 +69,11 @@ class InstalledSite implements SiteInterface */ protected $config; + /** + * @var \Flarum\Extend\ExtenderInterface[] + */ + protected $extenders = []; + public function __construct($basePath, $publicPath, array $config) { $this->basePath = $basePath; @@ -100,6 +105,17 @@ class InstalledSite implements SiteInterface return $this; } + /** + * @param \Flarum\Extend\ExtenderInterface[] $extenders + * @return InstalledSite + */ + public function extendWith(array $extenders): self + { + $this->extenders = $extenders; + + return $this; + } + protected function bootLaravel(): Application { $laravel = new Application($this->basePath, $this->publicPath); @@ -156,6 +172,10 @@ class InstalledSite implements SiteInterface $laravel->boot(); + foreach ($this->extenders as $extension) { + $extension($laravel); + } + return $laravel; } diff --git a/src/Foundation/Site.php b/src/Foundation/Site.php index dc58cb593..00de21ae1 100644 --- a/src/Foundation/Site.php +++ b/src/Foundation/Site.php @@ -35,11 +35,11 @@ class Site date_default_timezone_set('UTC'); if (static::hasConfigFile($paths['base'])) { - return new InstalledSite( + return (new InstalledSite( $paths['base'], $paths['public'], static::loadConfig($paths['base']) - ); + ))->extendWith(static::loadExtenders($paths['base'])); } else { return new UninstalledSite($paths['base'], $paths['public']); } @@ -60,4 +60,15 @@ class Site return $config; } + + private static function loadExtenders($basePath): array + { + $extenderFile = "$basePath/extend.php"; + + if (!file_exists($extenderFile)) { + return []; + } + + return array_flatten(require $extenderFile); + } }