Skip to content

Commit f438eae

Browse files
committed
minor symfony#13147 [2.3] for consistency, use value of DIRECTORY_SEPARATOR to detect Windows (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [2.3] for consistency, use value of DIRECTORY_SEPARATOR to detect Windows | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This commit unifies the detection of Windows builds across the Symfony codebase. Commits ------- 20a427d use value of DIRECTORY_SEPARATOR to detect Windows
2 parents b5e09ee + 20a427d commit f438eae

23 files changed

+67
-67
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
8585

8686
$filesystem->rename($realCacheDir, $oldCacheDir);
87-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
87+
if ('\\' === DIRECTORY_SEPARATOR) {
8888
sleep(1); // workaround for Windows PHP rename bug
8989
}
9090
$filesystem->rename($warmupDir, $realCacheDir);

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c
3030
*/
3131
public function testRoutingErrorIsExposedWhenNotProtected($config)
3232
{
33-
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
33+
if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50309) {
3434
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
3535
}
3636

@@ -46,7 +46,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
4646
*/
4747
public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
4848
{
49-
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
49+
if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50309) {
5050
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
5151
}
5252

src/Symfony/Component/Console/Application.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ protected function getTerminalHeight()
812812
*/
813813
public function getTerminalDimensions()
814814
{
815-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
815+
if ('\\' === DIRECTORY_SEPARATOR) {
816816
// extract [w, H] from "wxh (WxH)"
817817
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
818818
return array((int) $matches[1], (int) $matches[2]);

src/Symfony/Component/Console/Helper/DialogHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function askConfirmation(OutputInterface $output, $question, $default = t
255255
*/
256256
public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
257257
{
258-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
258+
if ('\\' === DIRECTORY_SEPARATOR) {
259259
$exe = __DIR__.'/../Resources/bin/hiddeninput.exe';
260260

261261
// handle code running from a phar

src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testAskWithAutocomplete()
9999
*/
100100
public function testAskHiddenResponse()
101101
{
102-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
102+
if ('\\' === DIRECTORY_SEPARATOR) {
103103
$this->markTestSkipped('This test is not supported on Windows');
104104
}
105105

src/Symfony/Component/Filesystem/Filesystem.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function remove($files)
152152
}
153153
} else {
154154
// https://bugs.php.net/bug.php?id=52176
155-
if (defined('PHP_WINDOWS_VERSION_MAJOR') && is_dir($file)) {
155+
if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) {
156156
if (true !== @rmdir($file)) {
157157
throw new IOException(sprintf('Failed to remove file %s', $file));
158158
}
@@ -295,7 +295,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
295295
if (true !== @symlink($originDir, $targetDir)) {
296296
$report = error_get_last();
297297
if (is_array($report)) {
298-
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) {
298+
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
299299
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
300300
}
301301
}
@@ -315,7 +315,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
315315
public function makePathRelative($endPath, $startPath)
316316
{
317317
// Normalize separators on Windows
318-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
318+
if ('\\' === DIRECTORY_SEPARATOR) {
319319
$endPath = strtr($endPath, '\\', '/');
320320
$startPath = strtr($startPath, '\\', '/');
321321
}

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
3232

3333
public static function setUpBeforeClass()
3434
{
35-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
35+
if ('\\' === DIRECTORY_SEPARATOR) {
3636
self::$symlinkOnWindows = true;
3737
$originDir = tempnam(sys_get_temp_dir(), 'sl');
3838
$targetDir = tempnam(sys_get_temp_dir(), 'sl');
@@ -798,7 +798,7 @@ public function providePathsForMakePathRelative()
798798
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
799799
);
800800

801-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
801+
if ('\\' === DIRECTORY_SEPARATOR) {
802802
$paths[] = array('c:\var\lib/symfony/src/Symfony/', 'c:/var/lib/symfony/', 'src/Symfony/');
803803
}
804804

@@ -960,7 +960,7 @@ public function testDumpFile()
960960
$this->assertSame('bar', file_get_contents($filename));
961961

962962
// skip mode check on Windows
963-
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
963+
if ('\\' !== DIRECTORY_SEPARATOR) {
964964
$this->assertEquals(753, $this->getFilePermissions($filename));
965965
}
966966
}
@@ -975,7 +975,7 @@ public function testDumpFileWithNullMode()
975975
$this->assertSame('bar', file_get_contents($filename));
976976

977977
// skip mode check on Windows
978-
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
978+
if ('\\' !== DIRECTORY_SEPARATOR) {
979979
$this->assertEquals(600, $this->getFilePermissions($filename));
980980
}
981981
}
@@ -1031,21 +1031,21 @@ private function markAsSkippedIfSymlinkIsMissing()
10311031
$this->markTestSkipped('symlink is not supported');
10321032
}
10331033

1034-
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false === self::$symlinkOnWindows) {
1034+
if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) {
10351035
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
10361036
}
10371037
}
10381038

10391039
private function markAsSkippedIfChmodIsMissing()
10401040
{
1041-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
1041+
if ('\\' === DIRECTORY_SEPARATOR) {
10421042
$this->markTestSkipped('chmod is not supported on Windows');
10431043
}
10441044
}
10451045

10461046
private function markAsSkippedIfPosixIsMissing()
10471047
{
1048-
if (defined('PHP_WINDOWS_VERSION_MAJOR') || !function_exists('posix_isatty')) {
1048+
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('posix_isatty')) {
10491049
$this->markTestSkipped('POSIX is not supported');
10501050
}
10511051
}

src/Symfony/Component/Finder/Iterator/PathFilterIterator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function accept()
2828
{
2929
$filename = $this->current()->getRelativePathname();
3030

31-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
31+
if ('\\' === DIRECTORY_SEPARATOR) {
3232
$filename = strtr($filename, '\\', '/');
3333
}
3434

src/Symfony/Component/Finder/Tests/FinderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public function getTestPathData()
734734
*/
735735
public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
736736
{
737-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
737+
if ('\\' === DIRECTORY_SEPARATOR) {
738738
$this->markTestSkipped('chmod is not supported on Windows');
739739
}
740740

@@ -773,7 +773,7 @@ public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
773773
*/
774774
public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter)
775775
{
776-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
776+
if ('\\' === DIRECTORY_SEPARATOR) {
777777
$this->markTestSkipped('chmod is not supported on Windows');
778778
}
779779

src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
4545
*/
4646
public static function isSupported()
4747
{
48-
return !defined('PHP_WINDOWS_VERSION_BUILD') && function_exists('passthru') && function_exists('escapeshellarg');
48+
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
4949
}
5050

5151
/**

src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testGuessWithIncorrectPath()
7171

7272
public function testGuessWithNonReadablePath()
7373
{
74-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
74+
if ('\\' === DIRECTORY_SEPARATOR) {
7575
$this->markTestSkipped('Can not verify chmod operations on Windows');
7676
}
7777

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function doStuff()
340340

341341
// Heredocs are preserved, making the output mixing Unix and Windows line
342342
// endings, switching to "\n" everywhere on Windows to avoid failure.
343-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
343+
if ('\\' === DIRECTORY_SEPARATOR) {
344344
$expected = str_replace("\r\n", "\n", $expected);
345345
$output = str_replace("\r\n", "\n", $output);
346346
}

src/Symfony/Component/Process/ExecutableFinder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public function find($name, $default = null, array $extraDirs = array())
7272
}
7373

7474
$suffixes = array('');
75-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
75+
if ('\\' === DIRECTORY_SEPARATOR) {
7676
$pathExt = getenv('PATHEXT');
7777
$suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
7878
}
7979
foreach ($suffixes as $suffix) {
8080
foreach ($dirs as $dir) {
81-
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
81+
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
8282
return $file;
8383
}
8484
}

src/Symfony/Component/Process/PhpExecutableFinder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function find($includeArgs = true)
6060
}
6161

6262
$dirs = array(PHP_BINDIR);
63-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
63+
if ('\\' === DIRECTORY_SEPARATOR) {
6464
$dirs[] = 'C:\xampp\php\\';
6565
}
6666

src/Symfony/Component/Process/Process.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
145145
// on Gnu/Linux, PHP builds with --enable-maintainer-zts are also affected
146146
// @see : https://bugs.php.net/bug.php?id=51800
147147
// @see : https://bugs.php.net/bug.php?id=50524
148-
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || defined('PHP_WINDOWS_VERSION_BUILD'))) {
148+
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
149149
$this->cwd = getcwd();
150150
}
151151
if (null !== $env) {
@@ -154,8 +154,8 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
154154

155155
$this->stdin = $stdin;
156156
$this->setTimeout($timeout);
157-
$this->useFileHandles = defined('PHP_WINDOWS_VERSION_BUILD');
158-
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this->isSigchildEnabled();
157+
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
158+
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
159159
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
160160
}
161161

@@ -231,7 +231,7 @@ public function start($callback = null)
231231

232232
$commandline = $this->commandline;
233233

234-
if (defined('PHP_WINDOWS_VERSION_BUILD') && $this->enhanceWindowsCompatibility) {
234+
if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
235235
$commandline = 'cmd /V:ON /E:ON /C "('.$commandline.')';
236236
foreach ($this->processPipes->getFiles() as $offset => $filename) {
237237
$commandline .= ' '.$offset.'>'.ProcessUtils::escapeArgument($filename);
@@ -314,8 +314,8 @@ public function wait($callback = null)
314314

315315
do {
316316
$this->checkTimeout();
317-
$running = defined('PHP_WINDOWS_VERSION_BUILD') ? $this->isRunning() : $this->processPipes->hasOpenHandles();
318-
$close = !defined('PHP_WINDOWS_VERSION_BUILD') || !$running;
317+
$running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->hasOpenHandles();
318+
$close = '\\' !== DIRECTORY_SEPARATOR || !$running;
319319
$this->readPipes(true, $close);
320320
} while ($running);
321321

@@ -379,7 +379,7 @@ public function getOutput()
379379
{
380380
$this->requireProcessIsStarted(__FUNCTION__);
381381

382-
$this->readPipes(false, defined('PHP_WINDOWS_VERSION_BUILD') ? !$this->processInformation['running'] : true);
382+
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
383383

384384
return $this->stdout;
385385
}
@@ -419,7 +419,7 @@ public function getErrorOutput()
419419
{
420420
$this->requireProcessIsStarted(__FUNCTION__);
421421

422-
$this->readPipes(false, defined('PHP_WINDOWS_VERSION_BUILD') ? !$this->processInformation['running'] : true);
422+
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
423423

424424
return $this->stderr;
425425
}
@@ -657,7 +657,7 @@ public function stop($timeout = 10, $signal = null)
657657
{
658658
$timeoutMicro = microtime(true) + $timeout;
659659
if ($this->isRunning()) {
660-
if (defined('PHP_WINDOWS_VERSION_BUILD') && !$this->isSigchildEnabled()) {
660+
if ('\\' === DIRECTORY_SEPARATOR && !$this->isSigchildEnabled()) {
661661
exec(sprintf("taskkill /F /T /PID %d 2>&1", $this->getPid()), $output, $exitCode);
662662
if ($exitCode > 0) {
663663
throw new RuntimeException('Unable to kill the process');
@@ -779,7 +779,7 @@ public function setTimeout($timeout)
779779
*/
780780
public function setTty($tty)
781781
{
782-
if (defined('PHP_WINDOWS_VERSION_BUILD') && $tty) {
782+
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
783783
throw new RuntimeException('TTY mode is not supported on Windows platform.');
784784
}
785785

@@ -1060,7 +1060,7 @@ protected function updateStatus($blocking)
10601060
$this->processInformation = proc_get_status($this->process);
10611061
$this->captureExitCode();
10621062

1063-
$this->readPipes($blocking, defined('PHP_WINDOWS_VERSION_BUILD') ? !$this->processInformation['running'] : true);
1063+
$this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
10641064

10651065
if (!$this->processInformation['running']) {
10661066
$this->close();

src/Symfony/Component/Process/ProcessUtils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function escapeArgument($argument)
4242
//Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
4343
//@see https://bugs.php.net/bug.php?id=43784
4444
//@see https://bugs.php.net/bug.php?id=49446
45-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
45+
if ('\\' === DIRECTORY_SEPARATOR) {
4646
if ('' === $argument) {
4747
return escapeshellarg($argument);
4848
}

0 commit comments

Comments
 (0)