Skip to content

Instantly share code, notes, and snippets.

@jfsimon
Created October 7, 2012 10:28
Show Gist options
  • Save jfsimon/3847794 to your computer and use it in GitHub Desktop.
Save jfsimon/3847794 to your computer and use it in GitHub Desktop.
Content negotiation
/**
* Content negotiator.
*/
interface NegotiatorInterface
{
/**
* Adds a qualifier.
*
* @param VariantQualifierInterface $qualifier
*/
function addQualifier(VariantQualifierInterface $qualifier);
/**
* Finds best variant according to request.
*
* @param VariantInterface[] $variant
* @param Request $request
*
* @return VariantInterface
*/
function findBestVariant(array $variants, Request $request);
}
/**
* A variant of one resource.
*/
interface VariantInterface
{
/**
* Returns document path.
*
* @return string
*/
function getName();
/**
* Returns document's content.
*
* @return string
*/
function getContent();
/**
* Returns base variant quality.
*
* @return float
*/
function getQuality();
/**
* Returns variant mime type.
*
* @return string
*/
function getContentType();
/**
* Returns variant charset.
*
* @return string
*/
function getCharset();
/**
* Returns variant language.
*
* @return string
*/
function getLanguage();
/**
* Returns variant encoding.
*
* @return string
*/
function getEncoding();
/**
* Returns variant features.
*
* @return array
*/
function getFeatures();
/**
* Returns variant description.
*
* @return string
*/
function getDescription();
}
/**
* Qualifies the request according to one header.
*/
interface VariantQualifierInterface
{
/**
* Returns quality factor for given variant according to given request.
*
* @param VariantInterface $variant
* @param Request $request
*
* @return float
*/
function qualify(VariantInterface $variant, Request $request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment