Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
Implemented check functions for full path. Relates to #19
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Jul 27, 2013
1 parent 919ec96 commit 5a8aa85
Show file tree
Hide file tree
Showing 12 changed files with 1,202 additions and 43 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"require": {
"php": ">=5.3.3",
"ext-mbstring": "*",
"icecave/isolator": "~2"
},
"require-dev": {
Expand Down
85 changes: 43 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 130 additions & 0 deletions src/Eloquent/Pathogen/AbstractPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,136 @@ public function hasExtension()
return count($this->nameAtoms()) > 1;
}

/**
* Determine if this path contains a substring.
*
* @param string $needle The substring to search for.
* @param boolean|null $caseSensitive True if case sensitive.
*
* @return boolean
*/
public function contains($needle, $caseSensitive = null)
{
if ('' === $needle) {
return true;
}
if (null === $caseSensitive) {
$caseSensitive = false;
}

if ($caseSensitive) {
return false !== mb_strpos($this->string(), $needle);
}

return false !== mb_stripos($this->string(), $needle);
}

/**
* Determine if this path starts with a substring.
*
* @param string $needle The substring to search for.
* @param boolean|null $caseSensitive True if case sensitive.
*
* @return boolean
*/
public function startsWith($needle, $caseSensitive = null)
{
if ('' === $needle) {
return true;
}
if (null === $caseSensitive) {
$caseSensitive = false;
}

if ($caseSensitive) {
return 0 === mb_strpos($this->string(), $needle);
}

return 0 === mb_stripos($this->string(), $needle);
}

/**
* Determine if this path ends with a substring.
*
* @param string $needle The substring to search for.
* @param boolean|null $caseSensitive True if case sensitive.
*
* @return boolean
*/
public function endsWith($needle, $caseSensitive = null)
{
if ('' === $needle) {
return true;
}
if (null === $caseSensitive) {
$caseSensitive = false;
}

$end = mb_substr($this->string(), -mb_strlen($needle));

if ($caseSensitive) {
return $end === $needle;
}

return mb_strtolower($end) === mb_strtolower($needle);
}

/**
* Determine if this path matches a wildcard pattern.
*
* @param string $pattern The pattern to check against.
* @param boolean|null $caseSensitive True if case sensitive.
* @param integer|null $flags Additional flags.
*
* @return boolean
*/
public function matches($pattern, $caseSensitive = null, $flags = null)
{
if (null === $caseSensitive) {
$caseSensitive = false;
}
if (null === $flags) {
$flags = 0;
}
if (!$caseSensitive) {
$flags = $flags | FNM_CASEFOLD;
}

return fnmatch($pattern, $this->string(), $flags);
}

/**
* Determine if this path matches a regular expression.
*
* @param string $pattern The pattern to check against.
* @param array|null &$matches Populated with the pattern matches.
* @param integer|null $flags Additional flags.
* @param integer|null $offset Start searching from this byte offset.
*
* @return boolean
*/
public function matchesRegex(
$pattern,
array &$matches = null,
$flags = null,
$offset = null
) {
if (null === $flags) {
$flags = 0;
}
if (null === $offset) {
$offset = 0;
}

return 1 === preg_match(
$pattern,
$this->string(),
$matches,
$flags,
$offset
);
}

/**
* Get the parent of this path a specified number of levels up.
*
Expand Down

0 comments on commit 5a8aa85

Please sign in to comment.