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

Inject new Paths class instead of Application

This (and similar work in other areas) will allow us to further
reduce the API surface of the Application class.

Separation of concerns etc.
This commit is contained in:
Franz Liedke
2020-05-01 14:54:08 +02:00
parent bf526125eb
commit 244f61f5d3
4 changed files with 31 additions and 36 deletions

View File

@@ -13,6 +13,7 @@ use Flarum\Console\AbstractCommand;
use Flarum\Database\Migrator; use Flarum\Database\Migrator;
use Flarum\Extension\ExtensionManager; use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Application; use Flarum\Foundation\Application;
use Flarum\Foundation\Paths;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Container\Container;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
@@ -26,18 +27,18 @@ class MigrateCommand extends AbstractCommand
protected $container; protected $container;
/** /**
* @var Application * @var Paths
*/ */
protected $app; protected $paths;
/** /**
* @param Container $container * @param Container $container
* @param Application $application * @param Paths $paths
*/ */
public function __construct(Container $container, Application $application) public function __construct(Container $container, Paths $paths)
{ {
$this->container = $container; $this->container = $container;
$this->app = $application; $this->paths = $paths;
parent::__construct(); parent::__construct();
} }
@@ -91,8 +92,8 @@ class MigrateCommand extends AbstractCommand
$this->info('Publishing assets...'); $this->info('Publishing assets...');
$this->container->make('files')->copyDirectory( $this->container->make('files')->copyDirectory(
$this->app->vendorPath().'/components/font-awesome/webfonts', $this->paths->vendor.'/components/font-awesome/webfonts',
$this->app->publicPath().'/assets/fonts' $this->paths->public.'/assets/fonts'
); );
} }
} }

View File

@@ -10,6 +10,7 @@
namespace Flarum\Database; namespace Flarum\Database;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
class MigrationServiceProvider extends AbstractServiceProvider class MigrationServiceProvider extends AbstractServiceProvider
@@ -26,7 +27,7 @@ class MigrationServiceProvider extends AbstractServiceProvider
$this->app->bind(MigrationCreator::class, function () { $this->app->bind(MigrationCreator::class, function () {
return new MigrationCreator( return new MigrationCreator(
$this->app->make(Filesystem::class), $this->app->make(Filesystem::class),
$this->app->basePath() $this->app->make(Paths::class)->base
); );
}); });
} }

View File

