search rendering method in function of request accept header
@param array $accept
@return ResponseAbstract
482407
protected function chooseRenderer(array $accept) {
        $renderClass = 'none';
        foreach ($accept as $mimeType) {

            switch (trim(strtolower($mimeType))) {
                case 'text/html' : 
                case 'application/xhtml+xml':
                case '*/*':
                    $renderClass = 'html';
                    break 2;
                case 'application/json' :
                case 'text/json' : 
                    $renderClass = 'json';
                    break 2;
            }
            
        }

        if(tao_helpers_Request::isAjax()) {
            $renderClass = 'ajax';
        }

        $className = __NAMESPACE__ . '\\' . $this->rendererClassList[$renderClass];
        
        $renderer = new $className();
        
        return $renderer->setServiceLocator($this->getServiceLocator());
    }
84597
public function getBest($header, array $priorities, $strict = false)
    {
        if (empty($priorities)) {
            throw new InvalidArgument('A set of server priorities should be given.');
        }

        if (!$header) {
            throw new InvalidArgument('The header string should not be empty.');
        }

        // Once upon a time, two `array_map` calls were sitting there, but for
        // some reasons, they triggered `E_WARNING` time to time (because of
        // PHP bug [55416](https://bugs.php.net/bug.php?id=55416). Now, they
        // are gone.
        // See: https://github.com/willdurand/Negotiation/issues/81
        $acceptedHeaders = array();
        foreach ($this->parseHeader($header) as $h) {
            try {
                $acceptedHeaders[] = $this->acceptFactory($h);
            } catch (Exception\Exception $e) {
                if ($strict) {
                    throw $e;
                }
            }
        }
        $acceptedPriorities = array();
        foreach ($priorities as $p) {
            $acceptedPriorities[] = $this->acceptFactory($p);
        }
        $matches         = $this->findMatches($acceptedHeaders, $acceptedPriorities);
        $specificMatches = array_reduce($matches, 'Negotiation\Match::reduce', []);

        usort($specificMatches, 'Negotiation\Match::compare');

        $match = array_shift($specificMatches);

        return null === $match ? null : $acceptedPriorities[$match->index];
    }
1013141
public function accepted() {
        $this->check_role = 'accepted';
        $result = in_array($this->value, ['1', 'on', 'yes']);
        $this->checkResult($result);
        return $this;
    }
1153300
def select_header_accept(accepts)
      return nil if accepts.nil? || accepts.empty?
      # use JSON when present, otherwise use all of the provided
      json_accept = accepts.find { |s| json_mime?(s) }
      json_accept || accepts.join(',')
    end
960195
public function searchBarAction(Request $request)
    {
        $this->denyAccessIfProfilerDisabled();

        if (null !== $this->cspHandler) {
            $this->cspHandler->disableCsp();
        }

        if (!$request->hasSession()) {
            $ip =
            $method =
            $statusCode =
            $url =
            $start =
            $end =
            $limit =
            $token = null;
        } else {
            $session = $request->getSession();

            $ip = $request->query->get('ip', $session->get('_profiler_search_ip'));
            $method = $request->query->get('method', $session->get('_profiler_search_method'));
            $statusCode = $request->query->get('status_code', $session->get('_profiler_search_status_code'));
            $url = $request->query->get('url', $session->get('_profiler_search_url'));
            $start = $request->query->get('start', $session->get('_profiler_search_start'));
            $end = $request->query->get('end', $session->get('_profiler_search_end'));
            $limit = $request->query->get('limit', $session->get('_profiler_search_limit'));
            $token = $request->query->get('token', $session->get('_profiler_search_token'));
        }

        return new Response(
            $this->twig->render('@WebProfiler/Profiler/search.html.twig', [
                'token' => $token,
                'ip' => $ip,
                'method' => $method,
                'status_code' => $statusCode,
                'url' => $url,
                'start' => $start,
                'end' => $end,
                'limit' => $limit,
                'request' => $request,
            ]),
            200,
            ['Content-Type' => 'text/html']
        );
    }
