Add a `phutil_fnmatch` function


Add a phutil_fnmatch function

Ref T5105. This function is an improved version of fnmatch. Internally, this function converts a glob pattern into a regular expression and is based on Symfony\Component\Finder\Glob, with influence from editorconfig-core-js.

The PHP fnmatch() is inadequate for our use case for a variety of reasons:

  • Lack of error handling (fnmatch('{', '') does not throw an exception).
  • Lack of support for {} groupings (fnmatch('{a,b}', 'a') returns false).
  • **/* only matches in subdirectories (fnmatch('**/file', $x) matches $x = 'subdir/file' but does not match $x = 'file').
NOTE: At the moment, phutil_fnmatch() doesn't support $flags, whereas fnmatch does. In the future, we may wish to implement these flags. Currently, $flags is basiically equivalent to 0.

Test Plan: Added unit tests.

Reviewers: Blessed Reviewers, epriestley

Reviewed By: Blessed Reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T5105

Differential Revision: https://secure.phabricator.com/D11444