From 0a4e763049a62853c7d494745e8f0935f0a8dc31 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Mon, 29 Feb 2016 19:09:31 +0300 Subject: [PATCH] Pass the data about field name and field class to template --- Extractor/ApiDocExtractor.php | 29 +++++++++++++++++++++++++++++ Formatter/AbstractFormatter.php | 2 ++ 2 files changed, 31 insertions(+) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 59ef0ca..a271a66 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -311,6 +311,7 @@ class ApiDocExtractor } } + $parameters = $this->setParentClasses($parameters); $parameters = $this->clearClasses($parameters); $parameters = $this->generateHumanReadableTypes($parameters); @@ -345,6 +346,7 @@ class ApiDocExtractor } } + $response = $this->setParentClasses($response); $response = $this->clearClasses($response); $response = $this->generateHumanReadableTypes($response); @@ -381,6 +383,7 @@ class ApiDocExtractor } } + $parameters = $this->setParentClasses($parameters); $parameters = $this->clearClasses($parameters); $parameters = $this->generateHumanReadableTypes($parameters); @@ -510,6 +513,32 @@ class ApiDocExtractor } } + /** + * Set parent class to children + * + * @param array $array The source array. + * @return array The updated array. + */ + protected function setParentClasses($array) + { + if (is_array($array)) { + foreach ($array as $k => $v) { + if (isset($v['children'])) { + if (isset($v['class'])) { + foreach ($v['children'] as $key => $item) { + $array[$k]['children'][$key]['parentClass'] = $v['class']; + $array[$k]['children'][$key]['field'] = $key; + } + } + + $array[$k]['children'] = $this->setParentClasses($array[$k]['children']); + } + } + } + + return $array; + } + /** * Clears the temporary 'class' parameter from the parameters array before it is returned. * diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php index 7615cad..d239c90 100644 --- a/Formatter/AbstractFormatter.php +++ b/Formatter/AbstractFormatter.php @@ -119,6 +119,8 @@ abstract class AbstractFormatter implements FormatterInterface 'untilVersion' => array_key_exists('untilVersion', $info) ? $info['untilVersion'] : null, 'actualType' => array_key_exists('actualType', $info) ? $info['actualType'] : null, 'subType' => array_key_exists('subType', $info) ? $info['subType'] : null, + 'parentClass' => array_key_exists('parentClass', $info) ? $info['parentClass'] : null, + 'field' => array_key_exists('field', $info) ? $info['field'] : null, ); if (isset($info['children']) && (!$info['readonly'] || !$ignoreNestedReadOnly)) {