TYPO3  7.6
GnuFindAdapter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Finder\Adapter;
13 
18 
25 {
29  public function getName()
30  {
31  return 'gnu_find';
32  }
33 
37  protected function buildFormatSorting(Command $command, $sort)
38  {
39  switch ($sort) {
41  $command->ins('sort')->add('| sort');
42 
43  return;
45  $format = '%y';
46  break;
48  $format = '%A@';
49  break;
51  $format = '%C@';
52  break;
54  $format = '%T@';
55  break;
56  default:
57  throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $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 
73  protected function canBeUsed()
74  {
75  return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed();
76  }
77 
81  protected function buildFindCommand(Command $command, $dir)
82  {
83  return parent::buildFindCommand($command, $dir)->add('-regextype posix-extended');
84  }
85 
89  protected function buildContentFiltering(Command $command, array $contains, $not = false)
90  {
91  foreach ($contains as $contain) {
92  $expr = Expression::create($contain);
93 
94  // todo: avoid forking process for each $pattern by using multiple -e options
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 }