소스 검색

refracto; content type header

develop
Robin Thoni 8 년 전
부모
커밋
b13a96e9fd
4개의 변경된 파일23개의 추가작업 그리고 71개의 파일을 삭제
  1. 12
    5
      src/Utils/Controller/LuticateApplication.php
  2. 11
    14
      src/Utils/Dbo/LuRequestDbo.php
  3. 0
    25
      src/Utils/LuHandler.php
  4. 0
    27
      src/Utils/LuOutputFormatter.php

+ 12
- 5
src/Utils/Controller/LuticateApplication.php 파일 보기

@@ -83,12 +83,8 @@ class LuticateApplication implements MessageComponentInterface
83 83
         $this->_router->setup();
84 84
     }
85 85
     
86
-    public function runHttp()
86
+    private function dispatch($httpMethod, $url, $parameters)
87 87
     {
88
-        $httpMethod = $_SERVER['REQUEST_METHOD'];
89
-        $url = $_SERVER['REQUEST_URI'];
90
-
91
-        $parameters = array_merge($_GET, $_POST);
92 88
         $r = new LuRequestDbo();
93 89
         $r->setVersion($this->getVersion());
94 90
 
@@ -109,6 +105,17 @@ class LuticateApplication implements MessageComponentInterface
109 105
             $r->setStatusCode(500);
110 106
             $r->setMessage("Internal Error");
111 107
         }
108
+        return $r;
109
+    }
110
+    
111
+    public function runHttp()
112
+    {
113
+        $httpMethod = $_SERVER['REQUEST_METHOD'];
114
+        $url = $_SERVER['REQUEST_URI'];
115
+        $parameters = array_merge($_GET, $_POST);
116
+        
117
+        $r = $this->dispatch($httpMethod, $url, $parameters);
118
+        header("content-type", "application/json");
112 119
         http_response_code($r->getStatusCode());
113 120
         echo $r->__toString();
114 121
     }

+ 11
- 14
src/Utils/Dbo/LuRequestDbo.php 파일 보기

@@ -10,19 +10,13 @@ namespace Luticate\Utils\Dbo;
10 10
 
11 11
 class LuRequestDbo extends LuDbo
12 12
 {
13
-    /**
14
-     * Specify data which should be serialized to JSON
15
-     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
16
-     * @return mixed data which can be serialized by <b>json_encode</b>,
17
-     * which is a value of any type other than a resource.
18
-     * @since 5.4.0
19
-     */
20 13
     function jsonSerialize()
21 14
     {
22 15
         return array(
23 16
             "Version" => $this->_version,
24 17
             "Data" => $this->_data,
25
-            "Message" => $this->_message
18
+            "Message" => $this->_message,
19
+            "StatusCode" => $this->_statusCode
26 20
         );
27 21
     }
28 22
 
@@ -38,19 +32,22 @@ class LuRequestDbo extends LuDbo
38 32
         if (isset($json["Message"])) {
39 33
             $dbo->setMessage($json["Message"]);
40 34
         }
35
+        if (isset($json["StatusCode"])) {
36
+            $dbo->setStatusCode($json["StatusCode"]);
37
+        }
41 38
         return $dbo;
42 39
     }
43 40
 
44 41
     private $_version;
45 42
     /**
46
-     * @return mixed
43
+     * @return float
47 44
      */
48 45
     public function getVersion()
49 46
     {
50 47
         return $this->_version;
51 48
     }
52 49
     /**
53
-     * @param mixed $version
50
+     * @param float $version
54 51
      */
55 52
     public function setVersion($version)
56 53
     {
@@ -75,14 +72,14 @@ class LuRequestDbo extends LuDbo
75 72
 
76 73
     private $_message;
77 74
     /**
78
-     * @return mixed
75
+     * @return string
79 76
      */
80 77
     public function getMessage()
81 78
     {
82 79
         return $this->_message;
83 80
     }
84 81
     /**
85
-     * @param mixed $message
82
+     * @param string $message
86 83
      */
87 84
     public function setMessage($message)
88 85
     {
@@ -92,7 +89,7 @@ class LuRequestDbo extends LuDbo
92 89
     private $_statusCode;
93 90
 
94 91
     /**
95
-     * @return mixed
92
+     * @return int
96 93
      */
97 94
     public function getStatusCode()
98 95
     {
@@ -100,7 +97,7 @@ class LuRequestDbo extends LuDbo
100 97
     }
101 98
 
102 99
     /**
103
-     * @param mixed $statusCode
100
+     * @param int $statusCode
104 101
      */
105 102
     public function setStatusCode($statusCode)
106 103
     {

+ 0
- 25
src/Utils/LuHandler.php 파일 보기

@@ -1,25 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Utils;
4
-
5
-use Exception;
6
-use Symfony\Component\HttpKernel\Exception\HttpException;
7
-use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
8
-
9
-class LuHandler extends ExceptionHandler {
10
-
11
-    public function render($request, Exception $e)
12
-    {
13
-        LuLog::log($e);
14
-        $data = "Internal error";
15
-        $code = 500;
16
-
17
-        if ($e instanceof HttpException)
18
-        {
19
-            $data = $e->getMessage();
20
-            $code = $e->getStatusCode();
21
-        }
22
-        return response(LuOutputFormatter::formatError($code, $data), $code);
23
-    }
24
-
25
-}

+ 0
- 27
src/Utils/LuOutputFormatter.php 파일 보기

@@ -1,27 +0,0 @@
1
-<?php
2
-
3
-namespace Luticate\Utils;
4
-
5
-
6
-class LuOutputFormatter
7
-{
8
-    public static $APP_VERSION = 1.0;
9
-
10
-    public static function formatSuccess($data)
11
-    {
12
-        $r = new LuRequestDbo();
13
-        $r->setVersion(self::$APP_VERSION);
14
-        $r->setData($data);
15
-        $r->setStatusCode(200);
16
-        return $r;
17
-    }
18
-
19
-    public static function formatError($code, $message)
20
-    {
21
-        $r = new LuRequestDbo();
22
-        $r->setVersion(self::$APP_VERSION);
23
-        $r->setMessage($message);
24
-        $r->setStatusCode($code);
25
-        return $r;
26
-    }
27
-}

Loading…
취소
저장