[ 'prefix' => 'f', 'required' => true, 'longPrefix' => self::OPTION_ASSEMBLY_FILE, 'description' => 'Path to the compiled assembly file.' ], self::OPTION_USE_ORIGINAL_URI => [ 'prefix' => 'uri', 'required' => true, 'flag' => true, 'longPrefix' => self::OPTION_USE_ORIGINAL_URI, 'description' => 'Use delivery URI from assembly package.', ], self::OPTION_CLASS_URI => [ 'prefix' => 'class', 'longPrefix' => self::OPTION_CLASS_URI, 'description' => 'Import into provided class.', ], ]; } /** * @return Report */ protected function run() { $this->report = Report::createInfo('Delivery assembly import started'); try { $file = $this->getOption(self::OPTION_ASSEMBLY_FILE); $importClass = $this->getImportClass(); /** @var AssemblyImporterService $importer */ $importer = $this->getServiceLocator()->get(AssemblyImporterService::class); $useOriginalUri = $this->hasOption(self::OPTION_USE_ORIGINAL_URI); $importReport = $importer->importDelivery($importClass, $file, $useOriginalUri); $this->report->add($importReport); } catch (\Exception $e) { $this->report->add(Report::createFailure("Export failed: " . $e->getMessage())); } return $this->report; } /** * @return array */ protected function provideUsage() { return [ 'prefix' => 'h', 'longPrefix' => 'help', 'description' => 'Prints a help statement' ]; } /** * @return \core_kernel_classes_Class */ private function getImportClass() { $classUri = $this->hasOption(self::OPTION_CLASS_URI) ? $this->getOption(self::OPTION_CLASS_URI) : DeliveryAssemblyService::CLASS_URI; $importClass = $this->getClass($classUri); if (!$importClass->exists()) { throw new AssemblyImportFailedException("Class with provided URI does not exist: {$importClass}"); } return $importClass; } }