Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function match(AcceptHeader $acceptLanguage, AcceptHeader $priority, $index)
 {
     if (!$acceptLanguage instanceof AcceptLanguage || !$priority instanceof AcceptLanguage) {
         return null;
     }
     $ab = $acceptLanguage->getBasePart();
     $pb = $priority->getBasePart();
     $as = $acceptLanguage->getSubPart();
     $ps = $priority->getSubPart();
     $baseEqual = !strcasecmp($ab, $pb);
     $subEqual = !strcasecmp($as, $ps);
     if (($ab == '*' || $baseEqual) && ($as === null || $subEqual)) {
         $score = 10 * $baseEqual + $subEqual;
         return new Match($acceptLanguage->getQuality() * $priority->getQuality(), $score, $index);
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function match(AcceptHeader $accept, AcceptHeader $priority, $index)
 {
     if (!$accept instanceof Accept || !$priority instanceof Accept) {
         return null;
     }
     $ab = $accept->getBasePart();
     $pb = $priority->getBasePart();
     $as = $accept->getSubPart();
     $ps = $priority->getSubPart();
     $intersection = array_intersect_assoc($accept->getParameters(), $priority->getParameters());
     $baseEqual = !strcasecmp($ab, $pb);
     $subEqual = !strcasecmp($as, $ps);
     if (($ab === '*' || $baseEqual) && ($as === '*' || $subEqual) && count($intersection) === count($accept->getParameters())) {
         $score = 100 * $baseEqual + 10 * $subEqual + count($intersection);
         return new Match($accept->getQuality() * $priority->getQuality(), $score, $index);
     }
     return null;
 }
Ejemplo n.º 3
0
function getOutputType()
{
    $acceptTypes = AcceptHeader::getAcceptTypes();
    $outputTypes = array('turtle', 'html', 'json');
    if (!empty($_GET['_output']) and in_array($_GET['_output'], $outputTypes)) {
        return $_GET['_output'];
    }
    $acceptTypes = AcceptHeader::getAcceptTypes();
    foreach ($acceptTypes as $mimetype) {
        switch ($mimetype) {
            case 'text/html':
            case 'application/xhtml+xml':
            case '*/*':
            case '':
                return 'html';
            case 'application/json':
            case 'application/x-rdf+json':
                return 'json';
            case 'text/turtle':
            case 'text/plain':
                return 'turtle';
        }
    }
}
Ejemplo n.º 4
0
 /**
  * Gets a list of content types acceptable by the client browser.
  *
  * @return array List of content types in preferable order
  */
 public function getAcceptableContentTypes()
 {
     if (null !== $this->acceptableContentTypes) {
         return $this->acceptableContentTypes;
     }
     return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
 }
Ejemplo n.º 5
0
                $title = 'Related: ' . local($_GET['_related']);
                $data = $store->get(null, null, $_GET['_related']);
                //$data = $store->related($_GET['_related']);
            } else {
                if (isset($_GET['_uri'])) {
                    $requestUri = $_GET['_uri'];
                } else {
                    $requestUri = (isset($Config->{$dataset}->urispace) ? $Config->{$dataset}->urispace : 'http://' . $_SERVER['SERVER_NAME']) . $_SERVER['REQUEST_URI'];
                }
                $data = $store->get($requestUri);
                if (empty($data)) {
                    header("HTTP/1.0 404 Not Found");
                }
                $page = 1;
            }
        }
    }
}
$facets = $store->getFacetsForLastQuery();
$acceptTypes = AcceptHeader::getAcceptTypes();
foreach ($acceptTypes as $mimetype) {
    switch ($mimetype) {
        case 'text/html':
        case '*/*':
            require 'template.html';
            exit;
        case 'application/json':
            echo json_encode($data);
            exit;
    }
}