diff --git a/modules/system/composer.json b/modules/system/composer.json index ff3b30b28..63c6c06ff 100644 --- a/modules/system/composer.json +++ b/modules/system/composer.json @@ -18,7 +18,8 @@ "require": { "php": ">=5.5.9", "composer/installers": "~1.0", - "october/rain": "~1.0" + "october/rain": "~1.0", + "symfony/filesystem": "2.7.*|2.8.*" }, "autoload": { "psr-4": { diff --git a/modules/system/console/OctoberMirror.php b/modules/system/console/OctoberMirror.php index f45a952df..99bf7aa59 100644 --- a/modules/system/console/OctoberMirror.php +++ b/modules/system/console/OctoberMirror.php @@ -4,6 +4,7 @@ use File; use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Filesystem\Filesystem; /** * This command will create symbolic links to files and directories @@ -105,7 +106,10 @@ class OctoberMirror extends Command $src = base_path().'/'.$file; $dest = $this->getDestinationPath().'/'.$file; if (!File::isFile($src) || File::isFile($dest)) return false; - symlink($src, $dest); + + $normalizedSrc = $this->normalizeSourcePath($src, $dest); + + symlink($normalizedSrc, $dest); } protected function mirrorDirectory($directory) @@ -116,7 +120,10 @@ class OctoberMirror extends Command $dest = $this->getDestinationPath().'/'.$directory; if (!File::isDirectory($src) || File::isDirectory($dest)) return false; if (!File::isDirectory(dirname($dest))) File::makeDirectory(dirname($dest), 0755, true); - symlink($src, $dest); + + $normalizedSrc = $this->normalizeSourcePath($src, $dest); + + symlink($normalizedSrc, $dest); } protected function mirrorWildcard($wildcard) @@ -149,11 +156,29 @@ class OctoberMirror extends Command File::makeDirectory($destPath, 0755, true); } + $destPath = realpath($destPath); + $this->output->writeln(sprintf('Destination: %s', $destPath)); return $this->destinationPath = $destPath; } + private function normalizeSourcePath($src, $dest) + { + $relative = $this->option('relative'); + + if ($relative) { + $filesystem = new Filesystem(); + $src = $filesystem->makePathRelative($src, $dest); + + if (strpos($src, '../') === 0) { + $src = rtrim(substr($src, 3), '/'); + } + } + + return $src; + } + /** * Get the console command arguments. */ @@ -169,6 +194,8 @@ class OctoberMirror extends Command */ protected function getOptions() { - return []; + return [ + ['relative', null, InputOption::VALUE_NONE, 'Create symlinks relative to the public directory.'], + ]; } }