private function addIndex(ClassMetadataInfo $class, \SimpleXmlElement $xmlIndex)
{
$attributes = $xmlIndex->attributes();
$keys = array();
foreach ($xmlIndex->{'key'} as $key) {
$keys[(string) $key['name']] = isset($key['order']) ? (string) $key['order'] : 'asc';
}
$options = array();
if (isset($attributes['background'])) {
$options['background'] = 'true' === (string) $attributes['background'];
}
if (isset($attributes['drop-dups'])) {
$options['dropDups'] = 'true' === (string) $attributes['drop-dups'];
}
if (isset($attributes['name'])) {
$options['name'] = (string) $attributes['name'];
}
if (isset($attributes['safe'])) {
$options['safe'] = 'true' === (string) $attributes['safe'];
}
if (isset($attributes['sparse'])) {
$options['sparse'] = 'true' === (string) $attributes['sparse'];
}
if (isset($attributes['unique'])) {
$options['unique'] = 'true' === (string) $attributes['unique'];
}
if (isset($xmlIndex->{'option'})) {
foreach ($xmlIndex->{'option'} as $option) {
$value = (string) $option['value'];
if ($value === 'true') {
$value = true;
} elseif ($value === 'false') {
$value = false;
} elseif (is_numeric($value)) {
$value = preg_match('/^[-]?\\d+$/', $value) ? (int) $value : (double) $value;
}
$options[(string) $option['name']] = $value;
}
}
if (isset($xmlIndex->{'partial-filter-expression'})) {
$partialFilterExpressionMapping = $xmlIndex->{'partial-filter-expression'};
if (isset($partialFilterExpressionMapping->and)) {
foreach ($partialFilterExpressionMapping->and as $and) {
if (!isset($and->field)) {
continue;
}
$partialFilterExpression = $this->getPartialFilterExpression($and->field);
if (!$partialFilterExpression) {
continue;
}
$options['partialFilterExpression']['$and'][] = $partialFilterExpression;
}
} elseif (isset($partialFilterExpressionMapping->field)) {
$partialFilterExpression = $this->getPartialFilterExpression($partialFilterExpressionMapping->field);
if ($partialFilterExpression) {
$options['partialFilterExpression'] = $partialFilterExpression;
}
}
}
$class->addIndex($keys, $options);
}