diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php index 886415e0..0687efab 100644 --- a/app/Services/Plugin.php +++ b/app/Services/Plugin.php @@ -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; diff --git a/app/Services/PluginManager.php b/app/Services/PluginManager.php index 4d4a1e47..da220ed3 100644 --- a/app/Services/PluginManager.php +++ b/app/Services/PluginManager.php @@ -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')); diff --git a/app/helpers.php b/app/helpers.php index 4080b8dc..650d2835 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -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()