/** * Read configuration data from the action controllers files using class reflector. * * @throws InvalidArgumentException * @throws LogicException * @return array */ public function getData() { if (!$this->_data && !$this->_loadDataFromCache()) { /** @var \Zend\Code\Scanner\FileScanner $file */ foreach ($this->getDirectoryScanner()->getFiles(true) as $file) { $filename = $file->getFile(); $classes = $file->getClasses(); if (count($classes) > 1) { throw new LogicException(sprintf('There can be only one class in the "%s" controller file .', $filename)); } /** @var \Zend\Code\Scanner\ClassScanner $class */ $class = current($classes); $className = $class->getName(); if (preg_match(self::RESOURCE_CLASS_PATTERN, $className)) { $classData = $this->_classReflector->reflectClassMethods($className); $this->_addData($classData); } } $postReflectionData = $this->_classReflector->getPostReflectionData(); $this->_addData($postReflectionData); if (!isset($this->_data['resources'])) { throw new LogicException('Cannot populate config - no action controllers were found.'); } $this->_saveDataToCache(); } return $this->_data; }
/** * Add REST routes to method data. * * @param Zend\Server\Reflection\ReflectionMethod $method * @return array */ public function extractMethodData(ReflectionMethod $method) { $methodData = parent::extractMethodData($method); $restRoutes = $this->_routeGenerator->generateRestRoutes($method); $methodData['rest_routes'] = array_keys($restRoutes); return $methodData; }