Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Pass options to doc generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dersam committed Dec 2, 2015
1 parent 85c3bda commit 176cf60
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/LinusShops/MagicDoc/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mapping['source']['path'],
$mapping['destination'],
isset($mapping['types']) ? $mapping['types'] : array(),
isset($mapping['parameters']) ? $mapping['parameters'] : array()
isset($mapping['parameters']) ? $mapping['parameters'] : array(),
isset($mapping['options']) ? $mapping['options']: array()
);
break;
case 'url':
Expand All @@ -78,7 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mapping['source'],
$mapping['destination'],
isset($mapping['types']) ? $mapping['types'] : array(),
isset($mapping['parameters']) ? $mapping['parameters'] : array()
isset($mapping['parameters']) ? $mapping['parameters'] : array(),
isset($mapping['options']) ? $mapping['options']: array()
);
}
}
Expand All @@ -105,23 +107,23 @@ private function processUrlMapping($source, $destination, $types = array(), $par

$this->writeDoc(
$destination,
$this->generateDoc($decoded, $types, $parameters)
$this->generateDoc($decoded, $types, $parameters, $options)
);
}

private function processFileMapping($source, $destination, $types = array(), $parameters = array())
private function processFileMapping($source, $destination, $types = array(), $parameters = array(), $options = array())
{
$json = file_get_contents($source);

$decoded = json_decode($json, true);

$this->writeDoc(
$destination,
$this->generateDoc($decoded, $types, $parameters)
$this->generateDoc($decoded, $types, $parameters, $options)
);
}

private function generateDoc($decodedJsonData, $types, $parameters)
private function generateDoc($decodedJsonData, $types, $parameters, $options = array())
{
$docblock = "";
foreach ($decodedJsonData as $key=>$value) {
Expand All @@ -135,7 +137,15 @@ private function generateDoc($decodedJsonData, $types, $parameters)
}

if (!isset($parameters[$key])) {
$params = "...\$parameters";
//Arrays are always descendable
if($type == 'array') {
$params = "...\$parameters";
}
else if (isset($options['parameter_default'])) {
$params = $options['parameter_default'];
} else {
$params = "...\$parameters";
}
} else {
$params = $parameters[$key];
}
Expand Down

0 comments on commit 176cf60

Please sign in to comment.