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