Merge branch 'several-inputs'

This commit is contained in:
Ilyas Salikhov 2014-11-02 12:56:20 +03:00
commit 7cb81ed07a
3 changed files with 74 additions and 17 deletions

View File

@ -44,6 +44,11 @@ class ApiDoc
*/ */
private $input = null; private $input = null;
/**
* @var string
*/
private $inputs = null;
/** /**
* @var string * @var string
*/ */
@ -165,6 +170,8 @@ class ApiDoc
if (isset($data['input'])) { if (isset($data['input'])) {
$this->input = $data['input']; $this->input = $data['input'];
} elseif (isset($data['inputs'])) {
$this->inputs = $data['inputs'];
} elseif (isset($data['filters'])) { } elseif (isset($data['filters'])) {
foreach ($data['filters'] as $filter) { foreach ($data['filters'] as $filter) {
if (!isset($filter['name'])) { if (!isset($filter['name'])) {
@ -325,6 +332,14 @@ class ApiDoc
return $this->input; return $this->input;
} }
/**
* @return array|null
*/
public function getInputs()
{
return $this->inputs;
}
/** /**
* @return string|null * @return string|null
*/ */

View File

@ -282,24 +282,32 @@ class ApiDocExtractor
$annotation->setRoute($route); $annotation->setRoute($route);
// input (populates 'parameters' for the formatters) // input (populates 'parameters' for the formatters)
if (null !== $input = $annotation->getInput()) { $inputs = array();
$parameters = array(); if (null !== $annotation->getInputs()) {
$normalizedInput = $this->normalizeClassParameter($input); $inputs = $annotation->getInputs();
} elseif (null !== $annotation->getInput()) {
$inputs[] = $annotation->getInput();
}
if (sizeof($inputs)) {
$parameters = array();
foreach ($inputs as $input) {
$normalizedInput = $this->normalizeClassParameter($input);
$supportedParsers = array(); $supportedParsers = array();
foreach ($this->getParsers($normalizedInput) as $parser) { foreach ($this->getParsers($normalizedInput) as $parser) {
if ($parser->supports($normalizedInput)) { if ($parser->supports($normalizedInput)) {
$supportedParsers[] = $parser; $supportedParsers[] = $parser;
$parameters = $this->mergeParameters($parameters, $parser->parse($normalizedInput)); $parameters = $this->mergeParameters($parameters, $parser->parse($normalizedInput));
}
} }
}
foreach ($supportedParsers as $parser) { foreach ($supportedParsers as $parser) {
if ($parser instanceof PostParserInterface) { if ($parser instanceof PostParserInterface) {
$parameters = $this->mergeParameters( $parameters = $this->mergeParameters(
$parameters, $parameters,
$parser->postParse($normalizedInput, $parameters) $parser->postParse($normalizedInput, $parameters)
); );
}
} }
} }

View File

@ -69,7 +69,31 @@ class ValidationParser implements ParserInterface, PostParserInterface
{ {
$className = $input['class']; $className = $input['class'];
return $this->doParse($className, array()); $result = $this->doParse($className, array());
if (!isset($input['name'])) {
return $result;
}
if (class_exists($className)) {
$parts = explode('\\', $className);
$dataType = sprintf('object (%s)', end($parts));
} else {
$dataType = sprintf('object (%s)', $className);
}
return array(
$input['name'] => array(
'required' => false,
'readonly' => false,
'description' => '',
'default' => null,
'dataType' => $dataType,
'actualType' => DataTypes::MODEL,
'subType' => $dataType,
'children' => $result,
),
);
} }
/** /**
@ -202,6 +226,16 @@ class ValidationParser implements ParserInterface, PostParserInterface
$vparams['format'][] = '{Time HH:MM:SS}'; $vparams['format'][] = '{Time HH:MM:SS}';
$vparams['actualType'] = DataTypes::TIME; $vparams['actualType'] = DataTypes::TIME;
break; break;
case 'Range':
$messages = array();
if (isset($constraint->min)) {
$messages[] = ">={$constraint->min}";
}
if (isset($constraint->max)) {
$messages[] = "<={$constraint->max}";
}
$vparams['format'][] = '{range: {' . join(', ', $messages) . '}}';
break;
case 'Length': case 'Length':
$messages = array(); $messages = array();
if (isset($constraint->min)) { if (isset($constraint->min)) {
@ -210,7 +244,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
if (isset($constraint->max)) { if (isset($constraint->max)) {
$messages[] = "max: {$constraint->max}"; $messages[] = "max: {$constraint->max}";
} }
$vparams['format'][] = '{length: ' . join(', ', $messages) . '}'; $vparams['format'][] = '{length: {' . join(', ', $messages) . '}}';
break; break;
case 'Choice': case 'Choice':
$choices = $this->getChoices($constraint, $className); $choices = $this->getChoices($constraint, $className);