@@ -7,94 +7,94 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ContextHelper implements ProtectedContextAwareInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @Flow\InjectConfiguration(path="contentDimensions", package="Neos.ContentRepository") |
|
| 12 | - * @var array |
|
| 13 | - */ |
|
| 14 | - protected $contentDimensionsConfiguration; |
|
| 10 | + /** |
|
| 11 | + * @Flow\InjectConfiguration(path="contentDimensions", package="Neos.ContentRepository") |
|
| 12 | + * @var array |
|
| 13 | + */ |
|
| 14 | + protected $contentDimensionsConfiguration; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Returns a context array with matched dimension values per dimension for given request uri path. If nothing |
|
| 18 | - * matches, it returns a context array with default dimension values per dimension. |
|
| 19 | - * |
|
| 20 | - * @param $requestUriPath |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - public function ofRequestUriPath($requestUriPath) |
|
| 24 | - { |
|
| 25 | - // No dimensions configured, context is empty |
|
| 26 | - if (count($this->contentDimensionsConfiguration) === 0) { |
|
| 27 | - return []; |
|
| 28 | - } |
|
| 16 | + /** |
|
| 17 | + * Returns a context array with matched dimension values per dimension for given request uri path. If nothing |
|
| 18 | + * matches, it returns a context array with default dimension values per dimension. |
|
| 19 | + * |
|
| 20 | + * @param $requestUriPath |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + public function ofRequestUriPath($requestUriPath) |
|
| 24 | + { |
|
| 25 | + // No dimensions configured, context is empty |
|
| 26 | + if (count($this->contentDimensionsConfiguration) === 0) { |
|
| 27 | + return []; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $uriSegments = $this->getUriSegments($requestUriPath); |
|
| 31 | - $dimensionValues = $this->getDimensionValuesForUriSegments($uriSegments); |
|
| 32 | - if (!$dimensionValues) { |
|
| 33 | - $dimensionValues = $this->getDefaultDimensionValues(); |
|
| 34 | - } |
|
| 30 | + $uriSegments = $this->getUriSegments($requestUriPath); |
|
| 31 | + $dimensionValues = $this->getDimensionValuesForUriSegments($uriSegments); |
|
| 32 | + if (!$dimensionValues) { |
|
| 33 | + $dimensionValues = $this->getDefaultDimensionValues(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $targetDimensionValues = array_map(function ($dimensionValues) { |
|
| 37 | - return reset($dimensionValues); // Default target dimension value is first dimension value |
|
| 38 | - }, $dimensionValues); |
|
| 36 | + $targetDimensionValues = array_map(function ($dimensionValues) { |
|
| 37 | + return reset($dimensionValues); // Default target dimension value is first dimension value |
|
| 38 | + }, $dimensionValues); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - return [ |
|
| 42 | - 'dimensions' => $dimensionValues, |
|
| 43 | - 'targetDimensions' => $targetDimensionValues |
|
| 44 | - ]; |
|
| 45 | - } |
|
| 41 | + return [ |
|
| 42 | + 'dimensions' => $dimensionValues, |
|
| 43 | + 'targetDimensions' => $targetDimensionValues |
|
| 44 | + ]; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param array $uriSegments |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - protected function getDimensionValuesForUriSegments($uriSegments) |
|
| 52 | - { |
|
| 53 | - if (count($uriSegments) !== count($this->contentDimensionsConfiguration)) { |
|
| 54 | - return []; |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * @param array $uriSegments |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + protected function getDimensionValuesForUriSegments($uriSegments) |
|
| 52 | + { |
|
| 53 | + if (count($uriSegments) !== count($this->contentDimensionsConfiguration)) { |
|
| 54 | + return []; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $index = 0; |
|
| 58 | - $dimensionValues = []; |
|
| 59 | - foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
| 60 | - $uriSegment = $uriSegments[$index++]; |
|
| 61 | - foreach ($dimensionConfiguration['presets'] as $preset) { |
|
| 62 | - if ($uriSegment === $preset['uriSegment']) { |
|
| 63 | - $dimensionValues[$dimensionName] = $preset['values']; |
|
| 64 | - continue 2; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - } |
|
| 57 | + $index = 0; |
|
| 58 | + $dimensionValues = []; |
|
| 59 | + foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
| 60 | + $uriSegment = $uriSegments[$index++]; |
|
| 61 | + foreach ($dimensionConfiguration['presets'] as $preset) { |
|
| 62 | + if ($uriSegment === $preset['uriSegment']) { |
|
| 63 | + $dimensionValues[$dimensionName] = $preset['values']; |
|
| 64 | + continue 2; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - if (count($uriSegments) !== count($dimensionValues)) { |
|
| 70 | - return []; |
|
| 71 | - } |
|
| 69 | + if (count($uriSegments) !== count($dimensionValues)) { |
|
| 70 | + return []; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return $dimensionValues; |
|
| 74 | - } |
|
| 73 | + return $dimensionValues; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Returns default dimension values per dimension. |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - protected function getDefaultDimensionValues() |
|
| 82 | - { |
|
| 83 | - $dimensionValues = []; |
|
| 84 | - foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
| 85 | - $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
| 86 | - } |
|
| 87 | - return $dimensionValues; |
|
| 88 | - } |
|
| 76 | + /** |
|
| 77 | + * Returns default dimension values per dimension. |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + protected function getDefaultDimensionValues() |
|
| 82 | + { |
|
| 83 | + $dimensionValues = []; |
|
| 84 | + foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
|
| 85 | + $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
| 86 | + } |
|
| 87 | + return $dimensionValues; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - protected function getUriSegments($requestUriPath) |
|
| 91 | - { |
|
| 92 | - $pathParts = explode('/', trim($requestUriPath, '/'), 2); |
|
| 93 | - return explode('_', $pathParts[0]); |
|
| 94 | - } |
|
| 90 | + protected function getUriSegments($requestUriPath) |
|
| 91 | + { |
|
| 92 | + $pathParts = explode('/', trim($requestUriPath, '/'), 2); |
|
| 93 | + return explode('_', $pathParts[0]); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - function allowsCallOfMethod($methodName) |
|
| 97 | - { |
|
| 98 | - return true; |
|
| 99 | - } |
|
| 96 | + function allowsCallOfMethod($methodName) |
|
| 97 | + { |
|
| 98 | + return true; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $dimensionValues = $this->getDefaultDimensionValues(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $targetDimensionValues = array_map(function ($dimensionValues) { |
|
| 36 | + $targetDimensionValues = array_map(function($dimensionValues) { |
|
| 37 | 37 | return reset($dimensionValues); // Default target dimension value is first dimension value |
| 38 | 38 | }, $dimensionValues); |
| 39 | 39 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | { |
| 83 | 83 | $dimensionValues = []; |
| 84 | 84 | foreach ($this->contentDimensionsConfiguration as $dimensionName => $dimensionConfiguration) { |
| 85 | - $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
| 85 | + $dimensionValues[$dimensionName] = [$dimensionConfiguration['default']]; |
|
| 86 | 86 | } |
| 87 | 87 | return $dimensionValues; |
| 88 | 88 | } |