Skip to content

Commit

Permalink
EZP-29234: As a developer, I want to read about customizing REST API …
Browse files Browse the repository at this point in the history
…response
  • Loading branch information
konradoboza committed Sep 4, 2018
1 parent 87c7b3d commit e179b73
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 3 additions & 2 deletions eZ/Publish/Core/REST/Common/Output/Generator.php
Original file line number Diff line number Diff line change
@@ -304,12 +304,13 @@ abstract public function getMediaType($name);
*
* @param string $name
* @param string $type
* @param string $vendor
*
* @return string
*/
protected function generateMediaType($name, $type)
protected function generateMediaType($name, $type, $vendor = 'vnd.ez.api')
{
return "application/vnd.ez.api.{$name}+{$type}";
return "application/{$vendor}.{$name}+{$type}";
}

/**
13 changes: 11 additions & 2 deletions eZ/Publish/Core/REST/Common/Output/Generator/Json.php
Original file line number Diff line number Diff line change
@@ -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;
}

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

/**
13 changes: 11 additions & 2 deletions eZ/Publish/Core/REST/Common/Output/Generator/Xml.php
Original file line number Diff line number Diff line change
@@ -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;
}

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

/**

0 comments on commit e179b73

Please # to comment.