Permalink
Browse files

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
  • Loading branch information...
2 parents 86f7d67 + 5259120 commit bcddd0e7463901f4b08e57d9532f8d23212591b1 @fabpot fabpot committed Oct 4, 2012
View
@@ -0,0 +1,174 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Finder\Adapter;
+
+/**
+ * Interface for finder engine implementations.
+ *
+ * @author Jean-François Simon <contact@jfsimon.fr>
+ */
+abstract class AbstractAdapter implements AdapterInterface
+{
+ protected $followLinks = false;
+ protected $mode = 0;
+ protected $minDepth = 0;
+ protected $maxDepth = INF;
+ protected $exclude = array();
+ protected $names = array();
+ protected $notNames = array();
+ protected $contains = array();
+ protected $notContains = array();
+ protected $sizes = array();
+ protected $dates = array();
+ protected $filters = array();
+ protected $sort = false;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setFollowLinks($followLinks)
+ {
+ $this->followLinks = $followLinks;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setMode($mode)
+ {
+ $this->mode = $mode;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setDepths(array $depths)
+ {
+ $this->minDepth = 0;
+ $this->maxDepth = INF;
+
+ foreach ($depths as $comparator) {
+ switch ($comparator->getOperator()) {
+ case '>':
+ $this->minDepth = $comparator->getTarget() + 1;
+ break;
+ case '>=':
+ $this->minDepth = $comparator->getTarget();
+ break;
+ case '<':
+ $this->maxDepth = $comparator->getTarget() - 1;
+ break;
+ case '<=':
+ $this->maxDepth = $comparator->getTarget();
+ break;
+ default:
+ $this->minDepth = $this->maxDepth = $comparator->getTarget();
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setExclude(array $exclude)
+ {
+ $this->exclude = $exclude;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setNames(array $names)
+ {
+ $this->names = $names;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setNotNames(array $notNames)
+ {
+ $this->notNames = $notNames;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setContains(array $contains)
+ {
+ $this->contains = $contains;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setNotContains(array $notContains)
+ {
+ $this->notContains = $notContains;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setSizes(array $sizes)
+ {
+ $this->sizes = $sizes;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setDates(array $dates)
+ {
+ $this->dates = $dates;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setFilters(array $filters)
+ {
+ $this->filters = $filters;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setSort($sort)
+ {
+ $this->sort = $sort;
+
+ return $this;
+ }
+}
@@ -0,0 +1,123 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Finder\Adapter;
+
+/**
+ * @author Jean-François Simon <contact@jfsimon.fr>
+ */
+interface AdapterInterface
+{
+ /**
+ * @param bool $followLinks
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setFollowLinks($followLinks);
+
+ /**
+ * @param int $mode
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setMode($mode);
+
+ /**
+ * @param array $exclude
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setExclude(array $exclude);
+
+ /**
+ * @param array $depths
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setDepths(array $depths);
+
+ /**
+ * @param array $names
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setNames(array $names);
+
+ /**
+ * @param array $notNames
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setNotNames(array $notNames);
+
+ /**
+ * @param array $contains
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setContains(array $contains);
+
+ /**
+ * @param array $notContains
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setNotContains(array $notContains);
+
+ /**
+ * @param array $sizes
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setSizes(array $sizes);
+
+ /**
+ * @param array $dates
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setDates(array $dates);
+
+ /**
+ * @param array $filters
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setFilters(array $filters);
+
+ /**
+ * @param \Closure|int $sort
+ *
+ * @return AdapterInterface Current instance
+ */
+ function setSort($sort);
+
+ /**
+ * @param string $dir
+ *
+ * @return \Iterator Result iterator
+ */
+ function searchInDirectory($dir);
+
+ /**
+ * Tests adapter support for current platform.
+ *
+ * @return bool
+ */
+ function isSupported();
+
+ /**
+ * Returns adapter name.
+ *
+ * @return string
+ */
+ function getName();
+}
Oops, something went wrong.

0 comments on commit bcddd0e

Please sign in to comment.