mirror of
https://github.com/flarum/framework.git
synced 2025-02-23 02:50:57 +08:00
Public and base directory can be separated (#938)
* Public and base directory can be separated * Standards compliance for folders separation implementation
This commit is contained in:
parent
d8b043dacb
commit
777579e146
@ -63,11 +63,11 @@ class ExtensionManager
|
|||||||
*/
|
*/
|
||||||
public function getExtensions()
|
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();
|
$extensions = new Collection();
|
||||||
|
|
||||||
// Load all packages installed by composer.
|
// 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) {
|
foreach ($installed as $package) {
|
||||||
if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) {
|
if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) {
|
||||||
@ -180,7 +180,7 @@ class ExtensionManager
|
|||||||
if ($extension->hasAssets()) {
|
if ($extension->hasAssets()) {
|
||||||
$this->filesystem->copyDirectory(
|
$this->filesystem->copyDirectory(
|
||||||
$extension->getPath().'/assets',
|
$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)
|
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)
|
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()
|
protected function getExtensionsDir()
|
||||||
{
|
{
|
||||||
return public_path('vendor');
|
return $this->app->basePath().'/vendor';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,12 @@ abstract class AbstractServer
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $path;
|
protected $basePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $publicPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -35,15 +40,20 @@ abstract class AbstractServer
|
|||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
*/
|
*/
|
||||||
public function __construct($path = null)
|
public function __construct($basePath = null, $publicPath = null)
|
||||||
{
|
{
|
||||||
if ($path === null) {
|
if ($basePath === null) {
|
||||||
$path = getcwd();
|
$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;
|
$this->config = include $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,17 +63,33 @@ abstract class AbstractServer
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @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');
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
$app = new Application($this->path);
|
$app = new Application($this->basePath, $this->publicPath);
|
||||||
|
|
||||||
$app->instance('env', 'production');
|
$app->instance('env', 'production');
|
||||||
$app->instance('flarum.config', $this->config);
|
$app->instance('flarum.config', $this->config);
|
||||||
|
@ -33,6 +33,13 @@ class Application extends Container implements ApplicationContract
|
|||||||
*/
|
*/
|
||||||
protected $basePath;
|
protected $basePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The public path for the Flarum installation.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $publicPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if the application has "booted".
|
* Indicates if the application has "booted".
|
||||||
*
|
*
|
||||||
@ -87,7 +94,7 @@ class Application extends Container implements ApplicationContract
|
|||||||
*
|
*
|
||||||
* @param string|null $basePath
|
* @param string|null $basePath
|
||||||
*/
|
*/
|
||||||
public function __construct($basePath = null)
|
public function __construct($basePath = null, $publicPath = null)
|
||||||
{
|
{
|
||||||
$this->registerBaseBindings();
|
$this->registerBaseBindings();
|
||||||
|
|
||||||
@ -98,6 +105,10 @@ class Application extends Container implements ApplicationContract
|
|||||||
if ($basePath) {
|
if ($basePath) {
|
||||||
$this->setBasePath($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.
|
* Set the base path for the application.
|
||||||
*
|
*
|
||||||
* @param string $basePath
|
* @param string $basePath
|
||||||
|
* @param string $publicPath
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setBasePath($basePath)
|
public function setBasePath($basePath)
|
||||||
@ -214,6 +226,22 @@ class Application extends Container implements ApplicationContract
|
|||||||
return $this;
|
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.
|
* Bind all of the application paths in the container.
|
||||||
*
|
*
|
||||||
@ -243,7 +271,7 @@ class Application extends Container implements ApplicationContract
|
|||||||
*/
|
*/
|
||||||
public function publicPath()
|
public function publicPath()
|
||||||
{
|
{
|
||||||
return $this->basePath;
|
return $this->publicPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,7 +358,7 @@ class InstallCommand extends AbstractCommand
|
|||||||
{
|
{
|
||||||
$this->filesystem->copyDirectory(
|
$this->filesystem->copyDirectory(
|
||||||
__DIR__.'/../../../assets',
|
__DIR__.'/../../../assets',
|
||||||
$this->application->basePath().'/assets'
|
$this->application->publicPath().'/assets'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ if (! function_exists('public_path')) {
|
|||||||
*/
|
*/
|
||||||
function public_path($path = '')
|
function public_path($path = '')
|
||||||
{
|
{
|
||||||
return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.$path : $path);
|
return app()->publicPath().($path ? DIRECTORY_SEPARATOR.$path : $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user