Injects the Terrific Composer Toolbar into the given Response.

@param Response $response A Response instance
@param array $params The parameters
19301
protected function injectToolbar(Response $response, $params)
    {
        if (function_exists('mb_stripos')) {
            $posrFunction = 'mb_strripos';
            $substrFunction = 'mb_substr';
        } else {
            $posrFunction = 'strripos';
            $substrFunction = 'substr';
        }

        $content = $response->getContent();

        if (false !== $pos = $posrFunction($content, '</body>')) {
            $toolbar = "\n".str_replace("\n", '', $this->templating->render(
                'TerrificComposerBundle:Toolbar:toolbar.html.twig', $params
            ))."\n";
            $content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos);
            $response->setContent($content);
        }
    }
1020662
public function show(string $key, array $params = [])
    {
        $path = $this->buildBuildPath(...explode('/', $key));

        return $this->get($path, $params);
    }
937722
public function execute(Request $request, Response $response, ...$params)
    {
        try {
            $className = "{$this->_controllerNs}\\{$this->_controllerName}";
            $methodName = $this->_actionName.'Action';

            $classRefl = new \ReflectionClass($className);

            $instance = $classRefl->newInstance();
            if (method_exists($instance, '__init__')) {
                $instance->__init__();
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug("exec: {$className}->__init__");
                }
            }
            if (!method_exists($instance, $methodName)) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug('the request method not exist');
                }

                throw new HttpNotFoundException('The request method not exist!');
            }

            $methodRefl = $classRefl->getMethod($methodName);
            $paramsRefl = $methodRefl->getParameters();
            $params = [];
            foreach ($paramsRefl as $index => $param) {
                $paramClass = $param->getClass();

                if ($paramClass->implementsInterface('Focus\Request\Request')) {
                    $params[$index] = $request;
                } elseif ($paramClass->implementsInterface('Focus\Response\Response')) {
                    $params[$index] = $response;
                } elseif ($paramClass->implementsInterface('Focus\Request\Session')) {
                    $params[$index] = $request->session();
                } elseif ($paramClass->implementsInterface('Focus\Config\Config')) {
                    $params[$index] = $request->config();
                } elseif ($paramClass->implementsInterface('Focus\MVC\Model')
                           || $paramClass->implementsInterface('Focus\MVC\Service')) {
                    if ($request->container()->has($paramClass->getName())) {
                        $object = $request->container()->get($paramClass->getName());
                    } else {
                        $object = $paramClass->newInstance();
                    }
                    $params[$index] = $object;
                    $params[$index]->init();
                } elseif ($paramClass->implementsInterface('Focus\MVC\View')) {
                    $params[$index] = $paramClass->newInstance();
                } else {
                    if (!empty($this->_pathParams)) {
                        $params[$index] = array_shift($this->_pathParams);
                    }
                }
            }

            $res = $instance->{$methodName}(...$params);
            if ($res instanceof View) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug('use view object for response');
                }

                $res->output($response);
            } elseif (is_string($res) || is_numeric($res)) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug('use scalar type for response');
                }

                $response->write($res);
            }

            return $res;
        } catch (\ReflectionException $exception) {
            if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                $this->getLogger()->debug(sprintf(
                    'reflection exception: [%s] %s',
                    $exception->getCode(),
                    $exception->getMessage()
                ));
            }
            throw new \RuntimeException($exception->getMessage(), $exception->getCode(), $exception);
        }
    }
819341
public function modifyResponse(Request $request, Response $response)
    {
        $app = $this->app;

        if (is_admin_panel() || $app->runningInConsole() || $this->isDebugbarRequest() || $request->ajax()) {
            return $response;
        }

        $this->injectAdminBar($response);

        return $response;
    }
1194671
public function execute($response) {
        global $DB;

        $params = $this->parse_template();
        $role = optional_param('role', '', PARAM_TEXT);
        $limitnum = optional_param('limit', 0, PARAM_INT);
        $limitfrom = optional_param('from', 0, PARAM_INT);
        $linkid = optional_param('rlid', '', PARAM_TEXT);
        $lti = null;
        $modinfo = null;

        if ($limitnum <= 0) {
            $limitfrom = 0;
        }

        try {
            if (!($course = $DB->get_record('course', array('id' => $params['context_id']), 'id', IGNORE_MISSING))) {
                throw new \Exception(null, 404);
            }
            if (!($context = \context_course::instance($course->id))) {
                throw new \Exception(null, 404);
            }
            if (!($tool = $DB->get_record('lti_types', array('id' => $params['tool_code']),
                                    'id,toolproxyid,enabledcapability,parameter', IGNORE_MISSING))) {
                throw new \Exception(null, 404);
            }
            if (!empty($linkid)) {
                if (!($lti = $DB->get_record('lti', array('id' => $linkid), 'id,course,typeid,servicesalt', IGNORE_MISSING))) {
                    throw new \Exception(null, 404);
                }
                $modinfo = get_fast_modinfo($course);
                $cm = get_coursemodule_from_instance('lti', $linkid, $lti->course, false, MUST_EXIST);
                $cm = $modinfo->get_cm($cm->id);
                $modinfo = new info_module($cm);
                if ($modinfo->is_available_for_all()) {
                    $modinfo = null;
                }
            }
            if ($tool->toolproxyid == 0) {
                if (!$this->check_type($params['tool_code'], $params['context_id'],
                        'ToolProxyBinding.memberships.url:get', null)) {
                    throw new \Exception(null, 403);
                }
            } else {
                $toolproxy = $DB->get_record('lti_tool_proxies', array('id' => $tool->toolproxyid), 'guid', IGNORE_MISSING);
                if (!$this->check_tool_proxy($toolproxy->guid, $response->get_request_data())) {
                    throw new \Exception(null, 403);
                }
            }
            $json = memberships::get_users_json($this, $context, $course->id, $tool, $role, $limitfrom, $limitnum, $lti, $modinfo);

            $response->set_content_type($this->formats[0]);
            $response->set_body($json);

        } catch (\Exception $e) {
            $response->set_code($e->getCode());
        }
    }
