/** * @param $classFile * * @return string * @throws Exception */ protected function processClass($classFile) { $content = file_get_contents($classFile); $result = ''; preg_match_all('/class\\s+(\\w*)\\s*(extends\\s+)?([^{])*/s', $content, $mclass, PREG_SET_ORDER); $className = $mclass[0][1]; if (!$className) { throw new Exception(sprintf('Class not found in %s', $classFile)); } $refl = new ReflectionClass($this->baseNameSpace . '\\' . $className); $methods = $refl->getMethods(); /** @var ReflectionMethod $method */ foreach ($methods as $method) { if (strpos($method->getName(), 'Action')) { $doc = $method->getDocComment(); preg_match_all("/\\*\\s+@([a-zA-z]+)\\s*\\('([^']*)'\\)/s", $doc, $annotations); $httpMethods = []; $route = ''; foreach ($annotations[1] as $idx => $annotation) { if (strtolower($annotation) == 'route') { $route = $annotations[2][$idx]; } elseif (strtolower($annotation) == 'method') { $httpMethods[] = $annotations[2][$idx]; } } if (count($httpMethods) == 0 || empty($route)) { throw new Exception(sprintf('Method %s has invalid annotations, route or method invalid.', $method->getName())); } $result .= str_replace('\\', '\\\\', sprintf('$this->app->map(%s, "%s", "%s\\%s:%s");' . PHP_EOL, Util::shortExport($httpMethods), $route, $this->baseNameSpace, $className, $method->getName())); } } return $result; }