Skip to content

[2.2] [WIP] [Finder] Adding native finders implementations #4061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
331e3ad
[Finder] Added adapter interface.
jfsimon Apr 21, 2012
a05f449
[Finder] Added abstract adapter.
jfsimon Apr 21, 2012
d340849
[Finder] Moved current implementation to php adapter.
jfsimon Apr 21, 2012
c3cdda3
[Finder] Moved min/max depth calculation to abstract adapter.
jfsimon Apr 21, 2012
411cb8b
[Finder] Fixed depth iterator tests.
jfsimon Apr 21, 2012
c47c5de
[Finder] Moved glob/regex methods to new Expr class.
jfsimon Apr 22, 2012
432a3fe
[Finder] Added Expr class tests.
jfsimon Apr 22, 2012
524ebe9
[Finder] Added file paths iterator and its tests.
jfsimon Apr 22, 2012
f6acae0
[Finder] Added minimalist gnu find adapter.
jfsimon Apr 22, 2012
de2ae38
[Finder] Added adapter validity control.
jfsimon Apr 22, 2012
dc4bf1f
[Finder] Added adapter selection method.
jfsimon Apr 22, 2012
c23ebf9
[Finder] Updated tests to use all valid adapters.
jfsimon Apr 22, 2012
bf74c89
[Finder] Added native names/notNames support to gnu find adapter.
jfsimon Apr 22, 2012
7b593ee
[Finder] Added native sizes support to gnu find adapter.
jfsimon Apr 22, 2012
3b3ee8f
[Finder] Added native dates support to gnu find adapter.
jfsimon Apr 22, 2012
530f229
[Finder] Performed some cleanup.
jfsimon Apr 22, 2012
05897a4
[Finder] Improved command class.
jfsimon Apr 22, 2012
da79cc4
[Finder] Refactored command building.
jfsimon Apr 23, 2012
19f055e
[Finder] Updated shell command test.
jfsimon Apr 23, 2012
daa9b31
[Finder] Added adapter registration method.
jfsimon Apr 23, 2012
cba5bca
[Finder] Cleaned code.
jfsimon Apr 24, 2012
f131e27
[Finder] Added possibility for adapter to fail.
Apr 24, 2012
8a3b2de
[Finder] Added adapters registration tests.
Apr 24, 2012
eefba16
[Finder] Added grep support for gnu find adapter.
May 10, 2012
924561c
[Finder] Fixed typo & removed debug output.
jfsimon Jul 4, 2012
f924d85
[Finder] Added native sorting support to gnu find adapter.
jfsimon Jul 10, 2012
4229962
[Finder] Refactored expression (regex/glob) handling.
jfsimon Jul 31, 2012
e80e115
[Finder] Added expression tests & fixed related bugs.
jfsimon Aug 1, 2012
8b9ffc6
[Finder] Moved Shell & Command classes to Shell namespace.
jfsimon Aug 1, 2012
0e61db9
[Finder] Fixed regex escaped flag/joker bug.
jfsimon Aug 1, 2012
60e69fe
[Finder] Fixed 'regex are not search' problem.
jfsimon Aug 1, 2012
4e3b017
[Finder] Fixed master rebase.
jfsimon Aug 1, 2012
144c61b
[Finder] Fixed search directory.
jfsimon Aug 1, 2012
aa84e2d
[Finder] Fixed typos, CS and small errors.
jfsimon Aug 1, 2012
46cc2d4
[Finder] Fixed namespace.
jfsimon Aug 2, 2012
5fc01f2
[Finder] Changed method name for gnu find adapter.
jfsimon Aug 2, 2012
ef0ebb8
[Finder] Fixed gnu find regex name filtering problems.
jfsimon Aug 3, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Finder] Fixed typos, CS and small errors.
  • Loading branch information
jfsimon committed Aug 1, 2012
commit aa84e2d6e5a5d8feefec69aecdbe93c6c0e7d24c
30 changes: 21 additions & 9 deletions src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ private function buildNamesCommand(Command $command, array $names, $not = false)