590941
protected function mime_in_header($mime, $accept_header)
	{
		// make sure we have input
		if (empty($mime) or empty($accept_header))
		{
			// no header or no mime to check
			return true;
		}

		// process the accept header and get a list of accepted mimes
		$accept_mimes = array();
		$accept_header = explode(',', $accept_header);
		foreach ($accept_header as $accept_def)
		{
			$accept_def = explode(';', $accept_def);
			$accept_def = trim($accept_def[0]);
			if ( ! in_array($accept_def, $accept_mimes))
			{
				$accept_mimes[] = $accept_def;
			}
		}

		// match on generic mime type
		if (in_array('*/*', $accept_mimes))
		{
			return true;
		}

		// match on full mime type
		if (in_array($mime, $accept_mimes))
		{
			return true;
		}

		// match on generic mime type
		$mime = substr($mime, 0, strpos($mime, '/')).'/*';
		if (in_array($mime, $accept_mimes))
		{
			return true;
		}

		// no match
		return false;
	}
1119169
protected function parseRequestAccept($accept)
    {
        $result = [];
        $rxMediaType = $this->getTypeSubtypeRegularExpression();
        $rxParameterAndValue = $this->getParameterAndValueRegularExpression();
        $matches = null;
        for (; ;) {
            if ($accept === '') {
                break;
            }
            // Read type/subtype
            if (!preg_match("/^({$rxMediaType})/", $accept, $matches)) {
                // Malformed: return what we read so far
                return $result;
            }
            $foundMediaType = strtolower($matches[1]);
            $result[$foundMediaType] = ['q' => 1.0];
            $accept = ltrim(substr($accept, strlen($foundMediaType)), static::OWS_CHARS);
            // Read parameters (eg "; q=1")
            while ($accept !== '' && $accept[0] === static::PARAMETER_SEPARATOR_CHAR) {
                $accept = ltrim(substr($accept, 1), static::OWS_CHARS);
                if (!preg_match("/^{$rxParameterAndValue}/", $accept, $matches)) {
                    // Malformed: return what we read so far
                    return $result;
                }
                $accept = ltrim(substr($accept, strlen($matches[0])), static::OWS_CHARS);
                switch (strtolower($matches[1])) {
                    case 'q':
                        if (is_numeric($matches[2])) {
                            $result[$foundMediaType]['q'] = min(max((float) $matches[2], 0), 1);
                        }
                        break;
                    default:
                        $result[$foundMediaType][$matches[1]] = $matches[2];
                        break;
                }
            }
            if ($accept === '') {
                break;
            }
            // Goto next type/subtype
            if ($accept[0] !== static::LIST_SEPARATOR_CHAR) {
                // Malformed: return what we read so far
                return $result;
            }
            $accept = ltrim(substr($accept, 1), static::OWS_CHARS);
        }

        return $result;
    }
722983
public function headers( array $headers )
      : Request
   {

      $this->_defaultHeaders = array_merge( $this->_defaultHeaders, $headers );

      return $this;

   }
282066
private function negotiateHeader(string $accept, AbstractNegotiator $negotiator, array $priorities)
    {
        try {
            $best = $negotiator->getBest($accept, $priorities);
        } catch (\Exception $exception) {
            return null;
        }

        if ($best) {
            return $best->getValue();
        }
    }
856983
public function accept()
    {
      $url = URIResource::Make($this->path, array($this->id));
      $data = new DataPacket(array("state" => CALL_STATES::active));
      $id = Locator::Find($this->client->post($url, $data->get()));
      $data->add("id", $id);

      return Constructor::Make($this, $data->get());
    }
905757
function accept(&$renderer)
    {
        $renderer->startForm($this);
        foreach (array_keys($this->_elements) as $key) {
            $element =& $this->_elements[$key];
            $elementName = $element->getName();
            $required    = ($this->isElementRequired($elementName) && !$element->isFrozen());
            $error       = $this->getElementError($elementName);
            $element->accept($renderer, $required, $error);
        }
        $renderer->finishForm($this);
    }
1261384
private function detectFromHeader(ServerRequestInterface $request)
    {
        $headers = call_user_func_array('array_merge', array_column($this->formats, 'mime-type'));
        $accept = $request->getHeaderLine('Accept');
        $mime = $this->negotiateHeader($accept, new Negotiator(), $headers);

        if ($mime !== null) {
            foreach ($this->formats as $format => $data) {
                if (in_array($mime, $data['mime-type'], true)) {
                    return $format;
                }
            }
        }
    }
