diff --git a/src/ApplicationLinker.php b/src/ApplicationLinker.php index f835ec3..1812196 100644 --- a/src/ApplicationLinker.php +++ b/src/ApplicationLinker.php @@ -9,6 +9,7 @@ use DirectoryIterator; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; +use ReflectionMethod; class ApplicationLinker { @@ -176,16 +177,30 @@ public function run(): void continue; } $this->filesystem->ensureDirectoryExists($appWebDir . DIRECTORY_SEPARATOR . $relativePath); - $pathProxyToAutoloader = $this->filesystem->findShortestPath( - $appWebDir . DIRECTORY_SEPARATOR . $relativePathName, - $vendorDir . DIRECTORY_SEPARATOR . 'autoload.php', - preferRelative: true - ); - $pathProxyToFile = $this->filesystem->findShortestPath( - $appWebDir . DIRECTORY_SEPARATOR . $relativePathName, - $appVendorDir . DIRECTORY_SEPARATOR . $relativePathName, - preferRelative: true - ); + $reflection = new ReflectionMethod($this->filesystem, 'findShortestPath'); + if ($reflection->getNumberOfParameters() >= 4) { + $pathProxyToAutoloader = $this->filesystem->findShortestPath( + $appWebDir . DIRECTORY_SEPARATOR . $relativePathName, + $vendorDir . DIRECTORY_SEPARATOR . 'autoload.php', + preferRelative: true + ); + $pathProxyToFile = $this->filesystem->findShortestPath( + $appWebDir . DIRECTORY_SEPARATOR . $relativePathName, + $appVendorDir . DIRECTORY_SEPARATOR . $relativePathName, + preferRelative: true + ); + } else { + // Older composer versions don't support preferRelative + $pathProxyToAutoloader = $this->filesystem->findShortestPath( + $appWebDir . DIRECTORY_SEPARATOR . $relativePathName, + $vendorDir . DIRECTORY_SEPARATOR . 'autoload.php', + ); + $pathProxyToFile = $this->filesystem->findShortestPath( + $appWebDir . DIRECTORY_SEPARATOR . $relativePathName, + $appVendorDir . DIRECTORY_SEPARATOR . $relativePathName, + ); + } + $originalContent = file_get_contents($appVendorDir . DIRECTORY_SEPARATOR . $relativePathName); if (str_contains((string) $originalContent, 'vendorHordeDir; } $hordeLocalFileContent = sprintf( - "configDir ); @@ -65,6 +65,14 @@ private function processApp(string $app): void $hordeLocalFileContent .= $this->_legacyWorkaround($this->filesystem->normalizePath($this->vendorDir)); $hordeLocalFileContent .= "require_once('" . $this->vendorDir . "/autoload.php');"; } + $appNameUpper = strtoupper($name); + $hordeLocalFileContent .= sprintf( + "\nif (!defined('%s_TEMPLATES')) define('%s_TEMPLATES', '%s');\n", + $appNameUpper, + $appNameUpper, + $this->vendorDir . DIRECTORY_SEPARATOR . $vendor . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'templates', + ); + $autoloadExtraFilePath = $this->baseDir . '/var/config/autoload-extra.php'; if (file_exists($autoloadExtraFilePath)) { $hordeLocalFileContent .= "\nrequire_once('$autoloadExtraFilePath')\n"; diff --git a/src/RegistrySnippetFileWriter.php b/src/RegistrySnippetFileWriter.php index 4a5d806..faa0c0b 100644 --- a/src/RegistrySnippetFileWriter.php +++ b/src/RegistrySnippetFileWriter.php @@ -84,10 +84,12 @@ public function run(): void ' * - var/config/horde/registry-sub.domain.org.php' . PHP_EOL . ' */' . PHP_EOL; + $appInVendorDir = $this->baseDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $appVendor . DIRECTORY_SEPARATOR . $appName . DIRECTORY_SEPARATOR; if ($app == 'horde/horde') { $registryAppFilename = $this->configRegistryDir . '/01-location-' . $appName . '.php'; $registryAppSnippet .= - '$this->applications[\'horde\'][\'fileroot\'] = $app_fileroot;' . PHP_EOL . + '$this->applications[\'' . $appName . '\'][\'fileroot\'] = \'' . $appInVendorDir . '\';' . PHP_EOL . + '$this->applications[\'' . $appName . '\'][\'templates\'] = \'' . $appInVendorDir . 'templates' . DIRECTORY_SEPARATOR . '\';' . PHP_EOL . '$this->applications[\'horde\'][\'webroot\'] = $app_webroot;' . PHP_EOL . '$this->applications[\'horde\'][\'jsfs\'] = $deployment_fileroot . \'/js/horde/\';' . PHP_EOL . '$this->applications[\'horde\'][\'jsuri\'] = $deployment_webroot . \'js/horde/\';' . PHP_EOL . @@ -98,7 +100,6 @@ public function run(): void } else { // A registry snippet should ensure the install dir is known $registryAppFilename = $this->configRegistryDir . '/02-location-' . $appName . '.php'; - $appInVendorDir = $this->baseDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $appVendor . DIRECTORY_SEPARATOR . $appName . DIRECTORY_SEPARATOR; $registryAppSnippet .= '$this->applications[\'' . $appName . '\'][\'fileroot\'] = \'' . $appInVendorDir . '\';' . PHP_EOL . '$this->applications[\'' . $appName . '\'][\'templates\'] = \'' . $appInVendorDir . 'templates' . DIRECTORY_SEPARATOR . '\';' . PHP_EOL .