Skip to content

Commit bb12295

Browse files
committed
merged branch jfsimon/issue-4031 (PR #4061)
This PR was squashed before being merged into the master branch (closes #4061). Commits ------- 32bb754 [2.2] [WIP] [Finder] Adding native finders implementations Discussion ---------- [2.2] [WIP] [Finder] Adding native finders implementations Work in progress... Bug fix: no Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #4031 This PR intends to add native finders implementation based on shell command execution. Planned support concerns: - GNU `find` command -> done - MS `FINDSTR` command --------------------------------------------------------------------------- by fabpot at 2012-05-15T06:19:50Z @jfsimon What's the status of this PR? --------------------------------------------------------------------------- by jfsimon at 2012-05-15T06:43:34Z @fabpot 2 features missing for the GNU find adapter: sorting result with `sort` command and excluding directories; 1 bug (even if tests pass, which let me thing it needs more tests): regex matching is done on full path, not basename. Then I'll need to work on MS `FINDSTR` command adapter (I talked to Pierre Couzy, and he's OK to help when he will have time to). I'll try to push the sort and directory excluding features this week. --------------------------------------------------------------------------- by jalliot at 2012-05-15T09:51:20Z BTW @jfsimon, in the (quite specific) case where you don't precise filenames or other options but only `contains` or `notContains`, you could call `grep` directly without the `find`. That would speed things up a bit more :) --------------------------------------------------------------------------- by fabpot at 2012-06-28T15:20:55Z @jfsimon Would be nice to be able to include this PR before 2.1.0 beta2. Would you have time to finish the work soon? --------------------------------------------------------------------------- by jfsimon at 2012-06-29T11:07:19Z @fabpot I'd say next week for GNU part with some help from @smaftoul. --------------------------------------------------------------------------- by jfsimon at 2012-07-10T08:20:44Z It seems that I need to perform some benchmarks as find may not be so fast :/ --------------------------------------------------------------------------- by jfsimon at 2012-07-10T16:51:19Z @fabpot @stof do you think I can add benchmark scripts inside the component, or should I create a new repository for that? --------------------------------------------------------------------------- by fabpot at 2012-07-10T16:57:05Z Then benchmark scripts won't be part of the repository in the end, so you should create a new repo for that. --------------------------------------------------------------------------- by jfsimon at 2012-07-13T17:57:03Z @fabpot @smaftoul Benchmark is ready (more cases to come): https://github.com/jfsimon/symfony-finder-benchmark I'm glad to see that `gnu_find` adapter is really faster than the `php` one! --------------------------------------------------------------------------- by stof at 2012-07-13T19:17:20Z @jfsimon could you make a gist with the result of the benchmark ? I think many people will be lazy to run it themselves when looking at this ticket, and people using windows will probably be unable to run it at all :) --------------------------------------------------------------------------- by jfsimon at 2012-07-13T21:37:50Z First results: https://gist.github.com/3107676 --------------------------------------------------------------------------- by jfsimon at 2012-08-01T07:26:21Z Sorry, I forgot `[Finder]` tag in 3 commits message... is it fixable? --------------------------------------------------------------------------- by stof at 2012-08-01T08:58:28Z @jfsimon you can edit the commit message whne doing an interactive rebase. and btw, you will need to do a rebase anyway: the PR conflicts with master --------------------------------------------------------------------------- by jfsimon at 2012-08-01T13:11:20Z @stof Okay, I rebased origin/master. As you can see, above comments are now floating in the air :/ Strangely, rebase broke my tests... I need to fix them :( --------------------------------------------------------------------------- by stof at 2012-08-01T13:14:11Z Weird. github still tells me that the PR cannot be merged. Did you fetch the latest master before rebasing ? --------------------------------------------------------------------------- by jfsimon at 2012-08-01T13:19:25Z Weird, git fetch only fetched my own repository, I had to `git fetch origin`. I'm rebasing... again. --------------------------------------------------------------------------- by jfsimon at 2012-08-01T14:50:02Z @stof Rebase done, tests fixed :) --------------------------------------------------------------------------- by stof at 2012-08-01T15:18:19Z hmm, Travis does not seems to agree with the second statement :) --------------------------------------------------------------------------- by jfsimon at 2012-08-01T17:33:55Z Ouch, I'm really sorry, I was in the wrong tmux window when started tests :/ Good news, I have to fix my last problem (the regex tested against full path instead of basename) to fix the tests. I'm on it. --------------------------------------------------------------------------- by jfsimon at 2012-08-01T18:16:10Z Grrr... I didnt start full test suite, shame on me. --------------------------------------------------------------------------- by jfsimon at 2012-08-01T19:10:02Z Same bench than before, but with non empty files: https://gist.github.com/3229865 --------------------------------------------------------------------------- by jfsimon at 2012-08-01T19:23:32Z It seems that searching files by their name with regex is really fatser than by glob with find: https://gist.github.com/3229911 @fabpot should I convert glob to regex when using `contains` and `notContains`? --------------------------------------------------------------------------- by jfsimon at 2012-08-01T19:55:02Z It seems that I'm an idiot, I used `contains` instead of `name`. Real bench is here: https://gist.github.com/3230139 @fabpot sorry for the mess, I should go to bed :/ Results are still convincing! --------------------------------------------------------------------------- by stof at 2012-08-01T20:04:42Z They are, but the regex are not faster than glob anymore in these results --------------------------------------------------------------------------- by jfsimon at 2012-08-01T21:17:25Z @travisbot you failed, not me! --------------------------------------------------------------------------- by jfsimon at 2012-08-01T21:18:28Z Anyone to launch benchmark with php 5.4? https://github.com/jfsimon/symfony-finder-benchmark --------------------------------------------------------------------------- by lyrixx at 2012-08-01T22:25:08Z Bench with php 5.4.5 https://gist.github.com/3231244
2 parents 47900b8 + 32bb754 commit bb12295

30 files changed

+2764
-189
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Adapter;
13+
14+
/**
15+
* Interface for finder engine implementations.
16+
*
17+
* @author Jean-François Simon <contact@jfsimon.fr>
18+
*/
19+
abstract class AbstractAdapter implements AdapterInterface
20+
{
21+
protected $followLinks = false;
22+
protected $mode = 0;
23+
protected $minDepth = 0;
24+
protected $maxDepth = INF;
25+
protected $exclude = array();
26+
protected $names = array();
27+
protected $notNames = array();
28+
protected $contains = array();
29+
protected $notContains = array();
30+
protected $sizes = array();
31+
protected $dates = array();
32+
protected $filters = array();
33+
protected $sort = false;
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function setFollowLinks($followLinks)
39+
{
40+
$this->followLinks = $followLinks;
41+
42+
return $this;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function setMode($mode)
49+
{
50+
$this->mode = $mode;
51+
52+
return $this;
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function setDepths(array $depths)
59+
{
60+
$this->minDepth = 0;
61+
$this->maxDepth = INF;
62+
63+
foreach ($depths as $comparator) {
64+
switch ($comparator->getOperator()) {
65+
case '>':
66+
$this->minDepth = $comparator->getTarget() + 1;
67+
break;
68+
case '>=':
69+
$this->minDepth = $comparator->getTarget();
70+
break;
71+
case '<':
72+
$this->maxDepth = $comparator->getTarget() - 1;
73+
break;
74+
case '<=':
75+
$this->maxDepth = $comparator->getTarget();
76+
break;
77+
default:
78+
$this->minDepth = $this->maxDepth = $comparator->getTarget();
79+
}
80+
}
81+
82+
return $this;
83+
}
84+
85+
/**
86+
* {@inheritdoc}
87+
*/
88+
public function setExclude(array $exclude)
89+
{
90+
$this->exclude = $exclude;
91+
92+
return $this;
93+
}
94+
95+
/**
96+
* {@inheritdoc}
97+
*/
98+
public function setNames(array $names)
99+
{
100+
$this->names = $names;
101+
102+
return $this;
103+
}
104+
105+
/**
106+
* {@inheritdoc}
107+
*/
108+
public function setNotNames(array $notNames)
109+
{
110+
$this->notNames = $notNames;
111+
112+
return $this;
113+
}
114+
115+
/**
116+
* {@inheritdoc}
117+
*/
118+
public function setContains(array $contains)
119+
{
120+
$this->contains = $contains;
121+
122+
return $this;
123+
}
124+
125+
/**
126+
* {@inheritdoc}
127+
*/
128+
public function setNotContains(array $notContains)
129+
{
130+
$this->notContains = $notContains;
131+
132+
return $this;
133+
}
134+
135+
/**
136+
* {@inheritdoc}
137+
*/
138+
public function setSizes(array $sizes)
139+
{
140+
$this->sizes = $sizes;
141+
142+
return $this;
143+
}
144+
145+
/**
146+
* {@inheritdoc}
147+
*/
148+
public function setDates(array $dates)
149+
{
150+
$this->dates = $dates;
151+
152+
return $this;
153+
}
154+
155+
/**
156+
* {@inheritdoc}
157+
*/
158+
public function setFilters(array $filters)
159+
{
160+
$this->filters = $filters;
161+
162+
return $this;
163+
}
164+
165+
/**
166+
* {@inheritdoc}
167+
*/
168+
public function setSort($sort)
169+
{
170+
$this->sort = $sort;
171+
172+
return $this;
173+
}
174+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Adapter;
13+
14+
/**
15+
* @author Jean-François Simon <contact@jfsimon.fr>
16+
*/
17+
interface AdapterInterface
18+
{
19+
/**
20+
* @param bool $followLinks
21+
*
22+
* @return AdapterInterface Current instance
23+
*/
24+
function setFollowLinks($followLinks);
25+
26+
/**
27+
* @param int $mode
28+
*
29+
* @return AdapterInterface Current instance
30+
*/
31+
function setMode($mode);
32+
33+
/**
34+
* @param array $exclude
35+
*
36+
* @return AdapterInterface Current instance
37+
*/
38+
function setExclude(array $exclude);
39+
40+
/**
41+
* @param array $depths
42+
*
43+
* @return AdapterInterface Current instance
44+
*/
45+
function setDepths(array $depths);
46+
47+
/**
48+
* @param array $names
49+
*
50+
* @return AdapterInterface Current instance
51+
*/
52+
function setNames(array $names);
53+
54+
/**
55+
* @param array $notNames
56+
*
57+
* @return AdapterInterface Current instance
58+
*/
59+
function setNotNames(array $notNames);
60+
61+
/**
62+
* @param array $contains
63+
*
64+
* @return AdapterInterface Current instance
65+
*/
66+
function setContains(array $contains);
67+
68+
/**
69+
* @param array $notContains
70+
*
71+
* @return AdapterInterface Current instance
72+
*/
73+
function setNotContains(array $notContains);
74+
75+
/**
76+
* @param array $sizes
77+
*
78+
* @return AdapterInterface Current instance
79+
*/
80+
function setSizes(array $sizes);
81+
82+
/**
83+
* @param array $dates
84+
*
85+
* @return AdapterInterface Current instance
86+
*/
87+
function setDates(array $dates);
88+
89+
/**
90+
* @param array $filters
91+
*
92+
* @return AdapterInterface Current instance
93+
*/
94+
function setFilters(array $filters);
95+
96+
/**
97+
* @param \Closure|int $sort
98+
*
99+
* @return AdapterInterface Current instance
100+
*/
101+
function setSort($sort);
102+
103+
/**
104+
* @param string $dir
105+
*
106+
* @return \Iterator Result iterator
107+
*/
108+
function searchInDirectory($dir);
109+
110+
/**
111+
* Tests adapter support for current platform.
112+
*
113+
* @return bool
114+
*/
115+
function isSupported();
116+
117+
/**
118+
* Returns adapter name.
119+
*
120+
* @return string
121+
*/
122+
function getName();
123+
}

0 commit comments

Comments
 (0)