1302393
public function getBestFormat($accept, $supported)
    {
        // Parse the accept header
        $parts = $this->parseHeader($accept);

        // Sort the array based on
        $parts = $this->sortParts($parts);

        // Loop through the array
        foreach ($parts as $part) {
            // Check if mime type is $supported
            if (in_array($part['value'], $supported)) {
                // Return the mime type
                return $part;
            }

            // Match for example image/*
            if (substr($part['value'], -2) === '/*') {
                // Get the type
                $range = substr($part['value'], 0, -2);

                // Look if type is found in $supported
                foreach ($supported as $support) {
                    if (strpos($support, $range, 0) === 0) {
                        $part['value'] = $support;
                        return $part;
                    }
                }
            }

            // Check if accepts anything
            if ($part['value'] === '*/*') {
                return $this->acceptsAnything($part['quality'], $supported);
            }
        }

        // Return null if no match is found
        return null;
    }
840032
public function getAcceptedContentTypes()
    {
        if (empty($this->acceptedContentTypes)) {
            // Values will be stored in this array
            $this->acceptedContentTypes = array();

            // Accept header is case insensitive, and whitespace isn’t important.
            $acceptHeader = strtolower(str_replace(' ', '', @$_SERVER['HTTP_ACCEPT'] ?: '*/*'));
            // Extract the content types from the header.
            $acceptHeaderItems = explode(',', $acceptHeader);
            foreach ($acceptHeaderItems as $contentType) {
                // The default quality is 1.
                $quality = 1;
                // Check whether a quality is specified.
                if (strpos($contentType, ';q=')) {
                    list($contentType, $quality) = explode(';q=', $contentType);
                }

                $this->acceptedContentTypes[$contentType] = $quality;
            }
            // Sort the content types by relevance.
            arsort($this->acceptedContentTypes);
        }

        return $this->acceptedContentTypes;
    }
666994
public function getContentType(Request $request, array $supportedContentTypes)
    {
        $acceptHeaderLine = $request->getHeaderLine('Accept');

        /** @var Accept $accept */
        $accept = $this->negotiator->getBest($acceptHeaderLine, $supportedContentTypes);
        if (null !== $accept) {
            $contentType = $accept->getValue();
            $this->logger->info(
                'error-handler: resolved content type {contentType} for accept header line {acceptHeaderLine}',
                ['contentType' => $contentType, 'acceptHeaderLine' => $acceptHeaderLine]
            );

            return $contentType;
        }

        $this->logger->warning(
            'error-handler: could not resolve content type for accept header line {acceptHeaderLine}',
            ['acceptHeaderLine' => $acceptHeaderLine]
        );

        return null;
    }
1331561
public static function findMatches(array $accepted, array $available = []) {
		$matches = [];
		if (!$available) {
			$available = static::parseLanguageList();
		}
		foreach ($accepted as $acceptedValue) {
			foreach ($available as $availableQuality => $availableValues) {
				$availableQuality = (float)$availableQuality;
				if ($availableQuality === 0.0) {
					continue;
				}

				foreach ($availableValues as $availableValue) {
					$matchingGrade = static::_matchLanguage($acceptedValue, $availableValue);
					if ($matchingGrade > 0) {
						$q = (string)($availableQuality * $matchingGrade);
						if ($q === '1') {
							$q = '1.0';
						}
						if (!isset($matches[$q])) {
							$matches[$q] = [];
						}
						if (!in_array($availableValue, $matches[$q])) {
							$matches[$q][] = $availableValue;
						}
					}
				}
			}
		}
		krsort($matches);
		return $matches;
	}
125664
public function shouldMakeApiResponse()
    {
        $accept   = request()->header('Accept');
        $accepted = implode('.', [env('API_STANDARDS_TREE'), env('API_SUBTYPE')]);
        return request()->wantsJson() && extension_active('api') && str_contains($accept, $accepted) && class_exists('\Antares\Modules\Api\Http\Router\Adapter');
    }