comparison vendor/symfony/console/Descriptor/JsonDescriptor.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children c2387f117808
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
62 * {@inheritdoc} 62 * {@inheritdoc}
63 */ 63 */
64 protected function describeApplication(Application $application, array $options = array()) 64 protected function describeApplication(Application $application, array $options = array())
65 { 65 {
66 $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; 66 $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
67 $description = new ApplicationDescription($application, $describedNamespace); 67 $description = new ApplicationDescription($application, $describedNamespace, true);
68 $commands = array(); 68 $commands = array();
69 69
70 foreach ($description->getCommands() as $command) { 70 foreach ($description->getCommands() as $command) {
71 $commands[] = $this->getCommandData($command); 71 $commands[] = $this->getCommandData($command);
72 } 72 }
73 73
74 $data = $describedNamespace 74 $data = array();
75 ? array('commands' => $commands, 'namespace' => $describedNamespace) 75 if ('UNKNOWN' !== $application->getName()) {
76 : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces())); 76 $data['application']['name'] = $application->getName();
77 if ('UNKNOWN' !== $application->getVersion()) {
78 $data['application']['version'] = $application->getVersion();
79 }
80 }
81
82 $data['commands'] = $commands;
83
84 if ($describedNamespace) {
85 $data['namespace'] = $describedNamespace;
86 } else {
87 $data['namespaces'] = array_values($description->getNamespaces());
88 }
77 89
78 $this->writeData($data, $options); 90 $this->writeData($data, $options);
79 } 91 }
80 92
81 /** 93 /**
82 * Writes data as json. 94 * Writes data as json.
83 *
84 * @param array $data
85 * @param array $options
86 * 95 *
87 * @return array|string 96 * @return array|string
88 */ 97 */
89 private function writeData(array $data, array $options) 98 private function writeData(array $data, array $options)
90 { 99 {
91 $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0)); 100 $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
92 } 101 }
93 102
94 /** 103 /**
95 * @param InputArgument $argument
96 *
97 * @return array 104 * @return array
98 */ 105 */
99 private function getInputArgumentData(InputArgument $argument) 106 private function getInputArgumentData(InputArgument $argument)
100 { 107 {
101 return array( 108 return array(
106 'default' => INF === $argument->getDefault() ? 'INF' : $argument->getDefault(), 113 'default' => INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
107 ); 114 );
108 } 115 }
109 116
110 /** 117 /**
111 * @param InputOption $option
112 *
113 * @return array 118 * @return array
114 */ 119 */
115 private function getInputOptionData(InputOption $option) 120 private function getInputOptionData(InputOption $option)
116 { 121 {
117 return array( 122 return array(
124 'default' => INF === $option->getDefault() ? 'INF' : $option->getDefault(), 129 'default' => INF === $option->getDefault() ? 'INF' : $option->getDefault(),
125 ); 130 );
126 } 131 }
127 132
128 /** 133 /**
129 * @param InputDefinition $definition
130 *
131 * @return array 134 * @return array
132 */ 135 */
133 private function getInputDefinitionData(InputDefinition $definition) 136 private function getInputDefinitionData(InputDefinition $definition)
134 { 137 {
135 $inputArguments = array(); 138 $inputArguments = array();
144 147
145 return array('arguments' => $inputArguments, 'options' => $inputOptions); 148 return array('arguments' => $inputArguments, 'options' => $inputOptions);
146 } 149 }
147 150
148 /** 151 /**
149 * @param Command $command
150 *
151 * @return array 152 * @return array
152 */ 153 */
153 private function getCommandData(Command $command) 154 private function getCommandData(Command $command)
154 { 155 {
155 $command->getSynopsis(); 156 $command->getSynopsis();
159 'name' => $command->getName(), 160 'name' => $command->getName(),
160 'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()), 161 'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()),
161 'description' => $command->getDescription(), 162 'description' => $command->getDescription(),
162 'help' => $command->getProcessedHelp(), 163 'help' => $command->getProcessedHelp(),
163 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()), 164 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
165 'hidden' => $command->isHidden(),
164 ); 166 );
165 } 167 }
166 } 168 }