Skip to content

Commit

Permalink
1.35.1
Browse files Browse the repository at this point in the history
* [*] Path fixes
  • Loading branch information
KarelWintersky committed Jun 10, 2021
1 parent 65070fa commit 6016ed5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion sources/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Path
*/
public static function create($path)
{
return new self($path);
return new self($path, false);
}

public static function createImmutable($path)
Expand All @@ -34,6 +34,8 @@ public function __construct($path, $isImmutable = false)
} elseif (is_array($path)) {
$this->atoms = $path;
}

$this->atoms = $this->trimEach($this->atoms);
}

public function toString()
Expand All @@ -46,6 +48,7 @@ public function join($data)
if (is_string($data)) {
$data = explode(DIRECTORY_SEPARATOR, trim($data, DIRECTORY_SEPARATOR));
}
$data = $this->trimEach($data);

if ($this->isImmutable) {
return new self(array_merge($this->atoms, $data), $this->isImmutable);
Expand All @@ -55,5 +58,16 @@ public function join($data)
return $this;
}

/**
* apply trim for each element of array
*
* @param $data
* @return array|string[]
*/
private function trimEach($data)
{
return array_map(static function ($item) { return trim($item, DIRECTORY_SEPARATOR); }, $data);
}


}

0 comments on commit 6016ed5

Please sign in to comment.