/** * @param $normalizedInput * @param null $resource * @param Resource $dunglasResource * @param ApiDoc $apiDoc * @param string $type * * @return array * @throws \Exception */ public function getParametersParser($normalizedInput, $resource = null, DunglasResource $dunglasResource, ApiDoc $apiDoc, $type = 'Input') { $supportedParsers = []; $parameters = []; $attributesValidationParser = []; foreach ($this->getParsers($normalizedInput) as $parser) { if ($parser->supports($normalizedInput)) { $supportedParsers[] = $parser; if ($type === 'Output' && !$parser instanceof JmsMetadataParser) { continue; } if ($parser instanceof JmsMetadataParser) { $normalizedInput['groups'] = []; $attributes = $parser->parse($normalizedInput); foreach ($attributes as $key => $value) { if ($type !== 'Input' && $key === 'id' && !empty($value)) { $parameters['id'] = $value; } if (isset($parameters[$key]) && isset($value['description'])) { $parameters[$key]['description'] = $value['description']; } } if (!is_null($resource) && $type !== 'Input') { $transformer = $this->transformerHelper->getTransformer($resource); $attributesTransformer = $parser->parse(['class' => get_class($transformer), 'groups' => []]); $attributes = array_merge($attributes, $attributesTransformer); $this->transformerHelper->getOutputAttr($resource, $parameters, 'doc', $attributes); } continue; } $attributes = $parser->parse($normalizedInput); if ($parser instanceof ValidationParser) { $attributesValidationParser = $attributes; } $parameters = $this->mergeParameters($parameters, $attributes); } } foreach ($supportedParsers as $parser) { if ($parser instanceof PostParserInterface) { $parameters = $this->mergeParameters($parameters, $parser->postParse($normalizedInput, $parameters)); } } if (!empty($attributesValidationParser)) { $this->attributesValidationParser[$dunglasResource->getShortName()] = $attributesValidationParser; } return $parameters; }
/** * @param $normalizedInput * @param $shortName * @param string $type * @return array */ public function getParametersParser($normalizedInput, $shortName, $type = 'Output') { $supportedParsers = []; $parameters = []; $transformerAttributes = []; if ($type === 'Output') { $normalizedOutput = $this->normalizeClassParameter($this->transformerHelper->getTransformerClass($shortName)); $transformerAttributes = $this->getParametersParser($normalizedOutput, $shortName, 'Transformer'); } foreach ($this->getParsers($normalizedInput) as $parser) { if ($parser->supports($normalizedInput)) { $supportedParsers[] = $parser; if ($parser instanceof JmsMetadataParser) { $normalizedInput['groups'] = []; $attributes = $parser->parse($normalizedInput); foreach ($attributes as $key => $value) { if ($key === 'id' && !empty($value)) { $parameters['id'] = $value; } if (isset($parameters[$key]) && isset($value['description'])) { $parameters[$key]['description'] = $value['description']; } } if ($type === 'Output') { $this->transformerHelper->getOutputAttr($shortName, $parameters, 'doc', $attributes, $transformerAttributes); } continue; } $attributes = $parser->parse($normalizedInput); $parameters = $this->mergeParameters($parameters, $attributes); } } if ($type === 'Output') { foreach ($supportedParsers as $parser) { if ($parser instanceof PostParserInterface) { $parameters = $this->mergeParameters($parameters, $parser->postParse($normalizedInput, $parameters)); } } } return $parameters; }