Execute the request for this resource.

@param \mod_lti\local\ltiservice\response $response  Response object for this request.
8250
public function execute($response) {
        global $CFG;

        $version = service_base::LTI_VERSION2P0;
        $params = $this->parse_template();
        $ok = $this->get_service()->check_tool_proxy($params['tool_proxy_id']);
        if (!$ok) {
            $response->set_code(404);
        } else if (optional_param('lti_version', '', PARAM_ALPHANUMEXT) != $version) {
            $response->set_code(400);
        } else {
            $toolproxy = $this->get_service()->get_tool_proxy();
            $response->set_content_type($this->formats[0]);

            $servicepath = $this->get_service()->get_service_path();
            $id = $servicepath . $this->get_path();
            $now = date('Y-m-d\TH:iO');
            $capabilityofferedarr = explode("\n", $toolproxy->capabilityoffered);
            $serviceofferedarr = explode("\n", $toolproxy->serviceoffered);
            $serviceoffered = '';
            $sep = '';
            $services = \core_component::get_plugin_list('ltiservice');
            foreach ($services as $name => $location) {
                if (in_array($name, $serviceofferedarr)) {
                    $classname = "\\ltiservice_{$name}\\local\\service\\{$name}";
                    /** @var service_base $service */
                    $service = new $classname();
                    $service->set_tool_proxy($toolproxy);
                    $resources = $service->get_resources();
                    foreach ($resources as $resource) {
                        $formats = implode("\", \"", $resource->get_formats());
                        $methods = implode("\", \"", $resource->get_methods());
                        $capabilityofferedarr = array_merge($capabilityofferedarr, $resource->get_variables());
                        $path = $servicepath . preg_replace('/\{?.*\}$/', '', $resource->get_path());
                        $serviceoffered .= <<< EOD
{$sep}
    {
      "@type":"{$resource->get_type()}",
      "@id":"tcp:{$resource->get_id()}",
      "endpoint":"{$path}",
      "format":["{$formats}"],
      "action":["{$methods}"]
    }
EOD;
                        $sep = ',';
                    }
                }
            }
            $capabilityoffered = implode("\",\n    \"", $capabilityofferedarr);
            if (strlen($capabilityoffered) > 0) {
                $capabilityoffered = "\n    \"{$capabilityoffered}\"";
            }
            $urlparts = parse_url($CFG->wwwroot);
            $orgid = $urlparts['host'];
            $name = 'Moodle';
            $code = 'moodle';
            $vendorname = 'Moodle.org';
            $vendorcode = 'mdl';
            $prodversion = strval($CFG->version);
            if (!empty($CFG->mod_lti_institution_name)) {
                $consumername = $CFG->mod_lti_institution_name;
                $consumerdesc = '';
            } else {
                $consumername = get_site()->fullname;
                $consumerdesc = strip_tags(get_site()->summary);
            }
            $profile = <<< EOD
{
  "@context":[
    "http://purl.imsglobal.org/ctx/lti/v2/ToolConsumerProfile",
    {
      "tcp":"{$id}#"
    }
  ],
  "@type":"ToolConsumerProfile",
  "@id":"{$id}",
  "lti_version":"{$version}",
  "guid":"{$toolproxy->guid}",
  "product_instance":{
    "guid":"{$orgid}",
    "product_info":{
      "product_name":{
        "default_value":"{$name}",
        "key":"product.name"
      },
      "product_version":"{$prodversion}",
      "product_family":{
        "code":"{$code}",
        "vendor":{
          "code":"{$vendorcode}",
          "vendor_name":{
            "default_value":"{$vendorname}",
            "key":"product.vendor.name"
          },
          "timestamp":"{$now}"
        }
      }
    },
    "service_owner":{
      "@id":"ServiceOwner",
      "service_owner_name":{
        "default_value":"{$consumername}",
        "key":"service_owner.name"
      },
      "description":{
        "default_value":"{$consumerdesc}",
        "key":"service_owner.description"
      }
    }
  },
  "capability_offered":[{$capabilityoffered}
  ],
  "service_offered":[{$serviceoffered}
  ]
}
EOD;
            $response->set_body($profile);

        }
    }
1133182
public function behave(Response $response)
    {
        return new Response(
            json_decode($response->content(), true),
            $response->contentType(),
            $response->error(),
            $response->errorCode(),
            $response->headerLines(),
            $response->statusCode()
        );
    }
