Well, for most of the cases, this should be possible to achieve with pakeFinder.
pakeFinder object is a set of rules, which can be applied (using $obj->in() method) to various directories, so you can create several pakeFinder objects and apply them to any directories you like afterwards.
Sometimes, that won't be enough, as you need to merge several sets of rules.
We can try to plan, how such tool would look like.
class pakeMultiFinder implements ArrayAccess
{
public function in($path);
/* ArrayAccess methods here */
}
> Alexey Zakhlestin wrote:
>> On 13.04.2011, at 12:18, gggeek wrote:
>>
>>> The use case I have in mind is:
>>> have a list of 'paths', where each path can be either a filename or a
>>> foldername, and it can be specified as either a complete path (eg.
>>> that/dir/file.txt) or as a relative path (eg. */file.txt).
>>>
>>> This can be done in ant, and it is pretty useful when you want to have
>>> a list of eg. files/dirs to remove from a build. Some of them you want
>>> to delete in a specific place, some other wherever they appear.
>> Well, for most of the cases, this should be possible to achieve with pakeFinder.
>>
>> pakeFinder object is a set of rules, which can be applied (using $obj->in() method) to various directories, so you can create several pakeFinder objects and apply them to any directories you like afterwards.
> Pardon my ignorance: what happens currently if I apply two times the ->in() method to the same pakeFinder object?
->in() returns an array and does NOTHING to original pakeFinder object.
so, you will just get several arrays :)
I put the code here: https://gist.github.com/919047
It's your code, but formatted according to PEAR coding standards with a bit of my personal taste tweaking.
I didn't do any tests yet.
After reading this code, I am even more sure, that pakeMultiFinder idea is the way to go. It would allow us to use other similar pattern-generators without repeating code over and over again
I'll try to implement something like that in a branch and will post result here.
I implemented ant-style matching in pakeFinder.
In the end, it was simpler than I thought, so I didn't need to, actually go with "multifinder" way.
implementation is not based on your code, but is made to match ant's documentation.
I also added some tests
How to use:
$rule = pakeFinder::type('any')->pattern('*/file.txt')->not_pattern('tmp*/*');
$files = $rule->in($target);
This will match:
1) any file or directory
2) which is named "file.txt"
3) and is located in some first-level subdirectory of $target,
4) where name of this first-level subdirectory doesn't start with "tmp"
pattern() and not_pattern() accept multiple arguments, or you can just call them several times
and, of course, you can mix this with other pakeFinder's checks.
does this look ok? :)
by the way, here is the order of pakeFinder's rules application:
1) check if last piece of path matches "type"
2) check if last piece of path is discarded
3) check if relative path matches ->not_pattern()/->pattern()
4) check if last piece of path matches ->not_name()/->name()
5) check if file size matches ->size() [only for files]
6) check if path is ok with custom checkers set with ->exec()