private function pattern_to_regex($pattern)
    {
        if (substr($pattern, -1) == '/') {
            $pattern .= '**';
        }

        $regex = '|^';
        foreach (explode('/', $pattern) as $i => $piece) {
            if ($i > 0) {
                $regex .= preg_quote('/', '|');
            }

            if ('**' == $piece) {
                $regex .= '.*';
            } else {
                $regex .= str_replace(array('?', '*'), array('[^/]', '[^/]*'), $piece);
            }
        }
        $regex .= '$|';

        return $regex;
    }