Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • AbstractAdapter
  • AbstractFindAdapter
  • BsdFindAdapter
  • GnuFindAdapter
  • PhpAdapter

Interfaces

  • AdapterInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  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: 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:  * Shell engine implementation using BSD find command.
 21:  *
 22:  * @author Jean-François Simon <contact@jfsimon.fr>
 23:  */
 24: class BsdFindAdapter extends AbstractFindAdapter
 25: {
 26:     /**
 27:      * {@inheritdoc}
 28:      */
 29:     public function getName()
 30:     {
 31:         return 'bsd_find';
 32:     }
 33: 
 34:     /**
 35:      * {@inheritdoc}
 36:      */
 37:     protected function canBeUsed()
 38:     {
 39:         return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
 40:     }
 41: 
 42:     /**
 43:      * {@inheritdoc}
 44:      */
 45:     protected function buildFormatSorting(Command $command, $sort)
 46:     {
 47:         switch ($sort) {
 48:             case SortableIterator::SORT_BY_NAME:
 49:                 $command->ins('sort')->add('| sort');
 50: 
 51:                 return;
 52:             case SortableIterator::SORT_BY_TYPE:
 53:                 $format = '%HT';
 54:                 break;
 55:             case SortableIterator::SORT_BY_ACCESSED_TIME:
 56:                 $format = '%a';
 57:                 break;
 58:             case SortableIterator::SORT_BY_CHANGED_TIME:
 59:                 $format = '%c';
 60:                 break;
 61:             case SortableIterator::SORT_BY_MODIFIED_TIME:
 62:                 $format = '%m';
 63:                 break;
 64:             default:
 65:                 throw new \InvalidArgumentException('Unknown sort options: '.$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: 
 74:     /**
 75:      * {@inheritdoc}
 76:      */
 77:     protected function buildFindCommand(Command $command, $dir)
 78:     {
 79:         parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);
 80: 
 81:         return $command;
 82:     }
 83: 
 84:     /**
 85:      * {@inheritdoc}
 86:      */
 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: }
104: 
php-coveralls API documentation generated by ApiGen 2.8.0