22File Collections
33################
44
5- Working with groups of files can be cumbersome, so the framework supplies the ``FileCollection `` class to facilitate
6- locating and working with groups of files across the filesystem.
5+ Working with groups of files can be cumbersome, so the framework supplies the
6+ ``FileCollection `` class to facilitate locating and working with groups of files
7+ across the filesystem.
78
89.. contents ::
910 :local:
@@ -18,13 +19,15 @@ of files you set or build:
1819
1920.. literalinclude :: files/011.php
2021
21- After you have input the files you would like to work with you may remove files or use the filtering commands to remove
22- or retain files matching a certain regex or glob-style pattern:
22+ After you have input the files you would like to work with you may remove files
23+ or use the filtering commands to remove or retain files matching a certain regex
24+ or glob-style pattern:
2325
2426.. literalinclude :: files/012.php
2527
26- When your collection is complete, you can use ``get() `` to retrieve the final list of file paths, or take advantage of
27- ``FileCollection `` being countable and iterable to work directly with each ``File ``:
28+ When your collection is complete, you can use ``get() `` to retrieve the final
29+ list of file paths, or take advantage of ``FileCollection `` being countable and
30+ iterable to work directly with each ``File ``:
2831
2932.. literalinclude :: files/013.php
3033
@@ -37,14 +40,16 @@ Starting a Collection
3740__construct(string[] $files = [])
3841=================================
3942
40- The constructor accepts an optional array of file paths to use as the initial collection. These are passed to
41- ``add() `` so any files supplied by child classes in the ``$files `` will remain.
43+ The constructor accepts an optional array of file paths to use as the initial
44+ collection. These are passed to ``add() `` so any files supplied by child classes
45+ in the ``$files `` will remain.
4246
4347define()
4448========
4549
46- Allows child classes to define their own initial files. This method is called by the constructor and allows
47- predefined collections without having to use their methods.
50+ Allows child classes to define their own initial files. This method is called by
51+ the constructor and allows predefined collections without having to use their
52+ methods.
4853
4954Example:
5055
@@ -57,8 +62,9 @@ every time.
5762set(array $files)
5863=================
5964
60- Sets the list of input files to the provided string array of file paths. This will remove any existing
61- files from the collection, so ``$collection->set([]) `` is essentially a hard reset.
65+ Sets the list of input files to the provided string array of file paths. This
66+ will remove any existing files from the collection, so ``$collection->set([]) ``
67+ is essentially a hard reset.
6268
6369***************
6470Inputting Files
@@ -67,13 +73,14 @@ Inputting Files
6773add(string[]|string $paths, bool $recursive = true)
6874===================================================
6975
70- Adds all files indicated by the path or array of paths. If the path resolves to a directory then `` $recursive ``
71- will include sub-directories.
76+ Adds all files indicated by the path or array of paths. If the path resolves to
77+ a directory then `` $recursive `` will include sub-directories.
7278
7379addFile(string $file) / addFiles(array $files)
7480==============================================
7581
76- Adds the file or files to the current list of input files. Files are absolute paths to actual files.
82+ Adds the file or files to the current list of input files. Files are absolute
83+ paths to actual files.
7784
7885removeFile(string $file) / removeFiles(array $files)
7986====================================================
@@ -85,8 +92,8 @@ addDirectory(string $directory, bool $recursive = false)
8592addDirectories(array $directories, bool $recursive = false)
8693===========================================================
8794
88- Adds all files from the directory or directories, optionally recursing into sub-directories. Directories are
89- absolute paths to actual directories.
95+ Adds all files from the directory or directories, optionally recursing into
96+ sub-directories. Directories are absolute paths to actual directories.
9097
9198***************
9299Filtering Files
@@ -97,11 +104,12 @@ removePattern(string $pattern, string $scope = null)
97104retainPattern(string $pattern, string $scope = null)
98105====================================================
99106
100- Filters the current file list through the pattern (and optional scope), removing or retaining matched
101- files. ``$pattern `` may be a complete regex (like ``'#[A-Za-z]+\.php#' ``) or a pseudo-regex similar
102- to ``glob() `` (like ``*.css ``).
103- If a ``$scope `` is provided then only files in or under that directory will be considered (i.e. files
104- outside of ``$scope `` are always retained). When no scope is provided then all files are subject.
107+ Filters the current file list through the pattern (and optional scope), removing
108+ or retaining matched files. ``$pattern `` may be a complete regex (like ``'#[A-Za-z]+\.php#' ``)
109+ or a pseudo-regex similar to ``glob() `` (like ``*.css ``). If a ``$scope `` is
110+ provided then only files in or under that directory will be considered (i.e. files
111+ outside of ``$scope `` are always retained). When no scope is provided then all
112+ files are subject.
105113
106114Examples:
107115
@@ -116,4 +124,5 @@ get(): string[]
116124
117125Returns an array of all the loaded input files.
118126
119- .. note :: ``FileCollection`` is an ``IteratorAggregate`` so you can work with it directly (e.g. ``foreach ($collection as $file)``).
127+ .. note :: ``FileCollection`` is an ``IteratorAggregate`` so you can work with it
128+ directly (e.g. ``foreach ($collection as $file) ``).
0 commit comments