ApiDocExtractor.php (1440B)
1 <?php 2 3 namespace PartKeepr\ApiDocBundle\Extractor; 4 5 use Nelmio\ApiDocBundle\Annotation\ApiDoc; 6 use Symfony\Component\Routing\Route; 7 8 class ApiDocExtractor extends \Nelmio\ApiDocBundle\Extractor\ApiDocExtractor 9 { 10 /** 11 * Parses annotations for a given method, and adds new information to the given ApiDoc 12 * annotation. Useful to extract information from the FOSRestBundle annotations. 13 * 14 * This method has been adjusted so that it can read annotations from the parent class. 15 * 16 * @param ApiDoc $annotation 17 * @param Route $route 18 * @param \ReflectionMethod $method 19 */ 20 protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method) 21 { 22 $classAnnotations = $this->reader->getMethodAnnotations($method); 23 24 $declaringClass = $method->getDeclaringClass(); 25 $parentClass = $declaringClass->getParentClass(); 26 27 $parentAnnotations = []; 28 29 if ($parentClass && $parentClass->hasMethod($method->getShortName())) { 30 $parentMethod = $parentClass->getMethod($method->getShortName()); 31 $parentAnnotations = $this->reader->getMethodAnnotations($parentMethod); 32 } 33 34 $allAnnotations = array_merge($classAnnotations, $parentAnnotations); 35 36 foreach ($this->handlers as $handler) { 37 $handler->handle($annotation, $allAnnotations, $route, $method); 38 } 39 } 40 }