Skip to content

Commit

Permalink
[2.2] [WIP] [Finder] Adding native finders implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
jfsimon authored and fabpot committed Oct 4, 2012
1 parent b1618d2 commit 32bb754
Show file tree
Hide file tree
Showing 30 changed files with 2,764 additions and 189 deletions.
174 changes: 174 additions & 0 deletions src/Symfony/Component/Finder/Adapter/AbstractAdapter.php
@@ -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;
}
}
123 changes: 123 additions & 0 deletions src/Symfony/Component/Finder/Adapter/AdapterInterface.php
@@ -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();
}

0 comments on commit 32bb754

Please sign in to comment.