Skip to content

Commit

Permalink
#8647: [GitHub] Order of how arguments are merged in multiple di.xml-…
Browse files Browse the repository at this point in the history
…files causes unexpected results
  • Loading branch information
serhii-balko committed Dec 12, 2017
1 parent 3620313 commit cf7477a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,10 @@ protected function _getRendererClass()
if (!is_array($acceptTypes)) {
$acceptTypes = [$acceptTypes];
}
// If Accept type = '*/*' then return default renderer.
$defaultRenderer = isset($this->_renders['default']) ? $this->_renders['default'] : null;
foreach ($acceptTypes as $acceptType) {
if ($acceptType == '*/*' && $defaultRenderer) {
return $defaultRenderer['model'];
}
foreach ($this->_renders as $rendererConfig) {
$rendererType = $rendererConfig['type'];
if ($acceptType == $rendererType || $acceptType == current(
explode('/', $rendererType)
) . '/*' || $acceptType == '*/*'
) {
return $rendererConfig['model'];
}
$renderer = $this->getRendererConfig($acceptType);
if ($renderer !== null) {
return $renderer['model'];
}
}
/** If server does not have renderer for any of the accepted types it SHOULD send 406 (not acceptable). */
Expand All @@ -98,4 +88,30 @@ protected function _getRendererClass()
\Magento\Framework\Webapi\Exception::HTTP_NOT_ACCEPTABLE
);
}

/**
* Get renderer config by accept type.
*
* @param string $acceptType
* @return array|null
*/
private function getRendererConfig($acceptType)
{
// If Accept type = '*/*' then return default renderer.
if ($acceptType == '*/*' && isset($this->_renders['default'])) {
return $this->_renders['default'];
}

foreach ($this->_renders as $rendererConfig) {
$rendererType = $rendererConfig['type'];
if ($acceptType == $rendererType
|| $acceptType == current(explode('/', $rendererType)) . '/*'
|| $acceptType == '*/*'
) {
return $rendererConfig;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp()
'model' => \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class,
],
'default' => [
'type' => '*/*',
'type' => '*/*',
'model' => \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class
],
];
Expand Down

0 comments on commit cf7477a

Please sign in to comment.