@@ -79,7 +79,7 @@ public function createDelegate($source, $dest)
7979 } else {
8080 $ destPath .= '/ ' . basename ($ source );
8181 }
82- return $ this ->create ($ source , substr ($ destPath , strlen ($ this ->getDestDir ())+ 1 ));
82+ return $ this ->create ($ source , substr ($ destPath , strlen ($ this ->getDestDir ()) + 1 ));
8383 }
8484
8585 // From now on $destPath can't be a directory, that case is already handled
@@ -94,14 +94,11 @@ public function createDelegate($source, $dest)
9494 }
9595 }
9696
97- // Windows doesn't allow relative symlinks
98- if (strtoupper (substr (PHP_OS , 0 , 3 )) !== 'WIN ' ) {
99- $ sourcePath = $ this ->getRelativePath ($ destPath , $ sourcePath );
100- }
97+ $ relSourcePath = $ this ->getRelativePath ($ destPath , $ sourcePath );
10198
10299 // Create symlink
103- if (false === symlink ( $ sourcePath , $ destPath )) {
104- throw new \ErrorException ("An error occured while creating symlink " . $ sourcePath );
100+ if (false === $ this -> _symlink ( $ relSourcePath , $ destPath, $ sourcePath )) {
101+ throw new \ErrorException ("An error occured while creating symlink " . $ relSourcePath );
105102 }
106103
107104 // Check we where able to create the symlink
@@ -112,6 +109,17 @@ public function createDelegate($source, $dest)
112109 return true ;
113110 }
114111
112+ protected function _symlink ($ relSourcePath , $ destPath , $ absSourcePath )
113+ {
114+ if (strtoupper (substr (PHP_OS , 0 , 3 )) == 'WIN ' ) {
115+ $ relSourcePath = str_replace ('/ ' , '\\' , $ relSourcePath );
116+ $ param = is_dir ($ absSourcePath ) ? ' /D ' : '' ;
117+ exec ('mklink ' . $ param . ' " ' . $ destPath . '" " ' . $ relSourcePath . '" ' );
118+ } else {
119+ symlink ($ relSourcePath , $ destPath );
120+ }
121+ }
122+
115123 /**
116124 * Returns the relative path from $from to $to
117125 *
@@ -120,13 +128,13 @@ public function createDelegate($source, $dest)
120128 */
121129 public function getRelativePath ($ from , $ to )
122130 {
123- // Can't use realpath() here since the destination doesn't exist yet
124- $ from = str_replace (array ('/./ ' , '// ' ), '/ ' , $ from );
125- $ from = explode ('/ ' , $ from );
131+ $ from = is_dir ($ from ) ? rtrim ($ from , '\/ ' ) . '/ ' : $ from ;
132+ $ to = is_dir ($ to ) ? rtrim ($ to , '\/ ' ) . '/ ' : $ to ;
133+ $ from = str_replace ('\\' , '/ ' , $ from );
134+ $ to = str_replace ('\\' , '/ ' , $ to );
126135
127- $ to = str_replace ( array ( ' /./ ' , ' // ' ), ' / ' , $ to );
136+ $ from = explode ( ' / ' , $ from );
128137 $ to = explode ('/ ' , $ to );
129-
130138 $ relPath = $ to ;
131139
132140 foreach ($ from as $ depth => $ dir ) {
0 commit comments