TYPO3  7.6
BsdFindAdapter.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 'bsd_find';
32  }
33 
37  protected function canBeUsed()
38  {
39  return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
40  }
41 
45  protected function buildFormatSorting(Command $command, $sort)
46  {
47  switch ($sort) {
49  $command->ins('sort')->add('| sort');
50 
51  return;
53  $format = '%HT';
54  break;
56  $format = '%a';
57  break;
59  $format = '%c';
60  break;
62  $format = '%m';
63  break;
64  default:
65  throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
66  }
67 
68  $command
69  ->add('-print0 | xargs -0 stat -f')
70  ->arg($format.'%t%N')
71  ->add('| sort | cut -f 2');
72  }
73 
77  protected function buildFindCommand(Command $command, $dir)
78  {
79  parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);
80 
81  return $command;
82  }
83 
87  protected function buildContentFiltering(Command $command, array $contains, $not = false)
88  {
89  foreach ($contains as $contain) {
90  $expr = Expression::create($contain);
91 
92  // todo: avoid forking process for each $pattern by using multiple -e options
93  $command
94  ->add('| grep -v \'^$\'')
95  ->add('| xargs -I{} grep -I')
96  ->add($expr->isCaseSensitive() ? null : '-i')
97  ->add($not ? '-L' : '-l')
98  ->add('-Ee')->arg($expr->renderPattern())
99  ->add('{}')
100  ;
101  }
102  }
103 }