Skip to content

Commit

Permalink
Merge branch '6.13' into 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Sep 20, 2018
2 parents b67b8a4 + 99dba26 commit b7dca05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
16 changes: 16 additions & 0 deletions eZ/Publish/Core/REST/Common/Output/Generator.php
Expand Up @@ -302,6 +302,8 @@ abstract public function getMediaType($name);
/**
* Generates a media type from $name and $type.
*
* @deprecated 6.13.5 please start to use generateMediaTypeWithVendor()
*
* @param string $name
* @param string $type
*
Expand All @@ -312,6 +314,20 @@ protected function generateMediaType($name, $type)
return "application/vnd.ez.api.{$name}+{$type}";
}

/**
* Generates a media type from $name, $type and $vendor.
*
* @param string $name
* @param string $type
* @param string $vendor
*
* @return string
*/
protected function generateMediaTypeWithVendor($name, $type, $vendor = 'vnd.ez.api')
{
return "application/{$vendor}.{$name}+{$type}";
}

/**
* Generates a generic representation of the scalar, hash or list given in
* $hashValue into the document, using an element of $hashElementName as
Expand Down
13 changes: 11 additions & 2 deletions eZ/Publish/Core/REST/Common/Output/Generator/Json.php
Expand Up @@ -36,12 +36,21 @@ class Json extends Generator
*/
protected $isEmpty = true;

/**
* Enables developer to modify REST response media type prefix.
*
* @var string
*/
protected $vendor;

/**
* @param \eZ\Publish\Core\REST\Common\Output\Generator\Json\FieldTypeHashGenerator $fieldTypeHashGenerator
* @param string $vendor
*/
public function __construct(Json\FieldTypeHashGenerator $fieldTypeHashGenerator)
public function __construct(Json\FieldTypeHashGenerator $fieldTypeHashGenerator, $vendor = 'vnd.ez.api')
{
$this->fieldTypeHashGenerator = $fieldTypeHashGenerator;
$this->vendor = $vendor;
}

/**
Expand Down Expand Up @@ -292,7 +301,7 @@ public function endAttribute($name)
*/
public function getMediaType($name)
{
return $this->generateMediaType($name, 'json');
return $this->generateMediaTypeWithVendor($name, 'json', $this->vendor);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions eZ/Publish/Core/REST/Common/Output/Generator/Xml.php
Expand Up @@ -36,12 +36,21 @@ class Xml extends Generator
*/
protected $isEmpty = true;

/**
* Enables developer to modify REST response media type prefix.
*
* @var string
*/
protected $vendor;

/**
* @param \eZ\Publish\Core\REST\Common\Output\Generator\Xml\FieldTypeHashGenerator $hashGenerator
* @param string $vendor
*/
public function __construct(Xml\FieldTypeHashGenerator $hashGenerator)
public function __construct(Xml\FieldTypeHashGenerator $hashGenerator, $vendor = 'vnd.ez.api')
{
$this->hashGenerator = $hashGenerator;
$this->vendor = $vendor;
}

/**
Expand Down Expand Up @@ -236,7 +245,7 @@ public function endAttribute($name)
*/
public function getMediaType($name)
{
return $this->generateMediaType($name, 'xml');
return $this->generateMediaTypeWithVendor($name, 'xml', $this->vendor);
}

/**
Expand Down

0 comments on commit b7dca05

Please sign in to comment.