diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index dcdde941a..3796ca05f 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -63,11 +63,11 @@ class ExtensionManager */ public function getExtensions() { - if (is_null($this->extensions) && $this->filesystem->exists(public_path('vendor/composer/installed.json'))) { + if (is_null($this->extensions) && $this->filesystem->exists($this->app->basePath().'/vendor/composer/installed.json')) { $extensions = new Collection(); // Load all packages installed by composer. - $installed = json_decode($this->filesystem->get(public_path('vendor/composer/installed.json')), true); + $installed = json_decode($this->filesystem->get($this->app->basePath().'/vendor/composer/installed.json'), true); foreach ($installed as $package) { if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) { @@ -180,7 +180,7 @@ class ExtensionManager if ($extension->hasAssets()) { $this->filesystem->copyDirectory( $extension->getPath().'/assets', - $this->app->basePath().'/assets/extensions/'.$extension->getId() + $this->app->publicPath().'/assets/extensions/'.$extension->getId() ); } } @@ -192,7 +192,7 @@ class ExtensionManager */ protected function unpublishAssets(Extension $extension) { - $this->filesystem->deleteDirectory($this->app->basePath().'/assets/extensions/'.$extension); + $this->filesystem->deleteDirectory($this->app->publicPath().'/assets/extensions/'.$extension); } /** @@ -204,7 +204,7 @@ class ExtensionManager */ public function getAsset(Extension $extension, $path) { - return $this->app->basePath().'/assets/extensions/'.$extension->getId().$path; + return $this->app->publicPath().'/assets/extensions/'.$extension->getId().$path; } /** @@ -318,6 +318,6 @@ class ExtensionManager */ protected function getExtensionsDir() { - return public_path('vendor'); + return $this->app->basePath().'/vendor'; } } diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/AbstractServer.php index a37d4ec28..66ef7e4bf 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/AbstractServer.php @@ -25,7 +25,12 @@ abstract class AbstractServer /** * @var string */ - protected $path; + protected $basePath; + + /** + * @var string + */ + protected $publicPath; /** * @var array @@ -35,15 +40,20 @@ abstract class AbstractServer /** * @param string $path */ - public function __construct($path = null) + public function __construct($basePath = null, $publicPath = null) { - if ($path === null) { - $path = getcwd(); + if ($basePath === null) { + $basePath = getcwd(); } - $this->path = $path; + if ($publicPath === null) { + $publicPath = $basePath; + } - if (file_exists($file = $this->path.'/config.php')) { + $this->basePath = $basePath; + $this->publicPath = $publicPath; + + if (file_exists($file = $this->basePath.'/config.php')) { $this->config = include $file; } @@ -53,17 +63,33 @@ abstract class AbstractServer /** * @return string */ - public function getPath() + public function getBasePath() { - return $this->path; + return $this->basePath; } /** - * @param string $path + * @return string */ - public function setPath($path) + public function getPublicPath() { - $this->path = $path; + return $this->publicPath; + } + + /** + * @param string $base_path + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * @param string $public_path + */ + public function setPublicPath($publicPath) + { + $this->publicPath = $publicPath; } /** @@ -89,7 +115,7 @@ abstract class AbstractServer { date_default_timezone_set('UTC'); - $app = new Application($this->path); + $app = new Application($this->basePath, $this->publicPath); $app->instance('env', 'production'); $app->instance('flarum.config', $this->config); diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index 697eec1eb..797ada8eb 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -33,6 +33,13 @@ class Application extends Container implements ApplicationContract */ protected $basePath; + /** + * The public path for the Flarum installation. + * + * @var string + */ + protected $publicPath; + /** * Indicates if the application has "booted". * @@ -87,7 +94,7 @@ class Application extends Container implements ApplicationContract * * @param string|null $basePath */ - public function __construct($basePath = null) + public function __construct($basePath = null, $publicPath = null) { $this->registerBaseBindings(); @@ -98,6 +105,10 @@ class Application extends Container implements ApplicationContract if ($basePath) { $this->setBasePath($basePath); } + + if ($publicPath) { + $this->setPublicPath($publicPath); + } } /** @@ -203,6 +214,7 @@ class Application extends Container implements ApplicationContract * Set the base path for the application. * * @param string $basePath + * @param string $publicPath * @return $this */ public function setBasePath($basePath) @@ -214,6 +226,22 @@ class Application extends Container implements ApplicationContract return $this; } + /** + * Set the public path for the application. + * + * @param string $basePath + * @param string $publicPath + * @return $this + */ + public function setPublicPath($publicPath) + { + $this->publicPath = rtrim($publicPath, '\/'); + + $this->bindPathsInContainer(); + + return $this; + } + /** * Bind all of the application paths in the container. * @@ -243,7 +271,7 @@ class Application extends Container implements ApplicationContract */ public function publicPath() { - return $this->basePath; + return $this->publicPath; } /** diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 49bb72a34..4e7b1c16a 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -358,7 +358,7 @@ class InstallCommand extends AbstractCommand { $this->filesystem->copyDirectory( __DIR__.'/../../../assets', - $this->application->basePath().'/assets' + $this->application->publicPath().'/assets' ); } diff --git a/framework/core/src/helpers.php b/framework/core/src/helpers.php index 488ef8644..11ba467f4 100644 --- a/framework/core/src/helpers.php +++ b/framework/core/src/helpers.php @@ -64,7 +64,7 @@ if (! function_exists('public_path')) { */ function public_path($path = '') { - return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.$path : $path); + return app()->publicPath().($path ? DIRECTORY_SEPARATOR.$path : $path); } }