protected function ensureProjectRoot() { if (!($this->rootDir = $this->input->getOption('project-root'))) { $this->rootDir = getcwd(); } $this->rootDir = realpath($this->rootDir); $this->fs->mkdir($this->rootDir); $finder = new Finder(); $finder->in($this->rootDir); $finder->depth(0); $finder->ignoreVCS(false); $rootFiles = []; /** @var SplFileInfo $splInfo */ foreach ($finder as $splInfo) { $rootFiles[] = $splInfo->getFilename(); } $requiredFiles = ['composer.json', 'composer.lock']; $requiredDirs = ['vendor']; foreach (array_merge($requiredFiles, $requiredDirs) as $file) { if (!in_array($file, $rootFiles)) { // possibly not root $this->output->writeln("<error>You should either run this script under your project root directory, or provide the '--project-root' option.</error>"); $this->output->writeln("The project root directory should contain at least the following files and directories:"); foreach ($requiredFiles as $requiredFile) { $this->output->writeln("\t- <comment>{$requiredFile}</comment>"); } foreach ($requiredDirs as $requiredDir) { $this->output->writeln("\t- <comment>{$requiredDir}/</comment>"); } exit(1); } } }
private function getHookDestinations($searchAt) { $finder = new Finder(); foreach ($searchAt as $location) { $finder->in(__DIR__ . '/../../..' . $location); } return $finder->ignoreVCS(false)->ignoreDotFiles(false)->exclude('vendor')->path('/\\.git\\/hooks$/'); }
/** * Returns a Finder instance for the files that will be included in the * backup. * * By default we ignore unreadable files and directories as well as, common * version control folders / files, "Dot" files and anything matching the * exclude rules. * * @uses Finder * @return Finder The Finder iterator of all files to be included */ public function get_files() { $finder = new Finder(); $finder->followLinks(true); $finder->ignoreDotFiles(false); $finder->ignoreVCS(true); $finder->ignoreUnreadableDirs(true); // Skip unreadable files too $finder->filter(function (\SplFileInfo $file) { if (!$file->isReadable()) { return false; } }); // Finder expects exclude rules to be in a regex format $exclude_rules = $this->excludes->get_excludes_for_regex(); // Skips folders/files that match default exclude patterns foreach ($exclude_rules as $exclude) { $finder->notPath($exclude); } return $finder->in(Path::get_root()); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var ConsoleApplication $console */ $console = $this->getApplication(); $slimapp = $console->getSlimapp(); $cacheDirs = [$slimapp->getConfigCachePath()]; $httpCacheDirs = $slimapp->getHttpKernel()->getCacheDirectories(); $cacheDirs = array_merge($cacheDirs, $httpCacheDirs); foreach ($cacheDirs as $dir) { $output->writeln(sprintf('<comment>removing cache in %s ...</comment>', $dir)); $fs = new Filesystem(); $finder = new Finder(); $finder->in($dir); $finder->depth(0); $finder->ignoreVCS(false); /** @var SplFileInfo $splInfo */ foreach ($finder as $splInfo) { $output->writeln(sprintf("removing file: %s", $splInfo->getPathname()), OutputInterface::VERBOSITY_VERBOSE); $fs->remove($splInfo->getPathname()); } $output->writeln(sprintf('<info>done.</info>', $dir)); } }
/** * @param OutputInterface $output * @return void */ protected function cleanCustom(OutputInterface $output) { if (empty($this->options['custom'])) { return; } foreach ($this->options['custom'] as $options) { try { $finder = new Finder(); $finder->ignoreDotFiles(false); $finder->ignoreVCS(false); $finder->ignoreUnreadableDirs(true); $in = []; if (!is_array($options['in'])) { $options['in'] = [$options['in']]; } foreach ($options['in'] as $dir) { $in[] = $this->baseDir . $dir; } $finder->in($in); if (!empty($options['type'])) { switch ($options['type']) { case 'files': $finder->files(); break; case 'dirs': case 'directories': $finder->directories(); break; } } if (!empty($options['notName'])) { if (!is_array($options['notName'])) { $options['notName'] = [$options['notName']]; } foreach ($options['notName'] as $notName) { $finder->notName($notName); } } if (!empty($options['name'])) { if (!is_array($options['name'])) { $options['name'] = [$options['name']]; } foreach ($options['name'] as $notName) { $finder->name($notName); } } if (!empty($options['depth'])) { $finder->depth($options['depth']); } foreach ($finder as $file) { $this->files[] = $file->getRealPath(); } } catch (\Exception $e) { // ignore errors } } }
public function testIgnoreVCS() { $finder = new Finder(); $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false)); $this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = new Finder(); $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false); $this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = new Finder(); $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false)); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator()); }
private function installThemeFiles(PackageInterface $package) { $theme = $this->findTheme($package); if (!$theme) { return; } $themeSource = $this->composer->getInstallationManager()->getInstallPath($package); $themeTarget = $theme['installation-path']; $this->filesystem->ensureDirectoryExists($themeTarget); $finder = new Finder(); $files = $finder->ignoreVCS(true)->in($themeSource); foreach ($files as $file) { $targetPath = $themeTarget . DIRECTORY_SEPARATOR . $file->getRelativePathname(); if ($file->isDir()) { $this->filesystem->ensureDirectoryExists($targetPath); } else { copy($file->getPathname(), $targetPath); } } }
/** * @return Finder */ public function getFixturesDirectories() { return $this->finder->ignoreVCS(true)->ignoreDotFiles(true)->depth('<= 5')->directories()->in($this->fixturesParentDirectory)->name('DataFixtures'); }
/** * Extract style package to demo board. * * @return null */ public function extract_package() { $this->package->ensure_extracted(); $package_root = $this->package->find_directory(array('files' => array('required' => 'style.cfg'))); $style_root = $this->get_style_dir(); $filesystem = new \Symfony\Component\Filesystem\Filesystem(); $filesystem->remove($style_root); // Only copy necessary files $finder = new Finder(); $finder->ignoreVCS(false)->ignoreDotFiles(false)->files()->notName('/\\.(svg|png|jpe?g|gif|html|js|css|cfg)$/i')->in($this->package->get_temp_path()); $filesystem->remove($finder); $filesystem->rename($this->package->get_temp_path() . '/' . $package_root, $style_root); }
protected function exportViewNode($view, $node) { $this->node = $node; $fs = new Filesystem(); $container = $this->get('kernel')->getContainer(); $bundle = $this->get('kernel')->getBundle('EUREKAG6KBundle', true); $viewdir = $bundle->getPath() . "/Resources/views"; $publicdir = $bundle->getPath() . "/Resources/public"; $nodePath = $this->searchNodePath($viewdir, $publicdir, $view); $content = array(); if ($nodePath != '') { $finder = new Finder(); $finder->ignoreVCS(true)->files()->in($nodePath)->sortByName(); foreach ($finder as $file) { $content[] = array('name' => $file->getRelativePathname(), 'data' => file_get_contents($file->getRealPath()), 'modtime' => $file->getMTime()); } } $filename = $node == 1 ? $view . "-templates" : $view . "-assets"; $zipcontent = $this->zip($content); $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', 'application/octet-stream'); $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename . ".zip")); $response->headers->set('Content-length', strlen($zipcontent)); $response->sendHeaders(); $response->setContent($zipcontent); return $response; }
/** * @return Finder */ public function ignoreVCS($ignoreVCS) { return parent::ignoreVCS($ignoreVCS); }