예제 #1
0
 function resolve(Request $request, Response $response)
 {
     if ($response->status() != 200) {
         return;
         // only normal response will be processed
     }
     foreach ((array) $request->meta('output') as $outputFilter) {
         // format: func([param1[,param2[,param3 ...]]])
         if (preg_match('/(\\w+)\\(([\\w\\s,]*)\\)/', $outputFilter, $matches)) {
             $func = @$this->funcMap[$matches[1]];
             if (is_callable($func)) {
                 if (@$matches[2]) {
                     $func = call_user_func_array($func, explode(',', $matches[2]));
                 }
                 if (is_callable($func)) {
                     try {
                         $response->send(call_user_func_array($func, array($response->body())));
                     } catch (\Exception $e) {
                         Log::error(sprintf('[InvokerPostProcessor] Error calling %s(): %s @ %s:%d', $matches[1], $e->getMessage(), basename($e->getFile()), $e->getLine()), $e->getTrace());
                         $response->send(array('error' => $e->getMessage(), 'code' => $e->getCode()), 500);
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 public function resolve(Request $request, Response $response)
 {
     // No more successful resolve should occur at this point.
     if (!$response->status()) {
         $response->status(404);
     }
     if ($response->body() || is_array($response->body())) {
         return;
     }
     // Check if docment of target status and mime type exists.
     switch ($response->header('Content-Type')) {
         case 'application/xhtml+xml':
         case 'text/html':
         default:
             $ext = 'html';
             break;
         case 'application/json':
             $ext = 'json';
             break;
         case 'application/xml':
         case 'text/xml':
             $ext = 'xml';
             break;
     }
     $basename = $this->pathPrefix() . '/' . $response->status();
     if (isset($ext) && file_exists("{$basename}.{$ext}")) {
         readfile("{$basename}.{$ext}");
     } else {
         if (file_exists("{$basename}.php")) {
             $context = array('request' => $request, 'response' => $response);
             (new IncludeRenderer($context))->render("{$basename}.php");
         } else {
             if ($ext != 'html' && file_exists("{$basename}.html")) {
                 readfile("{$basename}.html");
             }
         }
     }
 }