Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d243913

Browse files
[Finder] Deprecate adapters and related classes
1 parent 4d275b4 commit d243913

20 files changed

+255
-36
lines changed

src/Symfony/Component/Finder/Adapter/AbstractAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\AbstractAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED);
15+
1416
/**
1517
* Interface for finder engine implementations.
1618
*
1719
* @author Jean-François Simon <[email protected]>
20+
*
21+
* @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
1822
*/
1923
abstract class AbstractAdapter implements AdapterInterface
2024
{

src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\AbstractFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Exception\AccessDeniedException;
1517
use Symfony\Component\Finder\Iterator;
1618
use Symfony\Component\Finder\Shell\Shell;
@@ -23,6 +25,8 @@
2325
* Shell engine implementation using GNU find command.
2426
*
2527
* @author Jean-François Simon <[email protected]>
28+
*
29+
* @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
2630
*/
2731
abstract class AbstractFindAdapter extends AbstractAdapter
2832
{

src/Symfony/Component/Finder/Adapter/AdapterInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* @author Jean-François Simon <[email protected]>
16+
*
17+
* @deprecated since 2.8, to be removed in 3.0.
1618
*/
1719
interface AdapterInterface
1820
{

src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\BsdFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Shell\Shell;
1517
use Symfony\Component\Finder\Shell\Command;
1618
use Symfony\Component\Finder\Iterator\SortableIterator;
@@ -20,6 +22,8 @@
2022
* Shell engine implementation using BSD find command.
2123
*
2224
* @author Jean-François Simon <[email protected]>
25+
*
26+
* @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
2327
*/
2428
class BsdFindAdapter extends AbstractFindAdapter
2529
{

src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\GnuFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Shell\Shell;
1517
use Symfony\Component\Finder\Shell\Command;
1618
use Symfony\Component\Finder\Iterator\SortableIterator;
@@ -20,6 +22,8 @@
2022
* Shell engine implementation using GNU find command.
2123
*
2224
* @author Jean-François Simon <[email protected]>
25+
*
26+
* @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
2327
*/
2428
class GnuFindAdapter extends AbstractFindAdapter
2529
{

src/Symfony/Component/Finder/Adapter/PhpAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\PhpAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Iterator;
1517

1618
/**
1719
* PHP finder engine implementation.
1820
*
1921
* @author Jean-François Simon <[email protected]>
22+
*
23+
* @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
2024
*/
2125
class PhpAdapter extends AbstractAdapter
2226
{

src/Symfony/Component/Finder/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.8.0
5+
-----
6+
7+
* deprecated adapters and related classes
8+
49
2.5.0
510
-----
611
* added support for GLOB_BRACE in the paths passed to Finder::in()

src/Symfony/Component/Finder/Exception/AdapterFailureException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespace Symfony\Component\Finder\Exception;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\AdapterFailureException class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Adapter\AdapterInterface;
1517

1618
/**
1719
* Base exception for all adapter failures.
1820
*
1921
* @author Jean-François Simon <[email protected]>
22+
*
23+
* @deprecated since 2.8, to be removed in 3.0.
2024
*/
2125
class AdapterFailureException extends \RuntimeException implements ExceptionInterface
2226
{

src/Symfony/Component/Finder/Exception/OperationNotPermitedException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
namespace Symfony\Component\Finder\Exception;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\OperationNotPermitedException class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
/**
1517
* @author Jean-François Simon <[email protected]>
18+
*
19+
* @deprecated since 2.8, to be removed in 3.0.
1620
*/
1721
class OperationNotPermitedException extends AdapterFailureException
1822
{

src/Symfony/Component/Finder/Exception/ShellCommandFailureException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111

1212
namespace Symfony\Component\Finder\Exception;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\ShellCommandFailureException class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Adapter\AdapterInterface;
1517
use Symfony\Component\Finder\Shell\Command;
1618

1719
/**
1820
* @author Jean-François Simon <[email protected]>
21+
*
22+
* @deprecated since 2.8, to be removed in 3.0.
1923
*/
2024
class ShellCommandFailureException extends AdapterFailureException
2125
{

src/Symfony/Component/Finder/Finder.php

Lines changed: 125 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Finder implements \IteratorAggregate, \Countable
6262
private $iterators = array();
6363
private $contains = array();
6464
private $notContains = array();
65-
private $adapters = array();
65+
private $adapters = null;
6666
private $paths = array();
6767
private $notPaths = array();
6868
private $ignoreUnreadableDirs = false;
@@ -75,13 +75,6 @@ class Finder implements \IteratorAggregate, \Countable
7575
public function __construct()
7676
{
7777
$this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
78-
79-
$this
80-
->addAdapter(new GnuFindAdapter())
81-
->addAdapter(new BsdFindAdapter())
82-
->addAdapter(new PhpAdapter(), -50)
83-
->setAdapter('php')
84-
;
8578
}
8679

8780
/**
@@ -103,9 +96,15 @@ public static function create()
10396
* @param int $priority Highest is selected first
10497
*
10598
* @return Finder The current Finder instance
99+
*
100+
* @deprecated since 2.8, to be removed in 3.0.
106101
*/
107102
public function addAdapter(AdapterInterface $adapter, $priority = 0)
108103
{
104+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
105+
106+
$this->initDefaultAdapters();
107+
109108
$this->adapters[$adapter->getName()] = array(
110109
'adapter' => $adapter,
111110
'priority' => $priority,
@@ -119,9 +118,15 @@ public function addAdapter(AdapterInterface $adapter, $priority = 0)
119118
* Sets the selected adapter to the best one according to the current platform the code is run on.
120119
*
121120
* @return Finder The current Finder instance
121+
*
122+
* @deprecated since 2.8, to be removed in 3.0.
122123
*/
123124
public function useBestAdapter()
124125
{
126+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
127+
128+
$this->initDefaultAdapters();
129+
125130
$this->resetAdapterSelection();
126131

127132
return $this->sortAdapters();
@@ -135,9 +140,15 @@ public function useBestAdapter()
135140
* @throws \InvalidArgumentException
136141
*
137142
* @return Finder The current Finder instance
143+
*
144+
* @deprecated since 2.8, to be removed in 3.0.
138145
*/
139146
public function setAdapter($name)
140147
{
148+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
149+
150+
$this->initDefaultAdapters();
151+
141152
if (!isset($this->adapters[$name])) {
142153
throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name));
143154
}
@@ -152,9 +163,13 @@ public function setAdapter($name)
152163
* Removes all adapters registered in the finder.
153164
*
154165
* @return Finder The current Finder instance
166+
*
167+
* @deprecated since 2.8, to be removed in 3.0.
155168
*/
156169
public function removeAdapters()
157170
{
171+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
172+
158173
$this->adapters = array();
159174

160175
return $this;
@@ -164,9 +179,15 @@ public function removeAdapters()
164179
* Returns registered adapters ordered by priority without extra information.
165180
*
166181
* @return AdapterInterface[]
182+
*
183+
* @deprecated since 2.8, to be removed in 3.0.
167184
*/
168185
public function getAdapters()
169186
{
187+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
188+
189+
$this->initDefaultAdapters();
190+
170191
return array_values(array_map(function (array $adapter) {
171192
return $adapter['adapter'];
172193
}, $this->adapters));
@@ -771,11 +792,7 @@ private function sortAdapters()
771792
}
772793

773794
/**
774-
* @param $dir
775-
*
776795
* @return \Iterator
777-
*
778-
* @throws \RuntimeException When none of the adapters are supported
779796
*/
780797
private function searchInDirectory($dir)
781798
{
@@ -787,18 +804,93 @@ private function searchInDirectory($dir)
787804
$this->notPaths[] = '#(^|/)\..+(/|$)#';
788805
}
789806

790-
foreach ($this->adapters as $adapter) {
791-
if ($adapter['adapter']->isSupported()) {
792-
try {
793-
return $this
794-
->buildAdapter($adapter['adapter'])
795-
->searchInDirectory($dir);
796-
} catch (ExceptionInterface $e) {
807+
if ($this->adapters) {
808+
foreach ($this->adapters as $adapter) {
809+
if ($adapter['adapter']->isSupported()) {
810+
try {
811+
return $this
812+
->buildAdapter($adapter['adapter'])
813+
->searchInDirectory($dir);
814+
} catch (ExceptionInterface $e) {
815+
}
797816
}
798817
}
799818
}
800819

801-
throw new \RuntimeException('No supported adapter found.');
820+
$minDepth = 0;
821+
$maxDepth = PHP_INT_MAX;
822+
823+
foreach ($this->depths as $comparator) {
824+
switch ($comparator->getOperator()) {
825+
case '>':
826+
$minDepth = $comparator->getTarget() + 1;
827+
break;
828+
case '>=':
829+
$minDepth = $comparator->getTarget();
830+
break;
831+
case '<':
832+
$maxDepth = $comparator->getTarget() - 1;
833+
break;
834+
case '<=':
835+
$maxDepth = $comparator->getTarget();
836+
break;
837+
default:
838+
$minDepth = $maxDepth = $comparator->getTarget();
839+
}
840+
}
841+
842+
$flags = \RecursiveDirectoryIterator::SKIP_DOTS;
843+
844+
if ($this->followLinks) {
845+
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
846+
}
847+
848+
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
849+
850+
if ($this->exclude) {
851+
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
852+
}
853+
854+
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
855+
856+
if ($minDepth > 0 || $maxDepth < PHP_INT_MAX) {
857+
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $minDepth, $maxDepth);
858+
}
859+
860+
if ($this->mode) {
861+
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
862+
}
863+
864+
if ($this->names || $this->notNames) {
865+
$iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
866+
}
867+
868+
if ($this->contains || $this->notContains) {
869+
$iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
870+
}
871+
872+
if ($this->sizes) {
873+
$iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
874+
}
875+
876+
if ($this->dates) {
877+
$iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
878+
}
879+
880+
if ($this->filters) {
881+
$iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
882+
}
883+
884+
if ($this->paths || $this->notPaths) {
885+
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
886+
}
887+
888+
if ($this->sort) {
889+
$iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
890+
$iterator = $iteratorAggregate->getIterator();
891+
}
892+
893+
return $iterator;
802894
}
803895

804896
/**
@@ -837,4 +929,17 @@ private function resetAdapterSelection()
837929
return $properties;
838930
}, $this->adapters);
839931
}
932+
933+
private function initDefaultAdapters()
934+
{
935+
if (null === $this->adapters) {
936+
$this->adapters = array();
937+
$this
938+
->addAdapter(new GnuFindAdapter())
939+
->addAdapter(new BsdFindAdapter())
940+
->addAdapter(new PhpAdapter(), -50)
941+
->setAdapter('php')
942+
;
943+
}
944+
}
840945
}

0 commit comments

Comments
 (0)