/**
  * @param mixed $candidate
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 protected static function getTemplateVariableOrValueItself($candidate, RenderingContextInterface $renderingContext)
 {
     $variables = $renderingContext->getVariableProvider()->getAll();
     $extractor = new VariableExtractor();
     $suspect = $extractor->getByPath($variables, $candidate);
     if (NULL === $suspect) {
         return $candidate;
     }
     return $suspect;
 }
 /**
  * Groups the given array by the specified groupBy property.
  *
  * @param array $elements The array / traversable object to be grouped
  * @param string $groupBy Group by this property
  * @return array The grouped array in the form array('keys' => array('key1' => [key1value], 'key2' => [key2value], ...), 'values' => array('key1' => array([key1value] => [element1]), ...), ...)
  * @throws ViewHelper\Exception
  */
 protected function groupElements(array $elements, $groupBy)
 {
     $extractor = new VariableExtractor();
     $groups = array('keys' => array(), 'values' => array());
     foreach ($elements as $key => $value) {
         if (is_array($value)) {
             $currentGroupIndex = isset($value[$groupBy]) ? $value[$groupBy] : NULL;
         } elseif (is_object($value)) {
             $currentGroupIndex = $extractor->getByPath($value, $groupBy);
         } else {
             throw new ViewHelper\Exception('GroupedForViewHelper only supports multi-dimensional arrays and objects', 1253120365);
         }
         $currentGroupKeyValue = $currentGroupIndex;
         if ($currentGroupIndex instanceof \DateTime) {
             $currentGroupIndex = $currentGroupIndex->format(\DateTime::RFC850);
         } elseif (is_object($currentGroupIndex)) {
             $currentGroupIndex = spl_object_hash($currentGroupIndex);
         }
         $groups['keys'][$currentGroupIndex] = $currentGroupKeyValue;
         $groups['values'][$currentGroupIndex][$key] = $value;
     }
     return $groups;
 }