public static function check($path)
{
// Whitelist first
$is_white = false;
foreach (self::$include_paths as $white_dir) {
$len = strlen($white_dir);
if (substr($path, 0, $len) === $white_dir) {
$is_white = true;
}
}
if ($is_white === false) {
return false;
}
// Then blacklist
foreach (self::$exclude_paths as $black_dir) {
// Check excluded path that starts with '-'.
// '-' is smaller than '/', so this checking always comes first.
if (substr($black_dir, 0, 1) === '-') {
$black_dir = ltrim($black_dir, '-');
$len = strlen($black_dir);
if (substr($path, 0, $len) === $black_dir) {
return true;
}
}
$len = strlen($black_dir);
if (substr($path, 0, $len) === $black_dir) {
return false;
}
}
return true;
}