Ejemplo n.º 1
0
 /**
  * @param InternetMediaType $contentType
  * @return WebResource
  * @throws Exception
  */
 public function addValidContentType(InternetMediaType $contentType)
 {
     $addedMediaType = new InternetMediaType();
     $addedMediaType->setType($contentType->getType());
     $addedMediaType->setSubtype($contentType->getSubtype());
     $this->validContentTypes[$addedMediaType->getTypeSubtypeString()] = $addedMediaType;
     if ($this->hasHttpResponse() && !$this->hasValidContentType()) {
         throw new Exception('HTTP response contains invalid content type', 2);
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  *
  * @param string $internetMediaTypeString
  * @return \webignition\InternetMediaType\InternetMediaType
  */
 public function parse($internetMediaTypeString)
 {
     $inputString = trim($internetMediaTypeString);
     $internetMediaType = new InternetMediaType();
     $internetMediaType->setType($this->getTypeParser()->parse($inputString));
     $internetMediaType->setSubtype($this->getSubypeParser()->parse($inputString));
     $parameterString = $this->getParameterString($inputString, $internetMediaType->getType(), $internetMediaType->getSubtype());
     $parameterStrings = $this->getParameterStrings($parameterString);
     $parameters = $this->getParameters($parameterStrings);
     foreach ($parameters as $parameter) {
         $internetMediaType->addParameter($parameter);
     }
     return $internetMediaType;
 }