add plugin_assets() helper function

This commit is contained in:
printempw 2016-12-31 16:07:12 +08:00
parent f0a76dad04
commit d622e455c7
3 changed files with 33 additions and 1 deletions

View File

@ -16,12 +16,19 @@ use Illuminate\Contracts\Support\Arrayable;
class Plugin implements Arrayable, ArrayAccess
{
/**
* The directory of this plugin.
* The full directory of this plugin.
*
* @var string
*/
protected $path;
/**
* The directory name where the plugin installed.
*
* @var string
*/
protected $dirname;
/**
* package.json of the package.
*
@ -115,6 +122,18 @@ class Plugin implements Arrayable, ArrayAccess
return $this->installed;
}
public function getDirname()
{
return $this->dirname;
}
public function setDirname($dirname)
{
$this->dirname = $dirname;
return $this;
}
public function getNameSpace()
{
return $this->namespace;

View File

@ -85,6 +85,7 @@ class PluginManager
$plugin = new Plugin($this->getPluginsDir().'/'.$path, $package);
// Per default all plugins are installed if they are registered in composer.
$plugin->setDirname($path);
$plugin->setInstalled(true);
$plugin->setNameSpace(Arr::get($package, 'namespace'));
$plugin->setVersion(Arr::get($package, 'version'));

View File

@ -48,6 +48,18 @@ if (! function_exists('assets')) {
}
}
if (! function_exists('plugin_assets')) {
function plugin_assets($id, $relative_uri)
{
if ($plugin = app('plugins')->getPlugin($id)) {
return url("plugins/{$plugin->getDirname()}/$relative_uri");
} else {
throw new InvalidArgumentException("No such plugin.");
}
}
}
if (! function_exists('json')) {
function json()