4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Adapter;
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);
16 use Symfony\Component\Finder\Shell\Shell;
17 use Symfony\Component\Finder\Shell\Command;
18 use Symfony\Component\Finder\Iterator\SortableIterator;
19 use Symfony\Component\Finder\Expression\Expression;
22 * Shell engine implementation using GNU find command.
24 * @author Jean-François Simon <contact@jfsimon.fr>
26 * @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
28 class GnuFindAdapter extends AbstractFindAdapter
33 public function getName()
41 protected function buildFormatSorting(Command $command, $sort)
44 case SortableIterator::SORT_BY_NAME:
45 $command->ins('sort')->add('| sort');
48 case SortableIterator::SORT_BY_TYPE:
51 case SortableIterator::SORT_BY_ACCESSED_TIME:
54 case SortableIterator::SORT_BY_CHANGED_TIME:
57 case SortableIterator::SORT_BY_MODIFIED_TIME:
61 throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
67 ->arg($format.' %h/%f\\n')
77 protected function canBeUsed()
79 return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed();
85 protected function buildFindCommand(Command $command, $dir)
87 return parent::buildFindCommand($command, $dir)->add('-regextype posix-extended');
93 protected function buildContentFiltering(Command $command, array $contains, $not = false)
95 foreach ($contains as $contain) {
96 $expr = Expression::create($contain);
98 // todo: avoid forking process for each $pattern by using multiple -e options
100 ->add('| xargs -I{} -r grep -I')
101 ->add($expr->isCaseSensitive() ? null : '-i')
102 ->add($not ? '-L' : '-l')
103 ->add('-Ee')->arg($expr->renderPattern())