protected function getOptions()
{
if (!is_array($this->arguments['options']) && !$this->arguments['options'] instanceof \Traversable) {
return [];
}
$options = [];
$optionsArgument = $this->arguments['options'];
foreach ($optionsArgument as $key => $value) {
if (is_object($value)) {
if (isset($this->arguments['optionValueField']) && !empty($this->arguments['optionValueField'])) {
$key = ObjectAccess::getProperty($value, $this->arguments['optionValueField']);
if (true === is_object($key)) {
if (true === method_exists($key, '__toString')) {
$key = (string) $key;
} else {
throw new Exception('Identifying value for object of class "' . get_class($value) . '" was an object.', 1247827428);
}
}
} elseif (null !== $this->persistenceManager->getBackend()->getIdentifierByObject($value)) {
$key = $this->persistenceManager->getBackend()->getIdentifierByObject($value);
} elseif (true === method_exists($value, '__toString')) {
$key = (string) $value;
} else {
throw new Exception('No identifying value for object of class "' . get_class($value) . '" found.', 1247826696);
}
if (isset($this->arguments['optionLabelField']) && !empty($this->arguments['optionLabelField'])) {
$value = ObjectAccess::getProperty($value, $this->arguments['optionLabelField']);
if (true === is_object($value)) {
if (true === method_exists($value, '__toString')) {
$value = (string) $value;
} else {
throw new Exception('Label value for object of class "' . get_class($value) . '" was an object without ' . 'a __toString() method.', 1247827553);
}
}
} elseif (true === method_exists($value, '__toString')) {
$value = (string) $value;
} elseif (null !== $this->persistenceManager->getBackend()->getIdentifierByObject($value)) {
$value = $this->persistenceManager->getBackend()->getIdentifierByObject($value);
}
}
$options[$key] = $value;
}
if (isset($this->arguments['sortByOptionLabel']) && !empty($this->arguments['sortByOptionLabel'])) {
asort($options);
}
return $options;
}