Commits

Thomas Weinert committed 79ed2a5

Allow to provide the response content object to the createResponse method

Comments (0)

Files changed (2)

example/Http/route.php

 $route->match(
   '/hello/{name}',
   function (Http\Request $request, $parameters) {
-    $response = $request->createResponse();
-    $response->content = new Http\Response\Content\String(
-      "Hello ".$parameters['name']."!\n"
+    $response = $request->createResponse(
+      new Http\Response\Content\String(
+        "Hello ".$parameters['name']."!\n"
+      )
     );
     return $response;
   }
 $route->match(
   '/agent',
   function (Http\Request $request) {
-    $response = $request->createResponse();
-    $response->content = new Http\Response\Content\String(
-      $request->headers['User-Agent']
+    $response = $request->createResponse(
+      new Http\Response\Content\String(
+        $request->headers['User-Agent']
+      )
     );
     return $response;
   }
 $route->match(
   '/xml',
   function (Http\Request $request) {
-    $response = $request->createResponse();
-    $response->content = new Http\Response\Content\Xml();
+    $response = $request->createResponse(new Http\Response\Content\Xml());
     $dom = $response->content->document;
     $dom->appendChild($root = $dom->createElement('response'));
     foreach ($request->query as $name => $value) {

src/Carica/Io/Network/Http/Request.php

     /**
      * @return Response
      */
-    public function createResponse() {
-      return new Response($this->connection());
+    public function createResponse(Response\Content $content = NULL) {
+      $response = new Response($this->connection());
+      if (isset($content)) {
+        $response->content = $content;
+      }
+      return $response;
     }
   }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.