private static function buildPattern($masks)
    {
        $pattern = array();
        $masks = is_array($masks) ? $masks : [$masks];
        foreach ($masks as $mask) {
            $mask = rtrim(strtr($mask, '\\', '/'), '/');
            $prefix = '';
            if ($mask === '') {
                continue;

            } elseif ($mask === '*') {
                return NULL;

            } elseif ($mask[0] === '/') { // absolute fixing
                $mask = ltrim($mask, '/');
                $prefix = '(?<=^/)';
            }
            $pattern[] = $prefix . strtr(preg_quote($mask, '#'),
                    array('\*\*' => '.*', '\*' => '[^/]*', '\?' => '[^/]', '\[\!' => '[^', '\[' => '[', '\]' => ']', '\-' => '-'));
        }

        return $pattern ? '#/(' . implode('|', $pattern) . ')\z#i' : NULL;
    }