/** * Dump the metadata for extension loading on the 'post-autoload-dump' event. * * @param Event $event */ public static function dump(Event $event) { $composer = $event->getComposer(); $vendorDir = $composer->getConfig()->get('vendor-dir'); $finder = self::getInstalledComposerJson(); $extensions = []; /** @var SplFileInfo $jsonFile */ foreach ($finder as $jsonFile) { $jsonData = json_decode($jsonFile->getContents(), true); if (isset($jsonData['type']) && $jsonData['type'] === 'bolt-extension') { $extensions[$jsonData['name']] = PackageDescriptor::parse($composer, $jsonFile->getPath(), $jsonData); } } $fs = new Filesystem(); $fs->dumpFile($vendorDir . '/autoload.json', json_encode($extensions, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); }
/** * Dump the metadata for extension loading on the 'post-autoload-dump' event. * * @param Event $event */ public static function dump(Event $event) { $composer = $event->getComposer(); $extra = $composer->getPackage()->getExtra(); $includeAssetsDir = realpath($extra['bolt-web-path']) === realpath($extra['bolt-root-path']); /** @var PackageDescriptor[] $extensions */ $extensions = []; $finder = self::getInstalledComposerJson(); foreach ($finder as $jsonFile) { $jsonData = json_decode($jsonFile->getContents(), true); if (isset($jsonData['type']) && $jsonData['type'] === 'bolt-extension') { $webPath = 'extensions/vendor/' . $jsonData['name']; if ($includeAssetsDir && !empty($jsonData['extra']['bolt-assets'])) { $webPath .= '/' . trim($jsonData['extra']['bolt-assets'], '/'); } $extensions[$jsonData['name']] = PackageDescriptor::parse($composer, $webPath, $jsonFile->getPath(), $jsonData); } } $vendorDir = $composer->getConfig()->get('vendor-dir'); $fs = new Filesystem(); $fs->dumpFile($vendorDir . '/autoload.json', json_encode($extensions, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); }
/** * Load a single extension. * * @param PackageDescriptor $descriptor */ private function addManagedExtension(PackageDescriptor $descriptor) { $className = $descriptor->getClass(); if ($this->isClassLoadable($className) === false) { if ($descriptor->getType() === 'local' && $this->isClassLoadable('Wikimedia\\Composer\\MergePlugin') === false) { $this->flashLogger->error(Trans::__('general.phrase.error-local-extension-set-up-incomplete', ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } else { $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } return; } /** @var ExtensionInterface $extension */ $extension = new $className(); if ($extension instanceof ExtensionInterface) { $baseDir = $this->extFs->getDir($descriptor->getPath()); $webDir = $this->webFs->getDir($descriptor->getWebPath()); $this->add($extension, $baseDir, $webDir, $descriptor->getName())->setDescriptor($descriptor); } else { $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } }
/** * Load a single extension. * * @param PackageDescriptor $descriptor */ private function addManagedExtension(PackageDescriptor $descriptor) { $className = $descriptor->getClass(); if (class_exists($className) === false) { if ($descriptor->getType() === 'local' && class_exists('Wikimedia\\Composer\\MergePlugin') === false) { $this->flashLogger->error(Trans::__("Local extension set up incomplete. Please run 'Install all packages' on the Extensions page.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } else { $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } return; } /** @var ExtensionInterface $extension */ $extension = new $className(); if ($extension instanceof ExtensionInterface) { $baseDir = $this->filesystem->getDir($descriptor->getPath()); $relativeUrl = sprintf('/extensions/%s/web/', $descriptor->getPath()); $this->add($extension, $baseDir, $relativeUrl, $descriptor->getName())->setDescriptor($descriptor); } else { $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } }
/** * Load a single extension. * * @param PackageDescriptor $descriptor */ private function addManagedExtension(PackageDescriptor $descriptor) { $className = $descriptor->getClass(); if ($this->isClassLoadable($className) === false) { $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); return; } /** @var ExtensionInterface $extension */ $extension = new $className(); if ($extension instanceof ExtensionInterface) { $baseDir = $this->extFs->getDir($descriptor->getPath()); $webDir = $this->webFs->getDir($descriptor->getWebPath()); $this->add($extension, $baseDir, $webDir, $descriptor->getName())->setDescriptor($descriptor); } else { $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className])); } }
/** * Check if the extension is valid. * * @return bool */ public function isValid() { return $this->descriptor->isValid(); }