2 namespace Consolidation\AnnotatedCommand\Parser;
4 use Symfony\Component\Console\Input\InputOption;
5 use Consolidation\AnnotatedCommand\Parser\Internal\CommandDocBlockParser;
6 use Consolidation\AnnotatedCommand\Parser\Internal\CommandDocBlockParserFactory;
7 use Consolidation\AnnotatedCommand\AnnotationData;
10 * Serialize a CommandInfo object
12 class CommandInfoSerializer
14 public function serialize(CommandInfo $commandInfo)
16 $allAnnotations = $commandInfo->getAnnotations();
17 $path = $allAnnotations['_path'];
18 $className = $allAnnotations['_classname'];
20 // Include the minimum information for command info (including placeholder records)
22 'schema' => CommandInfo::SERIALIZATION_SCHEMA_VERSION,
23 'class' => $className,
24 'method_name' => $commandInfo->getMethodName(),
25 'mtime' => filemtime($path),
28 // If this is a valid method / hook, then add more information.
29 if ($commandInfo->valid()) {
31 'name' => $commandInfo->getName(),
32 'description' => $commandInfo->getDescription(),
33 'help' => $commandInfo->getHelp(),
34 'aliases' => $commandInfo->getAliases(),
35 'annotations' => $commandInfo->getRawAnnotations()->getArrayCopy(),
36 'example_usages' => $commandInfo->getExampleUsages(),
37 'return_type' => $commandInfo->getReturnType(),
39 $info['arguments'] = $this->serializeDefaultsWithDescriptions($commandInfo->arguments());
40 $info['options'] = $this->serializeDefaultsWithDescriptions($commandInfo->options());
46 protected function serializeDefaultsWithDescriptions(DefaultsWithDescriptions $defaults)
49 foreach ($defaults->getValues() as $key => $val) {
51 'description' => $defaults->getDescription($key),
53 if ($defaults->hasDefault($key)) {
54 $result[$key]['default'] = $val;