@@ -79,7 +79,7 @@ public function createDelegate($source, $dest)
79
79
} else {
80
80
$ destPath .= '/ ' . basename ($ source );
81
81
}
82
- return $ this ->create ($ source , substr ($ destPath , strlen ($ this ->getDestDir ())+ 1 ));
82
+ return $ this ->create ($ source , substr ($ destPath , strlen ($ this ->getDestDir ()) + 1 ));
83
83
}
84
84
85
85
// From now on $destPath can't be a directory, that case is already handled
@@ -94,14 +94,11 @@ public function createDelegate($source, $dest)
94
94
}
95
95
}
96
96
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 );
101
98
102
99
// 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 );
105
102
}
106
103
107
104
// Check we where able to create the symlink
@@ -112,6 +109,17 @@ public function createDelegate($source, $dest)
112
109
return true ;
113
110
}
114
111
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
+
115
123
/**
116
124
* Returns the relative path from $from to $to
117
125
*
@@ -120,13 +128,13 @@ public function createDelegate($source, $dest)
120
128
*/
121
129
public function getRelativePath ($ from , $ to )
122
130
{
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 );
126
135
127
- $ to = str_replace ( array ( ' /./ ' , ' // ' ), ' / ' , $ to );
136
+ $ from = explode ( ' / ' , $ from );
128
137
$ to = explode ('/ ' , $ to );
129
-
130
138
$ relPath = $ to ;
131
139
132
140
foreach ($ from as $ depth => $ dir ) {
0 commit comments