/** * Initializes the internal Symfony Finder with appropriate filters * * @param string $sources Path to source files to be archived * @param array $excludes Composer's own exclude rules from composer.json */ public function __construct($sources, array $excludes) { $fs = new Filesystem(); $sources = $fs->normalizePath($sources); $filters = array(new HgExcludeFilter($sources), new GitExcludeFilter($sources), new ComposerExcludeFilter($sources, $excludes)); $this->finder = new Finder\Finder(); $this->finder->in($sources)->filter(function (\SplFileInfo $file) use($sources, $filters, $fs) { $relativePath = preg_replace('#^' . preg_quote($sources, '#') . '#', '', $fs->normalizePath($file->getRealPath())); $exclude = false; foreach ($filters as $filter) { $exclude = $filter->filter($relativePath, $exclude); } return !$exclude; })->ignoreVCS(true)->ignoreDotFiles(false); parent::__construct($this->finder->getIterator()); }
/** * Initializes the internal Symfony Finder with appropriate filters * * @param string $sources Path to source files to be archived * @param array $excludes Composer's own exclude rules from composer.json */ public function __construct($sources, array $excludes) { $fs = new Filesystem(); $sources = $fs->normalizePath($sources); $filters = array(new HgExcludeFilter($sources), new GitExcludeFilter($sources), new ComposerExcludeFilter($sources, $excludes)); $this->finder = new Finder\Finder(); $filter = function (\SplFileInfo $file) use($sources, $filters, $fs) { if ($file->isLink() && strpos($file->getLinkTarget(), $sources) !== 0) { return false; } $relativePath = preg_replace('#^' . preg_quote($sources, '#') . '#', '', $fs->normalizePath($file->getRealPath())); $exclude = false; foreach ($filters as $filter) { $exclude = $filter->filter($relativePath, $exclude); } return !$exclude; }; if (method_exists($filter, 'bindTo')) { $filter = $filter->bindTo(null); } $this->finder->in($sources)->filter($filter)->ignoreVCS(true)->ignoreDotFiles(false); parent::__construct($this->finder->getIterator()); }
/** * @param $directory * @param array $exclude * @param array $pattern * * @return Translations */ public function fromDirectory($directory, $translations = null, $exclude = ['languages'], $pattern = ['*.php', '*.phtml']) { if (!$translations) { $translations = new Translations(); } // fetch strings $sourcesFinder = new \Symfony\Component\Finder\Finder(); $sourcesFinder->files()->in($directory)->exclude($exclude); foreach ($pattern as $filePattern) { $sourcesFinder->name($filePattern); } $sourcesList = iterator_to_array($sourcesFinder->getIterator()); $sourcesList = array_map('strval', $sourcesList); foreach ($sourcesList as $sourceFile) { $this->fromFile($sourceFile, $translations); } return $translations; }