// Fixes 'not search' regex problem.
if ($expr->isRegex()) {
$expr->prepend($expr->hasStartFlag() ? '/' : '/.*')->setStartFlag(false)->setStartJoker(true);
$regex = $expr->getRegex();
$regex->prepend($regex->hasStartFlag() ? '/' : '/.*')->setStartFlag(false)->setStartJoker(true);

if (!$expr->hasEndFlag()) {
$expr->setEndJoker(true);
if (!$regex->hasEndFlag()) {
$regex->setEndJoker(true);
}
}

Expand Down Expand Up @@ -280,12 +281,23 @@ private function buildContainsCommand(Command $command, array $contains, $not =
private function buildSortCommand(Command $command, $sort)
{
switch ($sort) {
case SortableIterator::SORT_BY_NAME: $format = null; break;
case SortableIterator::SORT_BY_TYPE: $format = '%y'; break;
case SortableIterator::SORT_BY_ACCESSED_TIME: $format = '%A@'; break;
case SortableIterator::SORT_BY_CHANGED_TIME: $format = '%C@'; break;
case SortableIterator::SORT_BY_MODIFIED_TIME: $format = '%T@'; break;
default: throw new \InvalidArgumentException('Unknown sort options: '.$sort.'.');
case SortableIterator::SORT_BY_NAME:
$format = null;
break;
case SortableIterator::SORT_BY_TYPE:
$format = '%y';
break;
case SortableIterator::SORT_BY_ACCESSED_TIME:
$format = '%A@';
break;
case SortableIterator::SORT_BY_CHANGED_TIME:
$format = '%C@';
break;
case SortableIterator::SORT_BY_MODIFIED_TIME:
$format = '%T@';
break;
default:
throw new \InvalidArgumentException('Unknown sort options: '.$sort.'.');
}

$command->get('find')->add('-printf')->arg($format.' %h/%f\\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class AdapterFailureException extends \RuntimeException
class AdapterFailureException extends \RuntimeException implements ExceptionInterface
{
/**
* @var \Symfony\Component\Finder\Adapter\AdapterInterface
*/
private $adapter;

/**
* @param \Symfony\Component\Finder\Adapter\AdapterInterface $adapter
* @param string|null $message
* @param \Exception|null $previous
* @param AdapterInterface $adapter
* @param string|null $message
* @param \Exception|null $previous
*/
public function __construct(AdapterInterface $adapter, $message = null, \Exception $previous = null)
{
Expand All @@ -37,7 +37,7 @@ public function __construct(AdapterInterface $adapter, $message = null, \Excepti
}

/**
* @return \Symfony\Component\Finder\Adapter\AdapterInterface
* {@inheritdoc}
*/
public function getAdapter()
{
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Finder/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Symfony\Component\Finder\Exception;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
interface ExceptionInterface
{
/**
* @return \Symfony\Component\Finder\Adapter\AdapterInterface
*/
function getAdapter();
}
11 changes: 0 additions & 11 deletions src/Symfony/Component/Finder/Expression/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ public function __toString()
return $this->render();
}

/**
* @param string $method
* @param array $arguments
*
* @return mixed
*/
public function __call($method, array $arguments)
{
return call_user_func_array(array($this->value, $method), $arguments);
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Finder;

use Symfony\Component\Finder\Adapter;
use Symfony\Component\Finder\Exception\AdapterFailureException;
use Symfony\Component\Finder\Exception\ExceptionInterface;

/**
* Finder allows to build rules to find files and directories.
Expand Down Expand Up @@ -82,7 +82,7 @@ public static function create()
* @param Adapter\AdapterInterface $adapter An adapter instance
* @param int $priority Highest is selected first
*
* @return \Symfony\Component\Finder\Finder The current Finder instance
* @return Finder The current Finder instance
*/
public function register(Adapter\AdapterInterface $adapter, $priority = 0)
{
Expand All @@ -97,7 +97,7 @@ public function register(Adapter\AdapterInterface $adapter, $priority = 0)
/**
* Removes all adapters registered in the finder.
*
* @return \Symfony\Component\Finder\Finder The current Finder instance
* @return Finder The current Finder instance
*/
public function removeAdapters()
{
Expand All @@ -107,7 +107,7 @@ public function removeAdapters()
}

/**
* Returns reegistered adapters ordered by priority without extra informations.
* Returns registered adapters ordered by priority without extra information.
*
* @return \Symfony\Component\Finder\Adapter\AdapterInterface[]
*/
Expand Down Expand Up @@ -654,7 +654,7 @@ private function searchInDirectory($dir)
return $this
->buildAdapter($adapter['adapter'])
->searchInDirectory($dir);
} catch(AdapterFailureException $e) {
} catch(ExceptionInterface $e) {
continue;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Finder/Shell/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __toString()
*
* @return Command New Command instance
*/
static public function create(Command $parent = null)
public static function create(Command $parent = null)
{
return new self($parent);
}
Expand All @@ -72,7 +72,7 @@ static public function create(Command $parent = null)
*
* @return string The escaped string
*/
static public function escape($input)
public static function escape($input)
{
return escapeshellcmd($input);
}
Expand All @@ -84,7 +84,7 @@ static public function escape($input)
*
* @return string The quoted string
*/
static public function quote($input)
public static function quote($input)
{
return escapeshellarg($input);
}
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Finder/Tests/Expression/GlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

use Symfony\Component\Finder\Expression\Expression;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class GlobTest extends \PHPUnit_Framework_TestCase
{
/**
Expand Down
21 changes: 9 additions & 12 deletions src/Symfony/Component/Finder/Tests/Expression/RegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

use Symfony\Component\Finder\Expression\Expression;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class RegexTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -25,8 +22,8 @@ public function testHasFlags($regex, $start, $end)
{
$expr = new Expression($regex);

$this->assertEquals($start, $expr->hasStartFlag());
$this->assertEquals($end, $expr->hasEndFlag());
$this->assertEquals($start, $expr->getRegex()->hasStartFlag());
$this->assertEquals($end, $expr->getRegex()->hasEndFlag());
}

/**
Expand All @@ -36,8 +33,8 @@ public function testHasJokers($regex, $start, $end)
{
$expr = new Expression($regex);

$this->assertEquals($start, $expr->hasStartJoker());
$this->assertEquals($end, $expr->hasEndJoker());
$this->assertEquals($start, $expr->getRegex()->hasStartJoker());
$this->assertEquals($end, $expr->getRegex()->hasEndJoker());
}

/**
Expand All @@ -46,7 +43,7 @@ public function testHasJokers($regex, $start, $end)
public function testSetFlags($regex, $start, $end, $expected)
{
$expr = new Expression($regex);
$expr->setStartFlag($start)->setEndFlag($end);
$expr->getRegex()->setStartFlag($start)->setEndFlag($end);

$this->assertEquals($expected, $expr->render());
}
Expand All @@ -57,15 +54,15 @@ public function testSetFlags($regex, $start, $end, $expected)
public function testSetJokers($regex, $start, $end, $expected)
{
$expr = new Expression($regex);
$expr->setStartJoker($start)->setEndJoker($end);
$expr->getRegex()->setStartJoker($start)->setEndJoker($end);

$this->assertEquals($expected, $expr->render());
}

public function testOptions()
{
$expr = new Expression('~abc~is');
$expr->removeOption('i')->addOption('m');
$expr->getRegex()->removeOption('i')->addOption('m');

$this->assertEquals('~abc~sm', $expr->render());
}
Expand All @@ -74,10 +71,10 @@ public function testMixFlagsAndJokers()
{
$expr = new Expression('~^.*abc.*$~is');

$expr->setStartFlag(false)->setEndFlag(false)->setStartJoker(false)->setEndJoker(false);
$expr->getRegex()->setStartFlag(false)->setEndFlag(false)->setStartJoker(false)->setEndJoker(false);
$this->assertEquals('~abc~is', $expr->render());

$expr->setStartFlag(true)->setEndFlag(true)->setStartJoker(true)->setEndJoker(true);
$expr->getRegex()->setStartFlag(true)->setEndFlag(true)->setStartJoker(true)->setEndJoker(true);
$this->assertEquals('~^.*abc.*$~is', $expr->render());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function isSupported()
/**
* {@inheritdoc}
*/
function getName()
public function getName()
{
return 'yes';
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy