Support multiple plugins directories
This commit is contained in:
parent
5fa956dfb6
commit
4fcdfc2b7e
|
|
@ -84,7 +84,7 @@ class MarketController extends Controller
|
||||||
|
|
||||||
$url = $metadata['dist']['url'];
|
$url = $metadata['dist']['url'];
|
||||||
$filename = Arr::last(explode('/', $url));
|
$filename = Arr::last(explode('/', $url));
|
||||||
$pluginsDir = $manager->getPluginsDir();
|
$pluginsDir = $manager->getPluginsDirs()->first();
|
||||||
$path = storage_path("packages/$name".'_'.$metadata['version'].'.zip');
|
$path = storage_path("packages/$name".'_'.$metadata['version'].'.zip');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,11 @@ class PluginManager
|
||||||
});
|
});
|
||||||
$plugins = collect();
|
$plugins = collect();
|
||||||
|
|
||||||
collect($this->filesystem->directories($this->getPluginsDir()))
|
$this->getPluginsDirs()
|
||||||
|
->flatMap(function ($directory) {
|
||||||
|
return $this->filesystem->directories($directory);
|
||||||
|
})
|
||||||
|
->unique()
|
||||||
->filter(function ($directory) {
|
->filter(function ($directory) {
|
||||||
return $this->filesystem->exists($directory.DIRECTORY_SEPARATOR.'package.json');
|
return $this->filesystem->exists($directory.DIRECTORY_SEPARATOR.'package.json');
|
||||||
})
|
})
|
||||||
|
|
@ -365,10 +369,18 @@ class PluginManager
|
||||||
/**
|
/**
|
||||||
* The plugins path.
|
* The plugins path.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getPluginsDir()
|
public function getPluginsDirs()
|
||||||
{
|
{
|
||||||
return config('plugins.directory') ? realpath(config('plugins.directory')) : base_path('plugins');
|
$config = config('plugins.directory');
|
||||||
|
if ($config) {
|
||||||
|
return collect(preg_split('/,\s*/', $config))
|
||||||
|
->map(function ($directory) {
|
||||||
|
return realpath($directory) ?: $directory;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return collect([base_path('plugins')]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -496,4 +496,37 @@ class PluginManagerTest extends TestCase
|
||||||
$this->expectExceptionMessage('No such plugin.');
|
$this->expectExceptionMessage('No such plugin.');
|
||||||
plugin_assets('nope', 'relative');
|
plugin_assets('nope', 'relative');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReadMultipleDirectories()
|
||||||
|
{
|
||||||
|
$old = config('plugins.directory');
|
||||||
|
config(['plugins.directory' => '/kumiko,/reina']);
|
||||||
|
|
||||||
|
$this->mock(Filesystem::class, function ($mock) {
|
||||||
|
$mock->shouldReceive('directories')
|
||||||
|
->with('/kumiko')
|
||||||
|
->once()
|
||||||
|
->andReturn(collect(['/a', '/b']));
|
||||||
|
$mock->shouldReceive('directories')
|
||||||
|
->with('/reina')
|
||||||
|
->once()
|
||||||
|
->andReturn(collect(['/b', '/c']));
|
||||||
|
|
||||||
|
$mock->shouldReceive('exists')
|
||||||
|
->with('/a'.DIRECTORY_SEPARATOR.'package.json')
|
||||||
|
->once()
|
||||||
|
->andReturn(false);
|
||||||
|
$mock->shouldReceive('exists')
|
||||||
|
->with('/b'.DIRECTORY_SEPARATOR.'package.json')
|
||||||
|
->once()
|
||||||
|
->andReturn(false);
|
||||||
|
$mock->shouldReceive('exists')
|
||||||
|
->with('/c'.DIRECTORY_SEPARATOR.'package.json')
|
||||||
|
->once()
|
||||||
|
->andReturn(false);
|
||||||
|
});
|
||||||
|
app('plugins')->all();
|
||||||
|
|
||||||
|
config(['plugins.directory' => $old]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user