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:
Buhnici Alexandru 2016-04-23 05:25:53 +03:00 committed by Toby Zerner
parent d8b043dacb
commit 777579e146
5 changed files with 76 additions and 22 deletions

View File

@ -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';
}
}

View File

@ -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);

View File

@ -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;
}
/**

View File

@ -358,7 +358,7 @@ class InstallCommand extends AbstractCommand
{
$this->filesystem->copyDirectory(
__DIR__.'/../../../assets',
$this->application->basePath().'/assets'
$this->application->publicPath().'/assets'
);
}

View File

@ -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);
}
}