Example #1
0
 protected function generateMap($class, $basePath)
 {
     $reflection = Utilities::reflectionClassFromObjectOrClass($class);
     if (isset($reflection)) {
         $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
     } else {
         $methods = array();
     }
     /** @var ReflectionMethod $method */
     foreach ($methods as $method) {
         $doc = $method->getDocComment();
         $all_http_verbs_joined_by_pipes = implode('|', HttpMethods::getAllMethods());
         if (preg_match_all('/@url[ \\t]+(' . $all_http_verbs_joined_by_pipes . ')[ \\t]+\\/?(\\S*)/s', $doc, $matches, PREG_SET_ORDER)) {
             $params = $method->getParameters();
             foreach ($matches as $match) {
                 $httpMethod = $match[1];
                 $url = $this->root . $basePath . $match[2];
                 // quick fix for running on windows
                 $url = str_replace('\\', '/', $url);
                 if ($url && $url[0] == '/') {
                     $url = substr($url, 1);
                 }
                 // end quick fix
                 if ($url && $url[strlen($url) - 1] == '/') {
                     $url = substr($url, 0, -1);
                 }
                 $call = array($class, $method->getName());
                 $args = array();
                 foreach ($params as $param) {
                     // The order of the parameters is essential, there is no name-matching
                     // inserting the name is just for easier debuging
                     try {
                         $args[$param->getName()] = $param->getDefaultValue();
                     } catch (ReflectionException $e) {
                         // If the method has no default parameter set the value to null
                         $args[$param->getName()] = null;
                     }
                 }
                 $call[] = $args;
                 $call[] = null;
                 $call[] = DocBlockParser::getDocKeys($method);
                 $this->map[$httpMethod][$url] = $call;
             }
         }
     }
 }
 /**
  * @covers ::getDocKeys()
  */
 public function testGetDocKeysWithoutAnyKeys()
 {
     $result = DocBlockParser::getDocKeys($this->reflection_method_without_doc_keys);
     $this->assertFalse($result);
 }