setName('dependencies:add-attachment') ->setDescription('Adds an attachment to the specification of a class.') ->addArgument('coid-target', InputArgument::REQUIRED, 'The COID of the target class.') ->addArgument('filename', InputArgument::REQUIRED, 'The name of the file that should be attached.') ->addOption('upload', null, InputOption::VALUE_NONE, 'Calls "cloudobjects" to actually upload the file to CloudObjects.'); } protected function execute(InputInterface $input, OutputInterface $output) { $this->requireCloudObjectsCLI(); $this->parse($input->getArgument('coid-target')); $this->assertRDF(); $this->assertPHPExists(); $filename = $input->getArgument('filename'); if (!file_exists($filename)) throw new \Exception("File not found: ".$filename); $fileUri = "file:///".basename($filename); // Edit configuration $found = false; $object = $this->index[(string)$this->coid]; if (isset($object['coid://phpmae.dev/usesAttachedFile'])) { foreach ($object['coid://phpmae.dev/usesAttachedFile'] as $o) { if ($o['type'] != 'uri') continue; if ($o['value'] == $fileUri) $found = true; } if (!$found) $object['coid://phpmae.dev/usesAttachedFile'][] = [ 'type' => 'uri', 'value' => $fileUri ]; } else $object['coid://phpmae.dev/usesAttachedFile'] = [[ 'type' => 'uri', 'value' => $fileUri ]]; // Persist configuration if (!$found) { $this->index[(string)$this->coid] = $object; $this->updateRDFLocally($output); } if ($input->getOption('upload') !== null) { $output->writeln("Calling cloudobjects ..."); passthru("cloudobjects attachment:put ".(string)$this->coid." ".$filename); } } }