Skip to content

Commit

Permalink
use value of DIRECTORY_SEPARATOR to detect Windows
Browse files Browse the repository at this point in the history
This commit unifies the detection of Windows builds across the Symfony
codebase.
  • Loading branch information
xabbuh committed Dec 30, 2014
1 parent 0469ea8 commit 20a427d
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 67 deletions.
Expand Up @@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));

$filesystem->rename($realCacheDir, $oldCacheDir);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
sleep(1); // workaround for Windows PHP rename bug
}
$filesystem->rename($warmupDir, $realCacheDir);
Expand Down
Expand Up @@ -30,7 +30,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c
*/
public function testRoutingErrorIsExposedWhenNotProtected($config)
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50309) {
$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');
}

Expand All @@ -46,7 +46,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
*/
public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50309) {
$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');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -812,7 +812,7 @@ protected function getTerminalHeight()
*/
public function getTerminalDimensions()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
// extract [w, H] from "wxh (WxH)"
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
return array((int) $matches[1], (int) $matches[2]);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/DialogHelper.php
Expand Up @@ -255,7 +255,7 @@ public function askConfirmation(OutputInterface $output, $question, $default = t
*/
public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$exe = __DIR__.'/../Resources/bin/hiddeninput.exe';

// handle code running from a phar
Expand Down
Expand Up @@ -99,7 +99,7 @@ public function testAskWithAutocomplete()
*/
public function testAskHiddenResponse()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test is not supported on Windows');
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -152,7 +152,7 @@ public function remove($files)
}
} else {
// https://bugs.php.net/bug.php?id=52176
if (defined('PHP_WINDOWS_VERSION_MAJOR') && is_dir($file)) {
if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) {
if (true !== @rmdir($file)) {
throw new IOException(sprintf('Failed to remove file %s', $file));
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
if (true !== @symlink($originDir, $targetDir)) {
$report = error_get_last();
if (is_array($report)) {
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) {
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
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?');
}
}
Expand All @@ -315,7 +315,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
public function makePathRelative($endPath, $startPath)
{
// Normalize separators on Windows
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$endPath = strtr($endPath, '\\', '/');
$startPath = strtr($startPath, '\\', '/');
}
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -32,7 +32,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase

public static function setUpBeforeClass()
{
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
self::$symlinkOnWindows = true;
$originDir = tempnam(sys_get_temp_dir(), 'sl');
$targetDir = tempnam(sys_get_temp_dir(), 'sl');
Expand Down Expand Up @@ -798,7 +798,7 @@ public function providePathsForMakePathRelative()
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
);

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

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

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

// skip mode check on Windows
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->assertEquals(600, $this->getFilePermissions($filename));
}
}
Expand Down Expand Up @@ -1031,21 +1031,21 @@ private function markAsSkippedIfSymlinkIsMissing()
$this->markTestSkipped('symlink is not supported');
}

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

private function markAsSkippedIfChmodIsMissing()
{
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}
}

