Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
master: added a segment() method to Path
Browse files Browse the repository at this point in the history
  • Loading branch information
leedwilkins committed Feb 16, 2017
1 parent 1435a53 commit b3a1d05
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Library/File/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,34 @@ public function equals(Path $path)
return $this->asString() === $path->asString();
}

/**
* @param Path $path
*
* @return bool
*/
public function contains(Path $path)
{
return (strstr($this->asString(), $path->asString()) !== false);
}

/**
* @param Path $path
*
* @return bool
*/
public function startsWith(Path $path)
{
return (substr($this->asString(), 0, strlen($path->asString())) === $path->asString());
}

/**
* @param int $index
*
* @return string
*/
public function segment($index)
{
$segments = explode('/', trim($this->path, '/'));
return $segments[$index];
}
}

0 comments on commit b3a1d05

Please sign in to comment.