From 8ebfebb6c7480473c368258ab3e3dc305aa3306f Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Sun, 23 Aug 2015 21:14:00 +0200 Subject: [PATCH 1/6] fixed using undefined classes in typehints --- src/Finder/Finder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Finder/Finder.php b/src/Finder/Finder.php index 0b00632..10677c0 100644 --- a/src/Finder/Finder.php +++ b/src/Finder/Finder.php @@ -30,7 +30,7 @@ class Finder extends Nette\Object implements \IteratorAggregate, \Countable /** @var array of filters */ private $groups; - /** @var filter for recursive traversing */ + /** @var array filter for recursive traversing */ private $exclude = array(); /** @var int */ From 3cc0eb758c7fd04c73837d8a2a09d5d515934069 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 5 Oct 2015 15:06:20 +0200 Subject: [PATCH 2/6] used https --- composer.json | 6 +++--- contributing.md | 4 ++-- license.md | 2 +- src/Finder/Finder.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index f18cf34..1b6763d 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,16 @@ { "name": "nette/finder", "description": "Nette Finder: Files Searching", - "homepage": "http://nette.org", + "homepage": "https://nette.org", "license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], "authors": [ { "name": "David Grudl", - "homepage": "http://davidgrudl.com" + "homepage": "https://davidgrudl.com" }, { "name": "Nette Community", - "homepage": "http://nette.org/contributors" + "homepage": "https://nette.org/contributors" } ], "require": { diff --git a/contributing.md b/contributing.md index a1cbbd5..860882b 100644 --- a/contributing.md +++ b/contributing.md @@ -5,7 +5,7 @@ The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests, but please respect the following restrictions: * Please **do not** use the issue tracker for personal support requests (use - [Nette forum](http://forum.nette.org) or [Stack Overflow](http://stackoverflow.com)). + [Nette forum](https://forum.nette.org) or [Stack Overflow](http://stackoverflow.com)). * Please **do not** derail or troll issues. Keep the discussion on topic and respect the opinions of others. @@ -21,7 +21,7 @@ fits with the scope and aims of the project. It's up to *you* to make a strong case to convince the project's developers of the merits of this feature. Nette welcomes **pull requests**. If you'd like to contribute, please take a moment -to [read the guidelines](http://nette.org/en/contributing) in order to make +to [read the guidelines](https://nette.org/en/contributing) in order to make the contribution process easy and effective for everyone involved. Thanks! diff --git a/license.md b/license.md index af571d5..cf741bd 100644 --- a/license.md +++ b/license.md @@ -21,7 +21,7 @@ If your stuff is good, it will not take long to establish a reputation for yours New BSD License --------------- -Copyright (c) 2004, 2014 David Grudl (http://davidgrudl.com) +Copyright (c) 2004, 2014 David Grudl (https://davidgrudl.com) All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/src/Finder/Finder.php b/src/Finder/Finder.php index 10677c0..bf0e7ed 100644 --- a/src/Finder/Finder.php +++ b/src/Finder/Finder.php @@ -1,8 +1,8 @@ Date: Mon, 5 Oct 2015 15:06:29 +0200 Subject: [PATCH 3/6] travis: removed PHP 7 from allowed failures --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f48ac6a..3dd7ea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ php: matrix: allow_failures: - - php: 7.0 - php: hhvm include: From 1a240cdec62c738f9aeeb1479b499aa31d5f3bf3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 19 Oct 2015 22:58:03 +0200 Subject: [PATCH 4/6] fixed typehints, FilesystemIterator -> RecursiveDirectoryIterator in filters --- src/Finder/Finder.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Finder/Finder.php b/src/Finder/Finder.php index bf0e7ed..b94a672 100644 --- a/src/Finder/Finder.php +++ b/src/Finder/Finder.php @@ -8,7 +8,7 @@ namespace Nette\Utils; use Nette; -use FilesystemIterator; +use RecursiveDirectoryIterator; use RecursiveIteratorIterator; @@ -99,7 +99,7 @@ private function select($masks, $type) $this->cursor = & $this->groups[]; $pattern = self::buildPattern($masks); if ($type || $pattern) { - $this->filter(function (FilesystemIterator $file) use ($type, $pattern) { + $this->filter(function (RecursiveDirectoryIterator $file) use ($type, $pattern) { return !$file->isDot() && (!$type || $file->$type()) && (!$pattern || preg_match($pattern, '/' . strtr($file->getSubPathName(), '\\', '/'))); @@ -226,7 +226,7 @@ public function getIterator() */ private function buildIterator($path) { - $iterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS); + $iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS); if ($this->exclude) { $filters = $this->exclude; @@ -253,7 +253,7 @@ private function buildIterator($path) $iterator = new CallbackFilterIterator($iterator, function ($foo, $bar, CallbackFilterIterator $file) use ($groups) { do { $file = $file->getInnerIterator(); - } while (!$file instanceof FilesystemIterator); + } while (!$file instanceof RecursiveDirectoryIterator); foreach ($groups as $filters) { foreach ($filters as $filter) { @@ -287,7 +287,7 @@ public function exclude($masks) } $pattern = self::buildPattern($masks); if ($pattern) { - $this->filter(function (FilesystemIterator $file) use ($pattern) { + $this->filter(function (RecursiveDirectoryIterator $file) use ($pattern) { return !preg_match($pattern, '/' . strtr($file->getSubPathName(), '\\', '/')); }); } @@ -297,7 +297,7 @@ public function exclude($masks) /** * Restricts the search using callback. - * @param callable function (FilesystemIterator $file) + * @param callable function (RecursiveDirectoryIterator $file) * @return self */ public function filter($callback) @@ -336,7 +336,7 @@ public function size($operator, $size = NULL) $size *= $units[strtolower($unit)]; $operator = $operator ? $operator : '='; } - return $this->filter(function (FilesystemIterator $file) use ($operator, $size) { + return $this->filter(function (RecursiveDirectoryIterator $file) use ($operator, $size) { return Finder::compare($file->getSize(), $operator, $size); }); } @@ -358,7 +358,7 @@ public function date($operator, $date = NULL) $operator = $operator ? $operator : '='; } $date = DateTime::from($date)->format('U'); - return $this->filter(function (FilesystemIterator $file) use ($operator, $date) { + return $this->filter(function (RecursiveDirectoryIterator $file) use ($operator, $date) { return Finder::compare($file->getMTime(), $operator, $date); }); } From 269bc5f676dc855e860b433edb3b131daf8067f4 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 20 Oct 2015 00:49:20 +0200 Subject: [PATCH 5/6] tests: added test --- tests/Finder/Finder.basic.phpt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Finder/Finder.basic.phpt b/tests/Finder/Finder.basic.phpt index 078f1cb..03055b9 100644 --- a/tests/Finder/Finder.basic.phpt +++ b/tests/Finder/Finder.basic.phpt @@ -105,3 +105,15 @@ test(function () { // recursive directory search 'files/subdir/subdir2', ), export($finder)); }); + + +test(function () { // getSubPathName + $res = array(); + foreach ($iterator = Finder::findFiles('file.txt')->from('files')->getIterator() as $foo) { + $res[$iterator->getSubPathName()] = TRUE; + } + Assert::same( + array('file.txt', 'subdir/file.txt', 'subdir/subdir2/file.txt'), + export($res) + ); +}); From ea8e796b42d542bd90e76f5b2a41c2c86a008256 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 20 Oct 2015 13:09:02 +0200 Subject: [PATCH 6/6] $groups is never empty --- src/Finder/Finder.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Finder/Finder.php b/src/Finder/Finder.php index b94a672..968ebc9 100644 --- a/src/Finder/Finder.php +++ b/src/Finder/Finder.php @@ -248,24 +248,22 @@ private function buildIterator($path) $iterator->setMaxDepth($this->maxDepth); } - if ($this->groups) { - $groups = $this->groups; - $iterator = new CallbackFilterIterator($iterator, function ($foo, $bar, CallbackFilterIterator $file) use ($groups) { - do { - $file = $file->getInnerIterator(); - } while (!$file instanceof RecursiveDirectoryIterator); - - foreach ($groups as $filters) { - foreach ($filters as $filter) { - if (!call_user_func($filter, $file)) { - continue 2; - } + $groups = $this->groups; + $iterator = new CallbackFilterIterator($iterator, function ($foo, $bar, CallbackFilterIterator $file) use ($groups) { + do { + $file = $file->getInnerIterator(); + } while (!$file instanceof RecursiveDirectoryIterator); + + foreach ($groups as $filters) { + foreach ($filters as $filter) { + if (!call_user_func($filter, $file)) { + continue 2; } - return TRUE; } - return FALSE; - }); - } + return TRUE; + } + return FALSE; + }); return $iterator; }