Skip to content

Commit e17c0b9

Browse files
authored
Merge pull request lkwdwrd#5 from johnpbloch/force-unix-separator
Add ability to force unix separators in the mu plugin loader
2 parents 54ec348 + 7fb6be8 commit e17c0b9

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/vendor
33
/phpunit.xml
44
/bootstrap.php
5+
/build

src/lkwdwrd/Composer/MULoaderPlugin.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ public function dumpRequireFile() {
134134

135135
// Find the relative path from the mu-plugins dir to the mu-loader file.
136136
$muPath = $this->resolveMURelPath( $muRelPath );
137-
$loadFile = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'mu-loader.php';
138-
$toLoader = DIRECTORY_SEPARATOR . Util\rel_path( $muPath, $loadFile );
137+
$ds = $this->getDirectorySeparator();
138+
$loadFile = dirname( __DIR__ ) . $ds . 'mu-loader.php';
139+
$toLoader = $ds . Util\rel_path( $muPath, $loadFile, $ds );
139140

140141
// Write the boostrapping PHP file.
141142
if ( !file_exists( $muPath ) ) {
@@ -194,4 +195,21 @@ protected function resolveMURelPath( $relpath ) {
194195
// Return the abosolute path.
195196
return $basepath . $relpath;
196197
}
198+
199+
/**
200+
* Get the directory separator to use for the generatoed loader
201+
*
202+
* This defaults to the DIRECTORY_SEPARATOR constant, but can be overridden in
203+
* the composer.json extra section with "force-unix-separator" set to true.
204+
*
205+
* @return string The directory separator character to use
206+
*/
207+
protected function getDirectorySeparator() {
208+
$separator = DIRECTORY_SEPARATOR;
209+
if ( ! empty( $this->extras['force-unix-separator'] ) ) {
210+
$separator = '/';
211+
}
212+
213+
return $separator;
214+
}
197215
}

tests/phpunit/list-table_Tests.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ public function test_list_table() {
4848
'lastone/lastone.php'
4949
]
5050
] );
51+
$base = WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR;
5152
WP_Mock::wpFunction( 'get_plugin_data', [
52-
'args' => ['/root/random/random.php', false ],
53+
'args' => [$base . 'random/random.php', false ],
5354
'return' => [
5455
'Name' => 'Random MU Plugin'
5556
]
5657
] );
5758
WP_Mock::wpFunction( 'get_plugin_data', [
58-
'args' => ['/root/testing/notsame.php', false],
59+
'args' => [$base . 'testing/notsame.php', false],
5960
'return' => []
6061
] );
6162
WP_Mock::wpFunction( 'get_plugin_data', [
62-
'args' => ['/root/lastone/lastone.php', false],
63+
'args' => [$base . 'lastone/lastone.php', false],
6364
'return' => [
6465
'Name' => 'The Last One',
6566
'arbitrary' => [ 1, 2, 3 ],

tests/phpunit/loader_Tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function test_get_muplugins_nocache() {
109109
// only plugins in directorys should pass: rootplugin.php will go away.
110110
// WP will include root plugins in it's normal course.
111111
WP_Mock::wpFunction( 'get_plugins', [
112-
'args' => [ '/relpath' ],
112+
'args' => [ DIRECTORY_SEPARATOR . 'relpath' ],
113113
'return' => [
114114
'random/plugin1.php' => true,
115115
'random/plugin2.php' => true,

0 commit comments

Comments
 (0)