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,25 +40,31 @@ 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. Example:
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.
53+
54+ Example:
4855
4956.. literalinclude :: files/014.php
5057
51- Now you may use the ``ConfigCollection `` anywhere in your project to access all App Config files without
52- having to re-call the collection methods every time.
58+ Now you may use the ``ConfigCollection `` anywhere in your project to access all
59+ PHP files in **app/Config/ ** without having to re-call the collection methods
60+ every time.
5361
5462set(array $files)
5563=================
5664
57- Sets the list of input files to the provided string array of file paths. This will remove any existing
58- 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.
5968
6069***************
6170Inputting Files
@@ -64,13 +73,14 @@ Inputting Files
6473add(string[]|string $paths, bool $recursive = true)
6574===================================================
6675
67- Adds all files indicated by the path or array of paths. If the path resolves to a directory then `` $recursive ``
68- 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.
6978
7079addFile(string $file) / addFiles(array $files)
7180==============================================
7281
73- 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.
7484
7585removeFile(string $file) / removeFiles(array $files)
7686====================================================
@@ -82,8 +92,8 @@ addDirectory(string $directory, bool $recursive = false)
8292addDirectories(array $directories, bool $recursive = false)
8393===========================================================
8494
85- Adds all files from the directory or directories, optionally recursing into sub-directories. Directories are
86- 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.
8797
8898***************
8999Filtering Files
@@ -94,11 +104,15 @@ removePattern(string $pattern, string $scope = null)
94104retainPattern(string $pattern, string $scope = null)
95105====================================================
96106
97- Filters the current file list through the pattern (and optional scope), removing or retaining matched
98- files. ``$pattern `` may be a complete regex (like ``'#[A-Za-z]+\.php#' ``) or a pseudo-regex similar
99- to ``glob() `` (like ``*.css ``).
100- If a ``$scope `` is provided then only files in or under that directory will be considered (i.e. files
101- 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.
109+
110+ ``$pattern `` may be a complete regex (like ``'#\A[A-Za-z]+\.php\z#' ``) or a
111+ pseudo-regex similar to ``glob() `` (like ``'*.css' ``).
112+
113+ If a ``$scope `` is provided then only files in or under that directory will be
114+ considered (i.e. files outside of ``$scope `` are always retained). When no scope
115+ is provided then all files are subject.
102116
103117Examples:
104118
@@ -113,4 +127,5 @@ get(): string[]
113127
114128Returns an array of all the loaded input files.
115129
116- .. note :: ``FileCollection`` is an ``IteratorAggregate`` so you can work with it directly (e.g. ``foreach ($collection as $file)``).
130+ .. note :: ``FileCollection`` is an ``IteratorAggregate`` so you can work with it
131+ directly (e.g. ``foreach ($collection as $file) ``).
0 commit comments