1034392
public function respond($type = 'json', array $response = array()) {
        if ($response) {
            $response = $response + array(
                'success' => false,
                'data' => '',
                'code' => null
            );

            $this->response($response['success'], $response['data'], $response['code']);
        }

        if ($type === 'html') {
            $this->RequestHandler->renderAs($this->controller, 'ajax');

        } else {
            $this->RequestHandler->respondAs($type);
            $this->controller->autoLayout = false;
            $this->controller->autoRender = false;

            echo $this->_format($type);
        }
    }
1247287
public function execute(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            return $this->router->start($request, $response);
        } catch (\Exception $e) {
            $this->logger->warning('Unexpected exception: ' . $e->getMessage());
            $this->logger->debug($e->__toString());

            return $response->withStatus(500)
                ->withBody(new StringStream($e->getMessage()));
        }
    }
67382
public function processResponse(ResponseInterface $response)
    {
        if (!$response instanceof Response
            || !$this->getRequest()
        ) {
            return;
        }

        $response = $this->handleResponse($response);
        $this->renderResponse($response);
        $this->terminateApp();
    }
876827
public function load(Response $response) : void
    {
        $this->response = $response;
        $this->checkModule();
        if ($this->response->getStatusCode() === 200) {
            try {
                $this->loadModule();
            } catch (\Exception $exception) {
                // If an exception is thrown in the code and not caught, switch over to the error handler
                $this->response->setStatusCode(500);
                $this->loadErrorModule();
            }
        } else {
            $this->loadErrorModule();
        }
    }
1235072
public function bind($response) {
		$this->_response = $response;
		$this->_response->headers += $this->_headers;

		foreach ($this->_queue as $message) {
			$this->_write($message);
		}
	}
613434
public function run(HttpRequest $request = null, HttpResponse $response = null)
    {
        if (false === $this->booted) {
            $this->boot();
        }

        if (null === $request) {
            $request = HttpRequest::createFromGlobals();
        }

        if (null === $response) {
            $response = new HttpResponse();
        }

        // Create a copy of request, as it's by-ref passed into $this->dispatch() and gets modified.
        $cleanRequest = clone $request;
        try {
            $response = $this->dispatch($request, $response);
        } catch (ResourceNotFoundException $e) {

            if($this->symfonyKernel === null) {
                throw $e;
            }
            $response = $this->symfonyKernel->handle($cleanRequest);
        }


        $response->send();

        return $response;
    }
991517
private function processResponse(Response $response)
    {
        $response = $response->getBody()->getContents();
        $response = json_decode($response, true);

        return $response;
    }
1157045
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
910027
public function handleRequest(Request $request, Response $response) {
		if ($this->static_enable) {
			$request->uri = $request->server['request_uri'];
			$uri = $request->server['request_uri'];
			if (strpos($uri, $this->static_prefix) === 0) {
				$uri = substr($uri, strlen($this->static_prefix));
			}
			$path = realpath($this->static_dir . $uri);
			if ($path !== false && strpos($path, $this->static_dir) === 0) {
				if ($this->executeInterceptor('before', $request, $response) !== null) {
					$request->end();
					$response->end();
					unset($request, $response);
					return;
				}
				$response->mimeType(pathinfo($path, PATHINFO_EXTENSION));
				$response->sendfile($path);
				$this->executeInterceptor('after', $request, $response);
				$request->end();
				$response->end();
				unset($request, $response);
				return;
			}
		}
		$this->router->parse($request);
		if ($this->executeInterceptor('before', $request, $response) !== null) {
			$request->end();
			$response->end();
			unset($request, $response);
			return;
		}
		$this->dispatch($request, $response);
	}
218388
private function sendResponse($response)
    {
        if ($response instanceof ResponseInterface) {
            $response->sendContent();
        } else {
            echo $this->response->send($response);
        }
    }
1320686
protected function setNeededAction(Response $response) {
        if ($response->hasHtml())
        {
            $response->setNeededAction(Response::NEEDED_SHOW_HTML);
        }
        elseif ($response->isProcessing())
        {
            $response->setNeededAction(Response::NEEDED_STATUS_UPDATE);
        }
    }
211000
protected function handleResponse(Response $response)
    {
        $statusCode = $response->getStatusCode();

        switch ($statusCode) {
            case 401:
                $response = $this->processNotAuthorized();
                break;
        }

        return $response;
    }
187222
protected function respond($response)
    {
        $success = Arr::get($response, 'success');

        return $this->mapResponse($success, $response);
    }
1277323
public function execute()
    {
        $this->response = curl_exec($this->curlHandle);

        $this->checkForErrors();

        list($this->responseHeaders, $this->responseBody) = explode("\r\n\r\n", $this->response, 2);
    }
1256103
public function prepareForResponse(Response $response) {
		$this->jsonPayload = new JsonPayload($this->data);
		$this->jsonPayload->prepareForResponse($response);
	}