OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
108
app/Core/Sessions/PathManifestRepository.php
Normal file
108
app/Core/Sessions/PathManifestRepository.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Sessions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class PathManifestRepository
|
||||
{
|
||||
/**
|
||||
* The application implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The path to the manifest file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $manifestPath;
|
||||
|
||||
/**
|
||||
* Create a new service repository instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ApplicationContract $app, Filesystem $files)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->files = $files;
|
||||
$this->manifestPath = storage_path('framework');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the service provider manifest JSON file.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function loadManifest(string $manifestName)
|
||||
{
|
||||
|
||||
if ($this->files->exists($this->manifestPath.'/'.$manifestName.'.php')) {
|
||||
$manifest = $this->files->getRequire($this->manifestPath.'/'.$manifestName.'.php');
|
||||
|
||||
if ($manifest) {
|
||||
return array_merge(['when' => []], $manifest[$manifestName]);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the manifest should be compiled.
|
||||
*
|
||||
* @param array|null $manifest
|
||||
* @param array $paths
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldRefresh($manifest, $paths)
|
||||
{
|
||||
return is_null($manifest) || $manifest != $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh service manifest data structure.
|
||||
*
|
||||
* @param string $manifestName
|
||||
* @return array
|
||||
*/
|
||||
protected function freshManifest($manifestName, array $paths)
|
||||
{
|
||||
return [$manifestName => $paths];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the service manifest file to disk.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function writeManifest(string $manifestName, array $paths)
|
||||
{
|
||||
if (! is_writable($dirname = dirname($this->manifestPath.'/'.$manifestName.'.php'))) {
|
||||
throw new Exception("The {$dirname} directory must be present and writable.");
|
||||
}
|
||||
|
||||
$manifest = $this->freshManifest($manifestName, $paths);
|
||||
|
||||
$this->files->replace(
|
||||
$this->manifestPath.'/'.$manifestName.'.php', '<?php return '.var_export($manifest, true).';'
|
||||
);
|
||||
|
||||
return array_merge(['when' => []], $manifest[$manifestName]);
|
||||
}
|
||||
}
|
||||
67
app/Core/Sessions/SessionServiceProvider.php
Normal file
67
app/Core/Sessions/SessionServiceProvider.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Sessions;
|
||||
|
||||
use Illuminate\Contracts\Cache\Factory as CacheFactory;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Session\SessionServiceProvider as LaravelSessionServiceProvider;
|
||||
use Leantime\Core\Middleware\StartSession;
|
||||
|
||||
class SessionServiceProvider extends LaravelSessionServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerSessionManager();
|
||||
|
||||
$this->registerSessionDriver();
|
||||
|
||||
$this->app->singleton(StartSession::class, function ($app) {
|
||||
return new StartSession($app->make(SessionManager::class), function () use ($app) {
|
||||
return $app->make(CacheFactory::class);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the session manager instance.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
protected function registerSessionManager()
|
||||
{
|
||||
|
||||
$this->app->singleton('session', function ($app) {
|
||||
|
||||
// Switch to redis as session store when setting useRedis is set
|
||||
if (! empty($app['config']['useRedis']) && (bool) $app['config']['useRedis'] === true) {
|
||||
|
||||
$app['config']->set('session.driver', 'redis');
|
||||
$app['config']->set('session.connection', 'sessions');
|
||||
|
||||
} else {
|
||||
|
||||
// Ensure session base path exists:
|
||||
if (! is_dir(storage_path('framework/sessions')) && ! mkdir(
|
||||
$concurrentDirectory = storage_path('framework/sessions'),
|
||||
0755,
|
||||
true
|
||||
) && ! is_dir(
|
||||
$concurrentDirectory
|
||||
)) {
|
||||
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new \Illuminate\Session\SessionManager($app);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user