Example #1
0
 private function executeCallback(Request $request, Route $route, array $availableRouteCallbackParameters)
 {
     if (null !== $this->pluginRegistry) {
         $pluginResponse = $this->pluginRegistry->run($request, $route);
         if ($pluginResponse instanceof Response) {
             // received Response from plugin, return this immediately
             return $pluginResponse;
         }
         $availableRouteCallbackParameters = array_merge($availableRouteCallbackParameters, $pluginResponse);
     }
     $availableRouteCallbackParameters[get_class($request)] = $request;
     $response = $route->executeCallback($availableRouteCallbackParameters);
     if (!$response instanceof Response) {
         // if the response is a string, we assume it needs to be sent back
         // to the client as text/html
         if (!is_string($response)) {
             throw new RuntimeException('callback return value must be Response object or string');
         }
         $htmlResponse = new Response();
         $htmlResponse->setBody($response);
         return $htmlResponse;
     }
     return $response;
 }
 public function testOptionalPluginEnabledReturnObject()
 {
     $stub = $this->getMockBuilder('fkooman\\Rest\\ServicePluginInterface')->setMockClassName('Stub')->getMock();
     $stub->expects($this->any())->method('execute')->will($this->returnValue((object) array('foo' => 'bar')));
     $srv = array('SERVER_NAME' => 'www.example.org', 'SERVER_PORT' => 80, 'QUERY_STRING' => '', 'REQUEST_URI' => '/', 'SCRIPT_NAME' => '/index.php', 'REQUEST_METHOD' => 'GET');
     $request = new Request($srv);
     $route = new Route(array('GET'), '/', function () {
     }, array('Stub' => array('enabled' => true)));
     $p = new PluginRegistry();
     $p->registerOptionalPlugin($stub);
     $response = $p->run($request, $route);
     $this->assertObjectHasAttribute('foo', $response['stdClass']);
 }