Skip to content

Commit

Permalink
replace DS with DIRECTORY_SEPARATOR in filesystem sub-package
Browse files Browse the repository at this point in the history
Removes external dependency of DS being defined in standalone usage.
See: https://github.com/cakephp/filesystem/issues/1
  • Loading branch information
Schlaefer committed May 23, 2015
1 parent fa18d1e commit 8c05515
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Filesystem/File.php
Expand Up @@ -206,7 +206,7 @@ public function offset($offset = false, $seek = SEEK_SET)
public static function prepare($data, $forceWindows = false)
{
$lineBreak = "\n";
if (DS === '\\' || $forceWindows === true) {
if (DIRECTORY_SEPARATOR === '\\' || $forceWindows === true) {
$lineBreak = "\r\n";
}
return strtr($data, ["\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak]);
Expand Down
24 changes: 12 additions & 12 deletions src/Filesystem/Folder.php
Expand Up @@ -350,8 +350,8 @@ public static function slashTerm($path)
public static function addPathElement($path, $element)
{
$element = (array)$element;
array_unshift($element, rtrim($path, DS));
return implode(DS, $element);
array_unshift($element, rtrim($path, DIRECTORY_SEPARATOR));
return implode(DIRECTORY_SEPARATOR, $element);
}

/**
Expand Down Expand Up @@ -420,7 +420,7 @@ public function chmod($path, $mode = false, $recursive = true, array $exceptions

foreach ($paths as $type) {
foreach ($type as $fullpath) {
$check = explode(DS, $fullpath);
$check = explode(DIRECTORY_SEPARATOR, $fullpath);
$count = count($check);

if (in_array($check[$count - 1], $exceptions)) {
Expand Down Expand Up @@ -485,7 +485,7 @@ public function tree($path = null, $exceptions = false, $type = null)
foreach ($iterator as $itemPath => $fsIterator) {
if ($skipHidden) {
$subPathName = $fsIterator->getSubPathname();
if ($subPathName{0} === '.' || strpos($subPathName, DS . '.') !== false) {
if ($subPathName{0} === '.' || strpos($subPathName, DIRECTORY_SEPARATOR . '.') !== false) {
continue;
}
}
Expand Down Expand Up @@ -538,8 +538,8 @@ public function create($pathname, $mode = false)
$this->_errors[] = sprintf('%s is a file', $pathname);
return false;
}
$pathname = rtrim($pathname, DS);
$nextPathname = substr($pathname, 0, strrpos($pathname, DS));
$pathname = rtrim($pathname, DIRECTORY_SEPARATOR);
$nextPathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR));

if ($this->create($nextPathname, $mode)) {
if (!file_exists($pathname)) {
Expand Down Expand Up @@ -638,7 +638,7 @@ public function delete($path = null)
}
}

$path = rtrim($path, DS);
$path = rtrim($path, DIRECTORY_SEPARATOR);
//@codingStandardsIgnoreStart
if (@rmdir($path)) {
//@codingStandardsIgnoreEnd
Expand Down Expand Up @@ -829,18 +829,18 @@ public function errors($reset = true)
*/
public function realpath($path)
{
$path = str_replace('/', DS, trim($path));
$path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
if (strpos($path, '..') === false) {
if (!Folder::isAbsolute($path)) {
$path = Folder::addPathElement($this->path, $path);
}
return $path;
}
$parts = explode(DS, $path);
$parts = explode(DIRECTORY_SEPARATOR, $path);
$newparts = [];
$newpath = '';
if ($path[0] === DS) {
$newpath = DS;
if ($path[0] === DIRECTORY_SEPARATOR) {
$newpath = DIRECTORY_SEPARATOR;
}

while (($part = array_shift($parts)) !== null) {
Expand All @@ -856,7 +856,7 @@ public function realpath($path)
}
$newparts[] = $part;
}
$newpath .= implode(DS, $newparts);
$newpath .= implode(DIRECTORY_SEPARATOR, $newparts);

return Folder::slashTerm($newpath);
}
Expand Down

0 comments on commit 8c05515

Please sign in to comment.