コード例 #1
0
 /**
  * @covers ::getMethodsWhereRequestBodyIsAllowed()
  */
 public function testGetMethodsWhereRequestBodyIsAllowed()
 {
     $result = HttpMethods::getMethodsWhereRequestBodyIsAllowed();
     $http_methods_expected = array(HttpMethods::POST, HttpMethods::PUT);
     foreach ($http_methods_expected as $http_method_expected) {
         $this->assertContains($http_method_expected, $result, 'HTTP method ' . $http_method_expected . ' is not present in getAllMethods()');
     }
 }
コード例 #2
0
ファイル: RestServer.php プロジェクト: tekintian/RestServer-1
 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;
             }
         }
     }
 }