784391
public function renderWithExtraParams($view, array $parameters = [], Response $response = null)
    {
        if (!$this->isXmlHttpRequest()) {
            $parameters['breadcrumbs_builder'] = $this->get('sonata.admin.breadcrumbs_builder');
        }
        $parameters['admin'] = $parameters['admin'] ??
            $this->admin;

        $parameters['base_template'] = $parameters['base_template'] ??
            $this->getBaseTemplate();

        $parameters['admin_pool'] = $this->get('sonata.admin.pool');

        //NEXT_MAJOR: Remove method alias and use $this->render() directly.
        return $this->originalRender($view, $parameters, $response);
    }
129154
protected function created(Response $response, $route, array $params = [])
    {
        return $this->redirect($response, $route, $params)->withStatus(201);
    }
1120780
private function injectHeaders(ResponseInterface $response, array $headers = []): ResponseInterface
    {
        foreach ($headers as $name => $value) {
            $response = $response->withHeader($name, $value);
        }

        return $response;
    }
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);

        }
    }
657509
public function render($view, array $parameters = [], Response $response = null)
    {
        return $this->templating->renderResponse($view, $parameters, $response);
    }
1236532
protected function injectAlert(Response $response)
    {
        $content = $response->getContent();

        $pos = strripos($content, '<body>');
        if (false !== $pos) {
            $renderedContent = soda_cms_view('partials.draft-alert')->render();

            $content = substr($content, 0, $pos).$renderedContent.substr($content, $pos);

            // Update the new content and reset the content length
            $response->setContent($content);
            $response->headers->remove('Content-Length');
        }
    }
260865
public function request(string $method, ...$params) : ResponseInterface
    {
        try {
            $response = $this->client
                ->post($this->path, $this->makeJson($method, $params));

            if ($response->hasError()) {
                // throw exception on error
                throw new BadRemoteCallException($response);
            }

            return $response;
        } catch (Throwable $exception) {
            throw exception()->handle($exception);
        }
    }
836546
protected function injectToolbar(Response $response, Request $request)
	{
		$content = $response->getContent();
		$pos = strripos($content, '</body>');

		if ($pos !== false)
		{
			$this->template->assign_vars(array(
				'position' => $this->position,
				'token' => $response->headers->get('X-Debug-Token'),
				'profiler_link' => $this->helper->route('_profiler', array('token' => $response->headers->get('X-Debug-Token'))),
				'toolbar_link' => $this->helper->route('_wdt', array('token' => $response->headers->get('X-Debug-Token'), '_referer' => $this->helper->get_current_url())),
				'excluded_ajax_paths' => $this->excludedAjaxPaths,
			));

			$this->template->set_filenames(array(
				'body'	=> "@nicofuma_webprofiler/profiler/toolbar_js.html",
			));

			$toolbar = "\n" . $this->template->assign_display('body') . "\n";
			$content = substr($content, 0, $pos) . $toolbar . substr($content, $pos);
			$response->setContent($content);
		}
	}
231674
protected function buildJsonpResponse(Response $response) {
		$content     = (string)$response->getBody();
		$contentType = $response->getHeaderLine('Content-Type');

		if (strpos($contentType, 'application/json') === false) {
			$content = '"' . $content . '"';
		}

		$callback = "{$this->callbackName}({$content});";

		$newResponse = new Response(200);
		$newResponse->getBody()->write($callback);

		return $newResponse->withHeader('Content-Type', 'application/javascript');
	}
248870
public function parseResponse(Response $response, array $params)
    {
        $method = (isset($params['wt']) && 'json' == $params['wt']) ? 'json' : 'xml';
        return $response->$method();
    }
1122394
public function process(\BearFramework\App\Response $response): void
    {
        $response->content = $this->app->components->process($response->content);
    }
322673
protected function _injectDatatableScript(Response $response, Request $request)
    {
        $content  = $response->getContent();
        $pos_body = strripos($content, '</body>');
        if (!$pos_body)
        {
            return;
        }
        $session       = $request->getSession();
        $dom           = '<script id="alidatatable-scripts" type="text/javascript">';
        $pos_container = strripos($content, 'alidatatable-scripts');
        $sess_dta      = $session->get('datatable',array());
        $dta_script    = null;
        if ($sess_dta)
        {
            array_walk($sess_dta, function(&$part, &$key) {
                $part = trim(preg_replace('/\s\s+/', ' ', $part));
            });
            $dta_script = implode("\n", $sess_dta);
        }
        $session->set('datatable', array());
        if (!$pos_container)
        {
            $dta_container = $dom;
            $content       = substr_replace($content, $dta_container . '</script>', $pos_body, 0);
            $response->setContent($content);
        }
        $pos_dta = strripos($content, $dom);
        $content = substr_replace($content, $dta_script, $pos_dta + strlen($dom), 0);
        $response->setContent($content);
    }