@@ -15,7 +15,7 @@ use Flarum\Extension\Event\Disabling;
use Flarum\Extension\Event\Enabled; use Flarum\Extension\Event\Enabled;
use Flarum\Extension\Event\Enabling; use Flarum\Extension\Event\Enabling;
use Flarum\Extension\Event\Uninstalled; use Flarum\Extension\Event\Uninstalled;
use Flarum\Foundation\Application; use Flarum\Foundation\Paths;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Events\Dispatcher;
@@ -29,7 +29,10 @@ class ExtensionManager
{ {
protected $config; protected $config;
protected $app; /**
* @var Paths
*/
protected $paths;
protected $container; protected $container;
@@ -52,14 +55,14 @@ class ExtensionManager
public function __construct( public function __construct(
SettingsRepositoryInterface $config, SettingsRepositoryInterface $config,
Application $app, Paths $paths,
Container $container, Container $container,
Migrator $migrator, Migrator $migrator,
Dispatcher $dispatcher, Dispatcher $dispatcher,
Filesystem $filesystem Filesystem $filesystem
) { ) {
$this->config = $config; $this->config = $config;
$this->app = $app; $this->paths = $paths;
$this->container = $container; $this->container = $container;
$this->migrator = $migrator; $this->migrator = $migrator;
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
@@ -71,11 +74,11 @@ class ExtensionManager
*/ */
public function getExtensions() public function getExtensions()
{ {
if (is_null($this->extensions) && $this->filesystem->exists($this->app->vendorPath().'/composer/installed.json')) { if (is_null($this->extensions) && $this->filesystem->exists($this->paths->vendor.'/composer/installed.json')) {
$extensions = new Collection(); $extensions = new Collection();
// Load all packages installed by composer. // Load all packages installed by composer.
$installed = json_decode($this->filesystem->get($this->app->vendorPath().'/composer/installed.json'), true); $installed = json_decode($this->filesystem->get($this->paths->vendor.'/composer/installed.json'), true);
// Composer 2.0 changes the structure of the installed.json manifest // Composer 2.0 changes the structure of the installed.json manifest
$installed = $installed['packages'] ?? $installed; $installed = $installed['packages'] ?? $installed;
@@ -86,8 +89,8 @@ class ExtensionManager
} }
$path = isset($package['install-path']) $path = isset($package['install-path'])
? $this->getExtensionsDir().'/composer/'.$package['install-path'] ? $this->paths->vendor.'/composer/'.$package['install-path']
: $this->getExtensionsDir().'/'.Arr::get($package, 'name'); : $this->paths->vendor.'/'.Arr::get($package, 'name');
// Instantiates an Extension object using the package path and composer.json file. // Instantiates an Extension object using the package path and composer.json file.
$extension = new Extension($path, $package); $extension = new Extension($path, $package);
@@ -203,7 +206,7 @@ class ExtensionManager
if ($extension->hasAssets()) { if ($extension->hasAssets()) {
$this->filesystem->copyDirectory( $this->filesystem->copyDirectory(
$extension->getPath().'/assets', $extension->getPath().'/assets',
$this->app->publicPath().'/assets/extensions/'.$extension->getId() $this->paths->public.'/assets/extensions/'.$extension->getId()
); );
} }
} }
@@ -215,7 +218,7 @@ class ExtensionManager
*/ */
protected function unpublishAssets(Extension $extension) protected function unpublishAssets(Extension $extension)
{ {
$this->filesystem->deleteDirectory($this->app->publicPath().'/assets/extensions/'.$extension->getId()); $this->filesystem->deleteDirectory($this->paths->public.'/assets/extensions/'.$extension->getId());
} }
/** /**
@@ -227,7 +230,7 @@ class ExtensionManager
*/ */
public function getAsset(Extension $extension, $path) public function getAsset(Extension $extension, $path)
{ {
return $this->app->publicPath().'/assets/extensions/'.$extension->getId().$path; return $this->paths->public.'/assets/extensions/'.$extension->getId().$path;
} }
/** /**
@@ -332,14 +335,4 @@ class ExtensionManager
return isset($enabled[$extension]); return isset($enabled[$extension]);
} }
/**
* The extensions path.
*
* @return string
*/
protected function getExtensionsDir()
{
return $this->app->vendorPath();
}
} }

View File

@@ -10,8 +10,8 @@
namespace Flarum\Foundation\Console; namespace Flarum\Foundation\Console;
use Flarum\Console\AbstractCommand; use Flarum\Console\AbstractCommand;
use Flarum\Foundation\Application;
use Flarum\Foundation\Event\ClearingCache; use Flarum\Foundation\Event\ClearingCache;
use Flarum\Foundation\Paths;
use Illuminate\Contracts\Cache\Store; use Illuminate\Contracts\Cache\Store;
class CacheClearCommand extends AbstractCommand class CacheClearCommand extends AbstractCommand
@@ -22,18 +22,18 @@ class CacheClearCommand extends AbstractCommand
protected $cache; protected $cache;
/** /**
* @var Application * @var Paths
*/ */
protected $app; protected $paths;
/** /**
* @param Store $cache * @param Store $cache
* @param Application $app * @param Paths $paths
*/ */
public function __construct(Store $cache, Application $app) public function __construct(Store $cache, Paths $paths)
{ {
$this->cache = $cache; $this->cache = $cache;
$this->app = $app; $this->paths = $paths;
parent::__construct(); parent::__construct();
} }
@@ -57,7 +57,7 @@ class CacheClearCommand extends AbstractCommand
$this->cache->flush(); $this->cache->flush();
$storagePath = $this->app->storagePath(); $storagePath = $this->paths->storage;
array_map('unlink', glob($storagePath.'/formatter/*')); array_map('unlink', glob($storagePath.'/formatter/*'));
array_map('unlink', glob($storagePath.'/locale/*')); array_map('unlink', glob($storagePath.'/locale/*'));