/** * @deprecated should be private */ public static function wordpressSymlinks(Event $event) { $composer = $event->getComposer(); $io = $event->getIO(); $extras = $composer->getPackage()->getExtra(); $web_dir = getcwd() . '/' . (empty($extras['web-dir']) ? 'htdocs' : $extras['web-dir']); $wp_dir = PackageLocator::getPackagePath($event->getComposer(), static::$wpPackage); $io->write(sprintf('Symlinking <info>%s/*</info> into <info>%s/</info>.', str_replace(getcwd() . '/', '', $wp_dir), str_replace(getcwd() . '/', '', $web_dir))); $symlink = function ($link_dir, $target_dir, $file, $target_file = null) use($io) { if (null === $target_file) { $target_file = $file; } $link = "{$link_dir}/{$file}"; $target = PathUtil::getRelativePath($link_dir, $target_dir) . ($target_file ? '/' . $target_file : ''); if (@readlink($link)) { if (readlink($link) === $target) { return; } else { unlink($link); } } if (file_exists($link)) { $io->write(sprintf('<error>Error while creating a symlink to %s: file exists</error>', str_replace(getcwd() . '/', '', $link))); } else { $io->write(sprintf('Creating symlink <info>%s</info> -> <info>%s</info>.', str_replace(getcwd() . '/', '', $link), $target)); symlink($target, $link); } }; foreach (scandir($wp_dir) as $file) { if ($file[0] == '.') { continue; } switch ($file) { case 'license.txt': case 'readme.html': case 'composer.json': case 'wp-config-sample.php': case 'wp-config.php': case 'wp-content': break; default: $symlink($web_dir, $wp_dir, $file); break; } } // Link core themes $symlink("{$web_dir}/wp-content/themes", "{$wp_dir}/wp-content/themes", "default-themes", ""); // Link our wp-config back into wordpress files $symlink($wp_dir, $web_dir, "wp-config.php"); }
public function testNonRelativePaths() { $this->assertFalse(PathUtil::getRelativePath('/sdfhjsklfjhskjdf', '/hkajsdhkajsdha')); }