Skip to content

Commit

Permalink
Move isWindows check to Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Dec 15, 2016
1 parent 8e5bdf7 commit cb70d53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 2 additions & 10 deletions system/src/Grav/Common/Filesystem/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Grav\Common\Filesystem;

use Grav\Common\Grav;
use Grav\Common\Utils;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;

abstract class Folder
Expand Down Expand Up @@ -341,7 +342,7 @@ public static function move($source, $target)
self::create(dirname($target));

// Just rename the directory.
if (self::execIsDisabled() || self::isWindows()) {
if (self::execIsDisabled() || Utils::isWindows()) {
// exec disabled, or windows. Cannot use mv. Fallback to rename() although
// not working cross volumes
$success = @rename($source, $target);
Expand All @@ -362,15 +363,6 @@ public static function move($source, $target)
@touch(dirname($target));
}

/**
* Utility method to determine if the current OS is Windows
*
* @return bool
*/
private static function isWindows() {
return strncasecmp(PHP_OS, 'WIN', 3) == 0;
}

/**
* Utility method to check if `exec` is disabled in the PHP disabled functioons
*
Expand Down
9 changes: 9 additions & 0 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,13 @@ public static function setDotNotation(&$array, $key, $value, $merge = false)

return $array;
}

/**
* Utility method to determine if the current OS is Windows
*
* @return bool
*/
public static function isWindows() {
return strncasecmp(PHP_OS, 'WIN', 3) == 0;

This comment has been minimized.

Copy link
@smz

smz Dec 16, 2016

Maybe checking the DIRECTORY_SEPARATOR, PHP_SHLIB_SUFFIX or PATH_SEPARATOR constants can be faster and possibly more "future proof".

e.g.: return DIRECTORY_SEPARATOR == '\';

See "Example #2" in http://php.net/manual/en/function.php-uname.php

This comment has been minimized.

Copy link
@flaviocopes

flaviocopes Dec 16, 2016

Author Contributor

It should be escaped

return DIRECTORY_SEPARATOR == '\\';

but I don't see a substantial difference

This comment has been minimized.

Copy link
@smz

smz Dec 16, 2016

Woops, yes, correct, it should be escaped!! 😳

}
}

0 comments on commit cb70d53

Please sign in to comment.