1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Finder\Adapter;
13:
14: use Symfony\Component\Finder\Shell\Shell;
15: use Symfony\Component\Finder\Shell\Command;
16: use Symfony\Component\Finder\Iterator\SortableIterator;
17: use Symfony\Component\Finder\Expression\Expression;
18:
19: 20: 21: 22: 23:
24: class GnuFindAdapter extends AbstractFindAdapter
25: {
26: 27: 28:
29: public function getName()
30: {
31: return 'gnu_find';
32: }
33:
34: 35: 36:
37: protected function buildFormatSorting(Command $command, $sort)
38: {
39: switch ($sort) {
40: case SortableIterator::SORT_BY_NAME:
41: $command->ins('sort')->add('| sort');
42:
43: return;
44: case SortableIterator::SORT_BY_TYPE:
45: $format = '%y';
46: break;
47: case SortableIterator::SORT_BY_ACCESSED_TIME:
48: $format = '%A@';
49: break;
50: case SortableIterator::SORT_BY_CHANGED_TIME:
51: $format = '%C@';
52: break;
53: case SortableIterator::SORT_BY_MODIFIED_TIME:
54: $format = '%T@';
55: break;
56: default:
57: throw new \InvalidArgumentException('Unknown sort options: '.$sort.'.');
58: }
59:
60: $command
61: ->get('find')
62: ->add('-printf')
63: ->arg($format.' %h/%f\\n')
64: ->add('| sort | cut')
65: ->arg('-d ')
66: ->arg('-f2-')
67: ;
68: }
69:
70: 71: 72:
73: protected function canBeUsed()
74: {
75: return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed();
76: }
77:
78: 79: 80:
81: protected function buildFindCommand(Command $command, $dir)
82: {
83: return parent::buildFindCommand($command, $dir)->add('-regextype posix-extended');
84: }
85:
86: 87: 88:
89: protected function buildContentFiltering(Command $command, array $contains, $not = false)
90: {
91: foreach ($contains as $contain) {
92: $expr = Expression::create($contain);
93:
94:
95: $command
96: ->add('| xargs -I{} -r grep -I')
97: ->add($expr->isCaseSensitive() ? null : '-i')
98: ->add($not ? '-L' : '-l')
99: ->add('-Ee')->arg($expr->renderPattern())
100: ->add('{}')
101: ;
102: }
103: }
104: }
105: