diff --git a/src/Database/Console/MigrateCommand.php b/src/Database/Console/MigrateCommand.php index a15373286..11c0126ec 100644 --- a/src/Database/Console/MigrateCommand.php +++ b/src/Database/Console/MigrateCommand.php @@ -80,7 +80,7 @@ class MigrateCommand extends AbstractCommand $this->info('Publishing assets...'); $this->app->make('files')->copyDirectory( - $this->app->basePath().'/vendor/components/font-awesome/webfonts', + $this->app->vendorPath().'/components/font-awesome/webfonts', $this->app->publicPath().'/assets/fonts' ); } diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index cb72b718b..6682612d1 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -67,11 +67,11 @@ class ExtensionManager */ public function getExtensions() { - if (is_null($this->extensions) && $this->filesystem->exists($this->app->basePath().'/vendor/composer/installed.json')) { + if (is_null($this->extensions) && $this->filesystem->exists($this->app->vendorPath().'/composer/installed.json')) { $extensions = new Collection(); // Load all packages installed by composer. - $installed = json_decode($this->filesystem->get($this->app->basePath().'/vendor/composer/installed.json'), true); + $installed = json_decode($this->filesystem->get($this->app->vendorPath().'/composer/installed.json'), true); foreach ($installed as $package) { if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) { @@ -326,6 +326,6 @@ class ExtensionManager */ protected function getExtensionsDir() { - return $this->app->basePath().'/vendor'; + return $this->app->vendorPath(); } } diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php index ccba98c97..ae550e4c1 100644 --- a/src/Foundation/Application.php +++ b/src/Foundation/Application.php @@ -41,6 +41,20 @@ class Application extends Container implements ApplicationContract */ protected $publicPath; + /** + * The custom storage path defined by the developer. + * + * @var string + */ + protected $storagePath; + + /** + * A custom vendor path to find dependencies in non-standard environments. + * + * @var string + */ + protected $vendorPath; + /** * Indicates if the application has "booted". * @@ -83,13 +97,6 @@ class Application extends Container implements ApplicationContract */ protected $deferredServices = []; - /** - * The custom storage path defined by the developer. - * - * @var string - */ - protected $storagePath; - /** * Create a new Flarum application instance. * @@ -226,7 +233,7 @@ class Application extends Container implements ApplicationContract */ protected function bindPathsInContainer() { - foreach (['base', 'public', 'storage'] as $path) { + foreach (['base', 'public', 'storage', 'vendor'] as $path) { $this->instance('path.'.$path, $this->{$path.'Path'}()); } } @@ -261,6 +268,16 @@ class Application extends Container implements ApplicationContract return $this->storagePath ?: $this->basePath.DIRECTORY_SEPARATOR.'storage'; } + /** + * Get the path to the vendor directory where dependencies are installed. + * + * @return string + */ + public function vendorPath() + { + return $this->vendorPath ?: $this->basePath.DIRECTORY_SEPARATOR.'vendor'; + } + /** * Set the storage directory. * @@ -276,6 +293,21 @@ class Application extends Container implements ApplicationContract return $this; } + /** + * Set the vendor directory. + * + * @param string $path + * @return $this + */ + public function useVendorPath($path) + { + $this->vendorPath = $path; + + $this->instance('path.vendor', $path); + + return $this; + } + /** * Get or check the current application environment. * diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index b7262ce41..614cb1119 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -100,6 +100,10 @@ class InstalledSite implements SiteInterface $laravel->useStoragePath($this->paths['storage']); + if (isset($this->paths['vendor'])) { + $laravel->useVendorPath($this->paths['vendor']); + } + $laravel->instance('env', 'production'); $laravel->instance('flarum.config', $this->config); $laravel->instance('config', $config = $this->getIlluminateConfig($laravel)); diff --git a/src/Foundation/UninstalledSite.php b/src/Foundation/UninstalledSite.php index d8dd0bc95..d363959b2 100644 --- a/src/Foundation/UninstalledSite.php +++ b/src/Foundation/UninstalledSite.php @@ -59,6 +59,10 @@ class UninstalledSite implements SiteInterface $laravel->useStoragePath($this->paths['storage']); + if (isset($this->paths['vendor'])) { + $laravel->useVendorPath($this->paths['vendor']); + } + $laravel->instance('env', 'production'); $laravel->instance('flarum.config', []); $laravel->instance('config', $config = $this->getIlluminateConfig()); diff --git a/src/Frontend/FrontendServiceProvider.php b/src/Frontend/FrontendServiceProvider.php index efae2c933..f09399513 100644 --- a/src/Frontend/FrontendServiceProvider.php +++ b/src/Frontend/FrontendServiceProvider.php @@ -30,7 +30,7 @@ class FrontendServiceProvider extends AbstractServiceProvider ); $assets->setLessImportDirs([ - $this->app->basePath().'/vendor/components/font-awesome/less' => '' + $this->app->vendorPath().'/components/font-awesome/less' => '' ]); $assets->css([$this, 'addBaseCss']); diff --git a/src/Install/InstallServiceProvider.php b/src/Install/InstallServiceProvider.php index 1ea4fa07b..d32955232 100644 --- a/src/Install/InstallServiceProvider.php +++ b/src/Install/InstallServiceProvider.php @@ -30,7 +30,8 @@ class InstallServiceProvider extends AbstractServiceProvider return new Installation( $this->app->basePath(), $this->app->publicPath(), - $this->app->storagePath() + $this->app->storagePath(), + $this->app->vendorPath(), ); }); } diff --git a/src/Install/Installation.php b/src/Install/Installation.php index 074d5d135..8c66fbbe2 100644 --- a/src/Install/Installation.php +++ b/src/Install/Installation.php @@ -16,6 +16,7 @@ class Installation private $basePath; private $publicPath; private $storagePath; + private $vendorPath; private $configPath; private $debug = false; @@ -35,11 +36,12 @@ class Installation /** @var \Illuminate\Database\ConnectionInterface */ private $db; - public function __construct($basePath, $publicPath, $storagePath) + public function __construct($basePath, $publicPath, $storagePath, $vendorPath) { $this->basePath = $basePath; $this->publicPath = $publicPath; $this->storagePath = $storagePath; + $this->vendorPath = $vendorPath; } public function configPath($path) @@ -137,11 +139,11 @@ class Installation }); $pipeline->pipe(function () { - return new Steps\PublishAssets($this->basePath, $this->getAssetPath()); + return new Steps\PublishAssets($this->vendorPath, $this->getAssetPath()); }); $pipeline->pipe(function () { - return new Steps\EnableBundledExtensions($this->db, $this->basePath, $this->getAssetPath()); + return new Steps\EnableBundledExtensions($this->db, $this->vendorPath, $this->getAssetPath()); }); return $pipeline; diff --git a/src/Install/Steps/EnableBundledExtensions.php b/src/Install/Steps/EnableBundledExtensions.php index b887339e5..e58280b31 100644 --- a/src/Install/Steps/EnableBundledExtensions.php +++ b/src/Install/Steps/EnableBundledExtensions.php @@ -32,17 +32,17 @@ class EnableBundledExtensions implements Step /** * @var string */ - private $basePath; + private $vendorPath; /** * @var string */ private $assetPath; - public function __construct(ConnectionInterface $database, $basePath, $assetPath) + public function __construct(ConnectionInterface $database, $vendorPath, $assetPath) { $this->database = $database; - $this->basePath = $basePath; + $this->vendorPath = $vendorPath; $this->assetPath = $assetPath; } @@ -90,7 +90,7 @@ class EnableBundledExtensions implements Step */ private function loadExtensions() { - $json = file_get_contents("$this->basePath/vendor/composer/installed.json"); + $json = file_get_contents("$this->vendorPath/composer/installed.json"); return (new Collection(json_decode($json, true))) ->filter(function ($package) { @@ -98,7 +98,7 @@ class EnableBundledExtensions implements Step })->filter(function ($package) { return ! empty(Arr::get($package, 'name')); })->map(function ($package) { - $extension = new Extension($this->basePath.'/vendor/'.Arr::get($package, 'name'), $package); + $extension = new Extension($this->vendorPath.'/'.Arr::get($package, 'name'), $package); $extension->setVersion(Arr::get($package, 'version')); return $extension; diff --git a/src/Install/Steps/PublishAssets.php b/src/Install/Steps/PublishAssets.php index b8f20868b..61d0164f9 100644 --- a/src/Install/Steps/PublishAssets.php +++ b/src/Install/Steps/PublishAssets.php @@ -20,16 +20,16 @@ class PublishAssets implements Step, ReversibleStep /** * @var string */ - private $basePath; + private $vendorPath; /** * @var string */ private $assetPath; - public function __construct($basePath, $assetPath) + public function __construct($vendorPath, $assetPath) { - $this->basePath = $basePath; + $this->vendorPath = $vendorPath; $this->assetPath = $assetPath; } @@ -41,7 +41,7 @@ class PublishAssets implements Step, ReversibleStep public function run() { (new Filesystem)->copyDirectory( - "$this->basePath/vendor/components/font-awesome/webfonts", + "$this->vendorPath/components/font-awesome/webfonts", $this->targetPath() ); }