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__.'\BsdFindAdapter 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 BSD 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 BsdFindAdapter extends AbstractFindAdapter
33 public function getName()
41 protected function canBeUsed()
43 return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
49 protected function buildFormatSorting(Command $command, $sort)
52 case SortableIterator::SORT_BY_NAME:
53 $command->ins('sort')->add('| sort');
56 case SortableIterator::SORT_BY_TYPE:
59 case SortableIterator::SORT_BY_ACCESSED_TIME:
62 case SortableIterator::SORT_BY_CHANGED_TIME:
65 case SortableIterator::SORT_BY_MODIFIED_TIME:
69 throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
73 ->add('-print0 | xargs -0 stat -f')
75 ->add('| sort | cut -f 2');
81 protected function buildFindCommand(Command $command, $dir)
83 parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);
91 protected function buildContentFiltering(Command $command, array $contains, $not = false)
93 foreach ($contains as $contain) {
94 $expr = Expression::create($contain);
96 // todo: avoid forking process for each $pattern by using multiple -e options
98 ->add('| grep -v \'^$\'')
99 ->add('| xargs -I{} grep -I')
100 ->add($expr->isCaseSensitive() ? null : '-i')
101 ->add($not ? '-L' : '-l')
102 ->add('-Ee')->arg($expr->renderPattern())