mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 11:34:36 +08:00
parent
b4dbab5df1
commit
e3e10a8fc3
|
@ -50,19 +50,9 @@ use Psr\Log\LoggerInterface;
|
|||
class InstalledSite implements SiteInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
private $basePath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $publicPath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $storagePath;
|
||||
private $paths;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@ -74,10 +64,9 @@ class InstalledSite implements SiteInterface
|
|||
*/
|
||||
private $extenders = [];
|
||||
|
||||
public function __construct($basePath, $publicPath, array $config)
|
||||
public function __construct(array $paths, array $config)
|
||||
{
|
||||
$this->basePath = $basePath;
|
||||
$this->publicPath = $publicPath;
|
||||
$this->paths = $paths;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
|
@ -94,17 +83,6 @@ class InstalledSite implements SiteInterface
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $storagePath
|
||||
* @return static
|
||||
*/
|
||||
public function setStoragePath($storagePath)
|
||||
{
|
||||
$this->storagePath = $storagePath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flarum\Extend\ExtenderInterface[] $extenders
|
||||
* @return InstalledSite
|
||||
|
@ -118,11 +96,9 @@ class InstalledSite implements SiteInterface
|
|||
|
||||
private function bootLaravel(): Application
|
||||
{
|
||||
$laravel = new Application($this->basePath, $this->publicPath);
|
||||
$laravel = new Application($this->paths['base'], $this->paths['public']);
|
||||
|
||||
if ($this->storagePath) {
|
||||
$laravel->useStoragePath($this->storagePath);
|
||||
}
|
||||
$laravel->useStoragePath($this->paths['storage']);
|
||||
|
||||
$laravel->instance('env', 'production');
|
||||
$laravel->instance('flarum.config', $this->config);
|
||||
|
@ -188,7 +164,7 @@ class InstalledSite implements SiteInterface
|
|||
return new ConfigRepository([
|
||||
'view' => [
|
||||
'paths' => [],
|
||||
'compiled' => $app->storagePath().'/views',
|
||||
'compiled' => $this->paths['storage'].'/views',
|
||||
],
|
||||
'mail' => [
|
||||
'driver' => 'mail',
|
||||
|
@ -199,18 +175,18 @@ class InstalledSite implements SiteInterface
|
|||
'disks' => [
|
||||
'flarum-assets' => [
|
||||
'driver' => 'local',
|
||||
'root' => $app->publicPath().'/assets',
|
||||
'root' => $this->paths['public'].'/assets',
|
||||
'url' => $app->url('assets')
|
||||
],
|
||||
'flarum-avatars' => [
|
||||
'driver' => 'local',
|
||||
'root' => $app->publicPath().'/assets/avatars'
|
||||
'root' => $this->paths['public'].'/assets/avatars'
|
||||
]
|
||||
]
|
||||
],
|
||||
'session' => [
|
||||
'lifetime' => 120,
|
||||
'files' => $app->storagePath().'/sessions',
|
||||
'files' => $this->paths['storage'].'/sessions',
|
||||
'cookie' => 'session'
|
||||
]
|
||||
]);
|
||||
|
@ -218,7 +194,7 @@ class InstalledSite implements SiteInterface
|
|||
|
||||
private function registerLogger(Application $app)
|
||||
{
|
||||
$logPath = $app->storagePath().'/logs/flarum.log';
|
||||
$logPath = $this->paths['storage'].'/logs/flarum.log';
|
||||
$handler = new RotatingFileHandler($logPath, Logger::INFO);
|
||||
$handler->setFormatter(new LineFormatter(null, null, true, true));
|
||||
|
||||
|
@ -233,8 +209,8 @@ class InstalledSite implements SiteInterface
|
|||
});
|
||||
$app->alias('cache.store', Repository::class);
|
||||
|
||||
$app->singleton('cache.filestore', function ($app) {
|
||||
return new FileStore(new Filesystem, $app->storagePath().'/cache');
|
||||
$app->singleton('cache.filestore', function () {
|
||||
return new FileStore(new Filesystem, $this->paths['storage'].'/cache');
|
||||
});
|
||||
$app->alias('cache.filestore', Store::class);
|
||||
}
|
||||
|
|
|
@ -16,32 +16,34 @@ use RuntimeException;
|
|||
|
||||
class Site
|
||||
{
|
||||
public static function fromDefaultBase($basePath)
|
||||
{
|
||||
return static::fromPaths([
|
||||
'base' => $basePath,
|
||||
'public' => "$basePath/public",
|
||||
'storage' => "$basePath/storage",
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @param array $paths
|
||||
* @return SiteInterface
|
||||
*/
|
||||
public static function fromPaths(array $paths)
|
||||
{
|
||||
if (! isset($paths['base'])) {
|
||||
if (! isset($paths['base'], $paths['public'], $paths['storage'])) {
|
||||
throw new InvalidArgumentException(
|
||||
'No base path given'
|
||||
'Paths array requires keys base, public and storage'
|
||||
);
|
||||
}
|
||||
|
||||
if (! isset($paths['public'])) {
|
||||
$paths['public'] = $paths['base'];
|
||||
}
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
if (static::hasConfigFile($paths['base'])) {
|
||||
return (new InstalledSite(
|
||||
$paths['base'],
|
||||
$paths['public'],
|
||||
static::loadConfig($paths['base'])
|
||||
))->extendWith(static::loadExtenders($paths['base']));
|
||||
return (
|
||||
new InstalledSite($paths, static::loadConfig($paths['base']))
|
||||
)->extendWith(static::loadExtenders($paths['base']));
|
||||
} else {
|
||||
return new UninstalledSite($paths['base'], $paths['public']);
|
||||
return new UninstalledSite($paths);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,24 +32,13 @@ use Psr\Log\LoggerInterface;
|
|||
class UninstalledSite implements SiteInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
private $basePath;
|
||||
private $paths;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $publicPath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $storagePath;
|
||||
|
||||
public function __construct($basePath, $publicPath)
|
||||
public function __construct(array $paths)
|
||||
{
|
||||
$this->basePath = $basePath;
|
||||
$this->publicPath = $publicPath;
|
||||
$this->paths = $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,15 +55,13 @@ class UninstalledSite implements SiteInterface
|
|||
|
||||
private function bootLaravel(): Application
|
||||
{
|
||||
$laravel = new Application($this->basePath, $this->publicPath);
|
||||
$laravel = new Application($this->paths['base'], $this->paths['public']);
|
||||
|
||||
if ($this->storagePath) {
|
||||
$laravel->useStoragePath($this->storagePath);
|
||||
}
|
||||
$laravel->useStoragePath($this->paths['storage']);
|
||||
|
||||
$laravel->instance('env', 'production');
|
||||
$laravel->instance('flarum.config', []);
|
||||
$laravel->instance('config', $config = $this->getIlluminateConfig($laravel));
|
||||
$laravel->instance('config', $config = $this->getIlluminateConfig());
|
||||
|
||||
$this->registerLogger($laravel);
|
||||
|
||||
|
@ -109,15 +96,14 @@ class UninstalledSite implements SiteInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @return ConfigRepository
|
||||
*/
|
||||
private function getIlluminateConfig(Application $app)
|
||||
private function getIlluminateConfig()
|
||||
{
|
||||
return new ConfigRepository([
|
||||
'session' => [
|
||||
'lifetime' => 120,
|
||||
'files' => $app->storagePath().'/sessions',
|
||||
'files' => $this->paths['storage'].'/sessions',
|
||||
'cookie' => 'session'
|
||||
]
|
||||
]);
|
||||
|
@ -125,7 +111,7 @@ class UninstalledSite implements SiteInterface
|
|||
|
||||
private function registerLogger(Application $app)
|
||||
{
|
||||
$logPath = $app->storagePath().'/logs/flarum-installer.log';
|
||||
$logPath = $this->paths['storage'].'/logs/flarum-installer.log';
|
||||
$handler = new StreamHandler($logPath, Logger::DEBUG);
|
||||
$handler->setFormatter(new LineFormatter(null, null, true, true));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user