private function markAsSkippedIfPosixIsMissing()
{
if (defined('PHP_WINDOWS_VERSION_MAJOR') || !function_exists('posix_isatty')) {
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('posix_isatty')) {
$this->markTestSkipped('POSIX is not supported');
}
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ public function accept()
{
$filename = $this->current()->getRelativePathname();

if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$filename = strtr($filename, '\\', '/');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Expand Up @@ -734,7 +734,7 @@ public function getTestPathData()
*/
public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
{
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}

Expand Down Expand Up @@ -773,7 +773,7 @@ public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
*/
public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter)
{
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}

Expand Down
Expand Up @@ -45,7 +45,7 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
*/
public static function isSupported()
{
return !defined('PHP_WINDOWS_VERSION_BUILD') && function_exists('passthru') && function_exists('escapeshellarg');
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
}

/**
Expand Down
Expand Up @@ -74,7 +74,7 @@ public function testGuessWithIncorrectPath()

public function testGuessWithNonReadablePath()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Can not verify chmod operations on Windows');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -341,7 +341,7 @@ public function doStuff()

// Heredocs are preserved, making the output mixing Unix and Windows line
// endings, switching to "\n" everywhere on Windows to avoid failure.
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$expected = str_replace("\r\n", "\n", $expected);
$output = str_replace("\r\n", "\n", $output);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Process/ExecutableFinder.php
Expand Up @@ -72,13 +72,13 @@ public function find($name, $default = null, array $extraDirs = array())
}

$suffixes = array('');
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$pathExt = getenv('PATHEXT');
$suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
}
foreach ($suffixes as $suffix) {
foreach ($dirs as $dir) {
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
return $file;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/PhpExecutableFinder.php
Expand Up @@ -60,7 +60,7 @@ public function find($includeArgs = true)
}

$dirs = array(PHP_BINDIR);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
$dirs[] = 'C:\xampp\php\\';
}

Expand Down
22 changes: 11 additions & 11 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -145,7 +145,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
// on Gnu/Linux, PHP builds with --enable-maintainer-zts are also affected
// @see : https://bugs.php.net/bug.php?id=51800
// @see : https://bugs.php.net/bug.php?id=50524
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || defined('PHP_WINDOWS_VERSION_BUILD'))) {
if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
$this->cwd = getcwd();
}
if (null !== $env) {
Expand All @@ -154,8 +154,8 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin

$this->stdin = $stdin;
$this->setTimeout($timeout);
$this->useFileHandles = defined('PHP_WINDOWS_VERSION_BUILD');
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this->isSigchildEnabled();
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
}

Expand Down Expand Up @@ -231,7 +231,7 @@ public function start($callback = null)

$commandline = $this->commandline;

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

do {
$this->checkTimeout();
$running = defined('PHP_WINDOWS_VERSION_BUILD') ? $this->isRunning() : $this->processPipes->hasOpenHandles();
$close = !defined('PHP_WINDOWS_VERSION_BUILD') || !$running;
$running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->hasOpenHandles();
$close = '\\' !== DIRECTORY_SEPARATOR || !$running;
$this->readPipes(true, $close);
} while ($running);

Expand Down Expand Up @@ -379,7 +379,7 @@ public function getOutput()
{
$this->requireProcessIsStarted(__FUNCTION__);

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

return $this->stdout;
}
Expand Down Expand Up @@ -419,7 +419,7 @@ public function getErrorOutput()
{
$this->requireProcessIsStarted(__FUNCTION__);

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

return $this->stderr;
}
Expand Down Expand Up @@ -657,7 +657,7 @@ public function stop($timeout = 10, $signal = null)
{
$timeoutMicro = microtime(true) + $timeout;
if ($this->isRunning()) {
if (defined('PHP_WINDOWS_VERSION_BUILD') && !$this->isSigchildEnabled()) {
if ('\\' === DIRECTORY_SEPARATOR && !$this->isSigchildEnabled()) {
exec(sprintf("taskkill /F /T /PID %d 2>&1", $this->getPid()), $output, $exitCode);
if ($exitCode > 0) {
throw new RuntimeException('Unable to kill the process');
Expand Down Expand Up @@ -779,7 +779,7 @@ public function setTimeout($timeout)
*/
public function setTty($tty)
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && $tty) {
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
throw new RuntimeException('TTY mode is not supported on Windows platform.');
}

Expand Down Expand Up @@ -1060,7 +1060,7 @@ protected function updateStatus($blocking)
$this->processInformation = proc_get_status($this->process);
$this->captureExitCode();

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

if (!$this->processInformation['running']) {
$this->close();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/ProcessUtils.php
Expand Up @@ -42,7 +42,7 @@ public static function escapeArgument($argument)
//Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
//@see https://bugs.php.net/bug.php?id=43784
//@see https://bugs.php.net/bug.php?id=49446
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('\\' === DIRECTORY_SEPARATOR) {
if ('' === $argument) {
return escapeshellarg($argument);
}
Expand Down

0 comments on commit 20a427d

Please sign in to comment.