You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/Gedmo/Sluggable/Mapping/Driver/Annotation.php
+98-67Lines changed: 98 additions & 67 deletions
Original file line number
Diff line number
Diff line change
@@ -62,81 +62,112 @@ public function readExtendedMetadata($meta, array &$config)
62
62
) {
63
63
continue;
64
64
}
65
-
// slug property
66
-
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
67
-
$field = $property->getName();
68
-
if (!$meta->hasField($field)) {
69
-
thrownewInvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
70
-
}
71
-
if (!$this->isValidField($meta, $field)) {
72
-
thrownewInvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
93
+
if (!$meta->hasField($fieldName)) {
94
+
thrownewInvalidMappingException("Unable to find slug [{$fieldName}] as mapped property in entity - {$meta->name}");
95
+
}
96
+
if (!$this->isValidField($meta, $fieldName)) {
97
+
thrownewInvalidMappingException("Cannot use field - [{$fieldName}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
98
+
}
99
+
// process slug handlers
100
+
$handlers = array();
101
+
if (is_array($slug->handlers) && $slug->handlers) {
102
+
foreach ($slug->handlersas$handler) {
103
+
if (!$handlerinstanceof SlugHandler) {
104
+
thrownewInvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
96
105
}
97
-
}
98
-
// process slug fields
99
-
if (empty($slug->fields) || !is_array($slug->fields)) {
100
-
thrownewInvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
101
-
}
102
-
foreach ($slug->fieldsas$slugField) {
103
-
if (!$meta->hasField($slugField)) {
104
-
thrownewInvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
106
+
if (!strlen($handler->class)) {
107
+
thrownewInvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
105
108
}
106
-
if (!$this->isValidField($meta, $slugField)) {
107
-
thrownewInvalidMappingException("Cannot use field - [{$slugField}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
109
+
$class = $handler->class;
110
+
$handlers[$class] = array();
111
+
foreach ((array)$handler->optionsas$option) {
112
+
if (!$optioninstanceof SlugHandlerOption) {
113
+
thrownewInvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
114
+
}
115
+
if (!strlen($option->name)) {
116
+
thrownewInvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
thrownewInvalidMappingException("Unable to find slug [{$slugFieldWithPrefix}] as mapped property in entity - {$meta->name}");
121
131
}
122
-
if ($slug->unique_base && !$meta->hasField($slug->unique_base) && !$meta->hasAssociation($slug->unique_base)) {
123
-
thrownewInvalidMappingException("Unable to find [{$slug->unique_base}] as mapped property in entity - {$meta->name}");
132
+
if (!$this->isValidField($meta, $slugFieldWithPrefix)) {
133
+
thrownewInvalidMappingException("Cannot use field - [{$slugFieldWithPrefix}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
124
134
}
125
-
// set all options
126
-
$config['slugs'][$field] = array(
127
-
'fields' => $slug->fields,
128
-
'slug' => $field,
129
-
'style' => $slug->style,
130
-
'dateFormat' => $slug->dateFormat,
131
-
'updatable' => $slug->updatable,
132
-
'unique' => $slug->unique,
133
-
'unique_base' => $slug->unique_base,
134
-
'separator' => $slug->separator,
135
-
'prefix' => $slug->prefix,
136
-
'suffix' => $slug->suffix,
137
-
'handlers' => $handlers,
138
-
);
139
135
}
136
+
if (!is_bool($slug->updatable)) {
137
+
thrownewInvalidMappingException("Slug annotation [updatable], type is not valid and must be 'boolean' in class - {$meta->name}");
138
+
}
139
+
if (!is_bool($slug->unique)) {
140
+
thrownewInvalidMappingException("Slug annotation [unique], type is not valid and must be 'boolean' in class - {$meta->name}");
141
+
}
142
+
if (!empty($meta->identifier) && $meta->isIdentifier($fieldName) && !(bool)$slug->unique) {
143
+
thrownewInvalidMappingException("Identifier field - [{$fieldName}] slug must be unique in order to maintain primary key in class - {$meta->name}");
144
+
}
145
+
if ($slug->unique === false && $slug->unique_base) {
146
+
thrownewInvalidMappingException("Slug annotation [unique_base] can not be set if unique is unset or 'false'");
147
+
}
148
+
if ($slug->unique_base && !$meta->hasField($slug->unique_base) && !$meta->hasAssociation($slug->unique_base)) {
149
+
thrownewInvalidMappingException("Unable to find [{$slug->unique_base}] as mapped property in entity - {$meta->name}");
0 commit comments