@@ -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
*
@@ -121,10 +129,16 @@ public function createDelegate($source, $dest)
121
129
public function getRelativePath ($ from , $ to )
122
130
{
123
131
// Can't use realpath() here since the destination doesn't exist yet
124
- $ from = str_replace (array ('/./ ' , '// ' ), '/ ' , $ from );
125
- $ from = explode ('/ ' , $ from );
132
+ $ from = is_dir ($ from ) ? rtrim ($ from , '\/ ' ) . '/ ' : $ from ;
133
+ $ to = is_dir ($ to ) ? rtrim ($ to , '\/ ' ) . '/ ' : $ to ;
134
+
135
+ $ from = str_replace ('\\' , '/ ' , $ from );
136
+ $ to = str_replace ('\\' , '/ ' , $ to );
126
137
138
+ $ from = str_replace (array ('/./ ' , '// ' ), '/ ' , $ from );
127
139
$ to = str_replace (array ('/./ ' , '// ' ), '/ ' , $ to );
140
+
141
+ $ from = explode ('/ ' , $ from );
128
142
$ to = explode ('/ ' , $ to );
129
143
130
144
$ relPath = $ to ;
0 commit comments