[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/finder/Adapter/ -> BsdFindAdapter.php (source)

   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  
  14  @trigger_error('The '.__NAMESPACE__.'\BsdFindAdapter class is deprecated since Symfony 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED);
  15  
  16  use Symfony\Component\Finder\Expression\Expression;
  17  use Symfony\Component\Finder\Iterator\SortableIterator;
  18  use Symfony\Component\Finder\Shell\Command;
  19  use Symfony\Component\Finder\Shell\Shell;
  20  
  21  /**
  22   * Shell engine implementation using BSD find command.
  23   *
  24   * @author Jean-François Simon <contact@jfsimon.fr>
  25   *
  26   * @deprecated since 2.8, to be removed in 3.0. Use Finder instead.
  27   */
  28  class BsdFindAdapter extends AbstractFindAdapter
  29  {
  30      /**
  31       * {@inheritdoc}
  32       */
  33      public function getName()
  34      {
  35          return 'bsd_find';
  36      }
  37  
  38      /**
  39       * {@inheritdoc}
  40       */
  41      protected function canBeUsed()
  42      {
  43          return \in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
  44      }
  45  
  46      /**
  47       * {@inheritdoc}
  48       */
  49      protected function buildFormatSorting(Command $command, $sort)
  50      {
  51          switch ($sort) {
  52              case SortableIterator::SORT_BY_NAME:
  53                  $command->ins('sort')->add('| sort');
  54  
  55                  return;
  56              case SortableIterator::SORT_BY_TYPE:
  57                  $format = '%HT';
  58                  break;
  59              case SortableIterator::SORT_BY_ACCESSED_TIME:
  60                  $format = '%a';
  61                  break;
  62              case SortableIterator::SORT_BY_CHANGED_TIME:
  63                  $format = '%c';
  64                  break;
  65              case SortableIterator::SORT_BY_MODIFIED_TIME:
  66                  $format = '%m';
  67                  break;
  68              default:
  69                  throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
  70          }
  71  
  72          $command
  73              ->add('-print0 | xargs -0 stat -f')
  74              ->arg($format.'%t%N')
  75              ->add('| sort | cut -f 2');
  76      }
  77  
  78      /**
  79       * {@inheritdoc}
  80       */
  81      protected function buildFindCommand(Command $command, $dir)
  82      {
  83          parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);
  84  
  85          return $command;
  86      }
  87  
  88      /**
  89       * {@inheritdoc}
  90       */
  91      protected function buildContentFiltering(Command $command, array $contains, $not = false)
  92      {
  93          foreach ($contains as $contain) {
  94              $expr = Expression::create($contain);
  95  
  96              // todo: avoid forking process for each $pattern by using multiple -e options
  97              $command
  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())
 103                  ->add('{}')
 104              ;
 105          }
 106      }
 107  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1