function CollectionConfigurator::prefix
Sets the prefix to add to the path of all child routes.
Parameters
string|array $prefix the prefix, or the localized prefixes:
Return value
$this
File
-
vendor/
symfony/ routing/ Loader/ Configurator/ CollectionConfigurator.php, line 76
Class
- CollectionConfigurator
- @author Nicolas Grekas <p@tchwork.com>
Namespace
Symfony\Component\Routing\Loader\ConfiguratorCode
public final function prefix(string|array $prefix) : static {
if (\is_array($prefix)) {
if (null === $this->parentPrefixes) {
// no-op
}
elseif ($missing = array_diff_key($this->parentPrefixes, $prefix)) {
throw new \LogicException(\sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing))));
}
else {
foreach ($prefix as $locale => $localePrefix) {
if (!isset($this->parentPrefixes[$locale])) {
throw new \LogicException(\sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale));
}
$prefix[$locale] = $this->parentPrefixes[$locale] . $localePrefix;
}
}
$this->prefixes = $prefix;
$this->route
->setPath('/');
}
else {
$this->prefixes = null;
$this->route
->setPath($prefix);
}
return $this;
}