/** * 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); } }
public function testGeneratedFileAfterInstall() { $pluginDir = __DIR__ . '/../Fixtures/PluginDirInstalled/test-plugin'; $pluginsDir = __DIR__ . '/../Fixtures/PluginDirInstalled'; $files = [$pluginsDir . '/services.php', $pluginsDir . '/autoload.php', $pluginsDir . '/commands.php', $pluginsDir . '/twig-paths.php', $pluginsDir . '/login.less', $pluginsDir . '/account.less']; $this->cleanup($files); $manifest = new Manifest(json_decode(file_get_contents($pluginDir . '/manifest.json'), true)); $generator = new AutoloaderGenerator($pluginsDir); $generator->write([$manifest]); $finder = new ExecutableFinder(); $php = $finder->find('php'); if (null === $php) { $this->markTestSkipped('Php executable not found.'); } foreach ($files as $file) { $this->assertFileExists($file); $process = ProcessBuilder::create([$php, '-l', $file])->getProcess(); $process->run(); $this->assertTrue($process->isSuccessful(), basename($file) . ' is valid'); } // test autoload $this->assertFalse(class_exists('Vendor\\PluginService')); $loader = (require $pluginsDir . '/autoload.php'); $this->assertInstanceOf('Composer\\Autoload\\ClassLoader', $loader); $this->assertTrue(class_exists('Vendor\\PluginService')); // load services $app = new Application(); $app['conf']->set(['plugins', $manifest->getName(), 'enabled'], true); $retrievedApp = (require $pluginsDir . '/services.php'); $this->assertSame($app, $retrievedApp); $this->assertEquals('hello world', $app['plugin-test']); // load services $cli = new CLI('test'); $retrievedCli = (require $pluginsDir . '/commands.php'); $this->assertSame($cli, $retrievedCli); $this->assertInstanceOf('Vendor\\CustomCommand', $cli['console']->find('hello:world')); $mapping = (require $pluginsDir . '/twig-paths.php'); $this->assertSame(['plugin-test-plugin' => realpath($pluginsDir) . '/test-plugin/views', realpath($pluginsDir) . '/test-plugin/views', realpath($pluginsDir) . '/test-plugin/twig-views'], $mapping); $this->assertRegExp('#@import#', file_get_contents($pluginsDir . '/login.less')); $this->assertRegExp('#@import#', file_get_contents($pluginsDir . '/account.less')); $this->cleanup($files); }
public function validatePlugin($directory) { $this->ensureComposer($directory); $this->ensureManifest($directory); $this->ensureDir($directory . DIRECTORY_SEPARATOR . 'public'); $manifest = $directory . DIRECTORY_SEPARATOR . 'manifest.json'; $data = @json_decode(@file_get_contents($manifest)); if (JSON_ERROR_NONE !== json_last_error()) { throw new PluginValidationException(sprintf('Unable to parse file %s', $manifest)); } try { $this->manifestValidator->validate($data); } catch (JsonValidationException $e) { throw new PluginValidationException('Manifest file is invalid', $e->getCode(), $e); } $manifest = new Manifest($this->objectToArray($data)); foreach ($manifest->getTwigPaths() as $path) { $this->ensureDirIn($directory . DIRECTORY_SEPARATOR . $path, $directory); } return $manifest; }
public function testGetters() { $data = json_decode(file_get_contents(__DIR__ . '/../Fixtures/PluginDir/TestPlugin/manifest.json'), true); $manifest = new Manifest($data); $this->assertEquals('test-plugin', $manifest->getName()); $this->assertEquals('A custom class connector', $manifest->getDescription()); $this->assertEquals(['connector'], $manifest->getKeywords()); $this->assertEquals([['name' => 'Author name', 'homepage' => 'http://example.com', 'email' => '*****@*****.**']], $manifest->getAuthors()); $this->assertEquals('http://example.com/project/example', $manifest->getHomepage()); $this->assertEquals('MIT', $manifest->getLicense()); $this->assertEquals('0.1', $manifest->getVersion()); $this->assertEquals('3.8', $manifest->getMinimumPhraseanetVersion()); $this->assertEquals('3.10', $manifest->getMaximumPhraseanetVersion()); $this->assertEquals(['views', 'twig-views'], $manifest->getTwigPaths()); $this->assertEquals([['class' => 'Vendor\\CustomCommand']], $manifest->getCommands()); $this->assertEquals([['class' => 'Vendor\\PluginService']], $manifest->getServices()); $this->assertEquals(['property' => 'value'], $manifest->getExtra()); }
/** * @param Manifest $manifest * @return string */ private function getPluginBaseDir(Manifest $manifest) { return DIRECTORY_SEPARATOR . $manifest->getName(); }
private function wrapWithConditionnal(Manifest $manifest, $wrapped) { if (trim($wrapped) === '') { return ''; } $name = $manifest->getName(); return <<<EOF if (\$app['plugins.manager']->isEnabled('{$name}')) { {$wrapped} } EOF; }