protected function expandSubPackageAndController($paths, $controllerName, $subPackageKey = null, $bubbleControllerAndSubpackage = false)
{
if ($bubbleControllerAndSubpackage === false) {
$paths = $this->expandPatterns($paths, '@subpackage', [$subPackageKey]);
$paths = $this->expandPatterns($paths, '@controller', [$controllerName]);
return $paths;
}
$numberOfPathsBeforeSubpackageExpansion = count($paths);
$subpackageKeyParts = $subPackageKey !== null ? explode('\\', $subPackageKey) : [];
$numberOfSubpackageParts = count($subpackageKeyParts);
$subpackageReplacements = [];
for ($i = 0; $i <= $numberOfSubpackageParts; $i++) {
$subpackageReplacements[] = implode('/', $i < 0 ? $subpackageKeyParts : array_slice($subpackageKeyParts, $i));
}
$paths = $this->expandPatterns($paths, '@subpackage', $subpackageReplacements);
for ($i = ($numberOfPathsBeforeSubpackageExpansion - 1) * ($numberOfSubpackageParts + 1); $i >= 0; $i -= $numberOfSubpackageParts + 1) {
array_splice($paths, $i, 0, str_replace('@controller', $controllerName, $paths[$i]));
}
$paths = $this->expandPatterns($paths, '@controller', ['']);
return $paths;
}