setName('files:object:get')
->setDescription('Get the contents of an object')
->addArgument('object', InputArgument::REQUIRED, 'Object to get')
->addArgument('output', InputArgument::REQUIRED, 'Target local file to output to, use - for STDOUT')
->addOption('bucket', 'b', InputOption::VALUE_REQUIRED, "Bucket to get the object from, only required in cases where it can't be determined from the config");
}
public function execute(InputInterface $input, OutputInterface $output): int {
$object = $input->getArgument('object');
$outputName = $input->getArgument('output');
$objectStore = $this->objectUtils->getObjectStore($input->getOption('bucket'), $output);
if (!$objectStore) {
return self::FAILURE;
}
if (!$objectStore->objectExists($object)) {
$output->writeln("Object $object does not exist");
return self::FAILURE;
}
try {
$source = $objectStore->readObject($object);
} catch (\Exception $e) {
$msg = $e->getMessage();
$output->writeln("Failed to read $object from object store: $msg");
return self::FAILURE;
}
$target = $outputName === '-' ? STDOUT : fopen($outputName, 'w');
if (!$target) {
$output->writeln("Failed to open $outputName for writing");
return self::FAILURE;
}
stream_copy_to_stream($source, $target);
return self::SUCCESS;
}
}