fs = $fs; $this->pluginsDirectory = $pluginsDirectory; $this->rootPath = $rootPath; } /** * Updates plugins assets so that they are available online. * * @param Manifest $manifest * * @throws RuntimeException */ public function update(Manifest $manifest) { try { $this->fs->mirror( $this->pluginsDirectory . DIRECTORY_SEPARATOR . $manifest->getName() . DIRECTORY_SEPARATOR . 'public', $this->rootPath . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $manifest->getName() ); } catch (IOException $e) { throw new RuntimeException( sprintf('Unable to copy assets for plugin %s', $manifest->getName()), $e->getCode(), $e ); } } /** * Removes assets for the plugin named with the given name * * @param string $name * * @throws RuntimeException */ public function remove($name) { try { $this->fs->remove($this->rootPath . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $name); } catch (IOException $e) { throw new RuntimeException( sprintf('Unable to remove assets for plugin %s', $name), $e->getCode(), $e ); } } /** * Twig function to generate asset URL. * * @param string $name * @param string $asset * * @return string */ public static function twigPluginAsset($name, $asset) { return sprintf('/plugins/%s/%s', $name, ltrim($asset, '/')); } }