2017 © Pedro Peláez
 

library glob

A PHP implementation of Ant's glob.

image

webmozart/glob

A PHP implementation of Ant's glob.

  • Monday, August 15, 2016
  • by webmozart
  • Repository
  • 7 Watchers
  • 109 Stars
  • 319,877 Installations
  • PHP
  • 41 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 16 Versions
  • 9 % Grown

The README.md

Webmozart Glob

Latest Stable Version Total Downloads, (*1)

A utility implementing Ant-like globbing., (*2)

Syntax:, (*3)

  • ? matches any character
  • * matches zero or more characters, except /
  • /**/ matches zero or more directory names
  • [abc] matches a single character a, b or c
  • [a-c] matches a single character a, b or c
  • [^abc] matches any character but a, b or c
  • [^a-c] matches any character but a, b or c
  • {ab,cd} matches ab or cd

API Documentation, (*4)

Comparison with glob()

Compared to PHP's native glob() function, this utility supports:, (*5)

  • /**/ for matching zero or more directories
  • globbing custom stream wrappers, like myscheme://path/**/*.css
  • matching globs against path strings
  • filtering arrays of path strings by a glob
  • exceptions if the glob contains invalid syntax

Since PHP's native glob() function is much more efficient, this utility uses glob() internally whenever possible (i.e. when no special feature is used)., (*6)

Installation

Use Composer to install the package:, (*7)

composer require webmozart/glob

Usage

The main class of the package is [Glob]. Use Glob::glob() to glob the filesystem:, (*8)

use Webmozart\Glob\Glob;

$paths = Glob::glob('/path/to/dir/*.css'); 

You can also use [GlobIterator] to search the filesystem iteratively. However, the iterator is not guaranteed to return sorted results:, (*9)

use Webmozart\Glob\Iterator\GlobIterator;

$iterator = new GlobIterator('/path/to/dir/*.css');

foreach ($iterator as $path) {
    // ...
}

Path Matching

The package also provides utility methods for comparing paths against globs. Use Glob::match() to match a path against a glob:, (*10)

if (Glob::match($path, '/path/to/dir/*.css')) {
    // ...
}

Glob::filter() filters a list of paths by a glob:, (*11)

$paths = Glob::filter($paths, '/path/to/dir/*.css');

The same can be achieved iteratively with [GlobFilterIterator]:, (*12)

use Webmozart\Glob\Iterator\GlobFilterIterator;

$iterator = new GlobFilterIterator('/path/to/dir/*.css', new ArrayIterator($paths));

foreach ($iterator as $path) {
    // ...
}

You can also filter the keys of the path list by passing the FILTER_KEY constant of the respective class:, (*13)

$paths = Glob::filter($paths, '/path/to/dir/*.css', Glob::FILTER_KEY);

$iterator = new GlobFilterIterator(
    '/path/to/dir/*.css', 
    new ArrayIterator($paths),
    GlobFilterIterator::FILTER_KEY
);

Relative Globs

Relative globs such as *.css are not supported. Usually, such globs refer to paths relative to the current working directory. This utility, however, does not want to make such assumptions. Hence you should always pass absolute globs, so usage of __DIR__ is encouraged:, (*14)

use Webmozart\Glob\Glob;

$paths = Glob::glob(__DIR__ . '/*');

Windows Compatibility

Globs need to be passed in canonical form with forward slashes only. Returned paths contain forward slashes only., (*15)

Escaping

The Glob class supports escaping by typing a backslash character \ before any special character:, (*16)

$paths = Glob::glob('/backup\\*/*.css');

In this example, the glob matches all CSS files in the /backup* directory rather than in all directories starting with /backup. Due to PHP's own escaping in strings, the backslash character \ needs to be typed twice to produce a single \ in the string., (*17)

The following escape sequences are available:, (*18)

  • \\?: match a ? in the path
  • \\*: match a * in the path
  • \\{: match a { in the path
  • \\}: match a } in the path
  • \\[: match a [ in the path
  • \\]: match a ] in the path
  • \\^: match a ^ in the path
  • \\-: match a - in the path
  • \\\\: match a \ in the path

Stream Wrappers

The Glob class supports stream wrappers:, (*19)

$paths = Glob::glob('myscheme:///**/*.css');

Authors

Contribute

Contributions to the package are always welcome!, (*20)

Support

If you are having problems, send a mail to bschussek@gmail.com or shout out to @webmozart on Twitter., (*21)

License

All contents of this package are licensed under the MIT license., (*22)

The Versions

15/08 2016

dev-master

9999999-dev

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

29/12 2015

4.1.0

4.1.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

28/12 2015

4.0.0

4.0.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

23/12 2015

3.x-dev

3.9999999.9999999.9999999-dev

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

23/12 2015

3.3.1

3.3.1.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

23/12 2015

3.3.0

3.3.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

23/12 2015

3.2.0

3.2.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

24/08 2015

3.1.1

3.1.1.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

21/08 2015

3.1.0

3.1.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

11/08 2015

3.0.0

3.0.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

21/05 2015

2.0.1

2.0.1.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

06/04 2015

2.0.0

2.0.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

19/03 2015

1.0.0

1.0.0.0

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

30/01 2015

1.0.0-beta3

1.0.0.0-beta3

A PHP implementation of Ant's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

22/01 2015

1.0.0-beta2

1.0.0.0-beta2

A PHP implementation of Git's glob.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

12/01 2015

1.0.0-beta

1.0.0.0-beta

A PHP implementation of Git's glob.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Bernhard Schussek