public function tearDown() { // Delete local files $finder = new Finder(); $fs = new Filesystem(); $fs->remove($finder->files()->in($this->tmpDir . "/download")); $fs->remove($finder->files()->in($this->tmpDir)); $fs->remove($this->tmpDir . "/download"); $fs->remove($this->tmpDir); // Delete file uploads $options = new ListFilesOptions(); $options->setTags(["docker-bundle-test"]); $files = $this->client->listFiles($options); foreach ($files as $file) { $this->client->deleteFile($file["id"]); } if ($this->client->bucketExists("in.c-docker-test")) { // Delete tables foreach ($this->client->listTables("in.c-docker-test") as $table) { $this->client->dropTable($table["id"]); } // Delete bucket $this->client->dropBucket("in.c-docker-test"); } if ($this->client->bucketExists("in.c-docker-test-redshift")) { // Delete tables foreach ($this->client->listTables("in.c-docker-test-redshift") as $table) { $this->client->dropTable($table["id"]); } // Delete bucket $this->client->dropBucket("in.c-docker-test-redshift"); } }
/** * Process a build set * @param object $set The build configuration set * @return array Returns the complete process set * @since 1.1.0 */ public function process() { $result = array(); if (property_exists($this->set, 'processor')) { $this->processor += $this->pushProcessor($this->set->processor); $result[] = new Stack($this->processor); } foreach ($this->set->build as $entry) { if (is_object($entry)) { $subManager = new BuildManager($entry, $this->processor); $result = array_merge($result, $subManager->process()); $result[] = new Stack($this->processor); } else { $find = new Finder(); if (is_dir($entry)) { $find->files()->in($entry); } elseif (is_file($entry)) { $find->files()->depth('== 0')->name(basename($entry))->in(dirname($entry)); } else { $find = array(); } foreach ($find as $file) { $result[] = $file; } } } return $result; }
/** * @Route("/search") */ public function searchAction(Request $request) { $search = new FileSearch(); $dirList = $this->generateDirList(); $form = $this->createForm(SearchType::class, $search, array('dir_list' => $dirList)); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $searchFor = $form->get('searchFor')->getData(); $fileType = $form->get('fileType')->getData(); $searchDir = $form->get('searchDir')->getData(); $finder = new Finder(); if (isset($fileType)) { $finder->files()->name("*.{$fileType}"); } if (isset($searchDir)) { $finder->files()->in($searchDir); } else { $finder->files()->in(__DIR__); } if (isset($searchFor)) { $finder->contains($searchFor); } if (isset($finder) && count($finder) > 0) { echo "<h3>Found results in {$searchDir}: </h3><br/>"; foreach ($finder as $key => $value) { echo "<h4> {$value} contains '{$searchFor}' </h4>"; } } else { echo "No content '{$searchFor}' in '{$searchDir}'"; } } return $this->render('MihailSearchBundle:randomsearch:search_form.html.twig', array('form' => $form->createView())); }
protected function warmup($warmupDir) { $this->getContainer()->get('filesystem')->remove($warmupDir); $parent = $this->getContainer()->get('kernel'); $class = get_class($parent); $namespace = ''; if (false !== ($pos = strrpos($class, '\\'))) { $namespace = substr($class, 0, $pos); $class = substr($class, $pos + 1); } $kernel = $this->getTempKernel($parent, $namespace, $class, $warmupDir); $kernel->boot(); $warmer = $kernel->getContainer()->get('cache_warmer'); $warmer->enableOptionalWarmers(); $warmer->warmUp($warmupDir); // fix container files and classes $regex = '/' . preg_quote($this->getTempKernelSuffix(), '/') . '/'; $finder = new Finder(); foreach ($finder->files()->name(get_class($kernel->getContainer()) . '*')->in($warmupDir) as $file) { $content = file_get_contents($file); $content = preg_replace($regex, '', $content); file_put_contents(preg_replace($regex, '', $file), $content); unlink($file); } // fix meta references to the Kernel foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) { $content = preg_replace('/C\\:\\d+\\:"' . preg_quote($class . $this->getTempKernelSuffix(), '"/') . '"/', sprintf('C:%s:"%s"', strlen($class), $class), file_get_contents($file)); file_put_contents($file, $content); } }
public function loadResource($language, $directoryRoot) { $this->language = $language; $this->translator = new Translator($this->language); $this->addLoader(new ArrayLoader(), 'array'); $this->addLoader(new YamlFileLoader(), 'yaml'); $finder = new Finder(); // Fetch all language files for translation try { $finder->files()->name('*.yml')->in($directoryRoot . 'config/translations/' . $language); } catch (Exception $e) { if ($language != 'en') { $finder->files()->name('*.yml')->in($directoryRoot . 'config/translations/en'); } } foreach ($finder as $file) { $resource = $file->getRealpath(); $filename = $file->getBasename('.yml'); // Handle application file different than commands if ($filename == 'application') { $this->writeTranslationByFile($resource, 'application'); } else { $key = 'commands.' . $filename; $this->writeTranslationByFile($resource, $key); } } }
/** * @param string $repository * @param PriorityHandlerInterface $priorityHandler * @param Filesystem $fs * @param Finder $finder * @param LockHandlerFactoryInterface $lockHandlerFactory */ public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null) { if (empty($repository)) { throw new InvalidArgumentException('Argument repository empty or not defined.'); } if (null === $fs) { $fs = new Filesystem(); } if (null === $finder) { $finder = new Finder(); } if (null === $lockHandlerFactory) { $lockHandlerFactory = new LockHandlerFactory(); } if (null === $priorityHandler) { $priorityHandler = new StandardPriorityHandler(); } $this->fs = $fs; if (!$this->fs->exists($repository)) { try { $this->fs->mkdir($repository); } catch (IOExceptionInterface $e) { throw new InvalidArgumentException('An error occurred while creating your directory at ' . $e->getPath()); } } $this->priorityHandler = $priorityHandler; $this->repository = $repository; $this->finder = $finder; $this->finder->files()->in($repository); $this->lockHandlerFactory = $lockHandlerFactory; return $this; }
/** * Get the file list as an iterator. * * @since 1.0.0 * @access public */ public function get_file_list_as_iterator() { //Get the files in the provided path $this->finder->files()->in($this->path); //Return the iterator return $this->finder; }
/** * Create a map for a given path * * @param array $paths * @return array */ public function createMap(...$paths) { $classes = []; $this->finder->files()->ignoreUnreadableDirs()->in($paths); foreach ($this->excludePathPatterns as $exclude) { $this->finder->notPath($exclude); } foreach ($this->inPathPatterns as $inPath) { $this->finder->path($inPath); } foreach ($this->names as $name) { $this->finder->name($name); } /** @var SplFileInfo $file */ foreach ($this->finder as $file) { $content = file_get_contents($file->getPathname()); preg_match('^\\s*class ([\\S]*)\\s*(extends|implements|{)^', $content, $match, PREG_OFFSET_CAPTURE); if (isset($match[1])) { $className = '\\' . trim($match[1][0]); $offset = $match[1][1]; } else { continue; } preg_match('|\\s*namespace\\s*([\\S]*)\\s*;|', substr($content, 0, $offset), $match); if (isset($match[1]) && trim($match[1]) !== '') { $className = '\\' . trim($match[1]) . $className; } if ($className !== '\\') { $classes[$file->getPathname()] = $className; } } return $classes; }
/** * {@inheritdoc} */ public function load($resource) { $files = $this->finder->files()->name('*.php')->ignoreDotFiles(true)->ignoreUnreadableDirs(true)->ignoreUnreadableDirs(true)->in($resource); if (0 === $files->count()) { throw new \InvalidArgumentException(sprintf('%s doesnt contains any php files', $resource)); } return $this->parseFiles($files->getIterator()); }
protected function syncTranslations($io, $language = null, $languages, $file, $appRoot) { $englishFilesFinder = new Finder(); $yaml = new Parser(); $dumper = new Dumper(); $englishDirectory = $appRoot . 'config/translations/en'; if ($file) { $englishFiles = $englishFilesFinder->files()->name($file)->in($englishDirectory); } else { $englishFiles = $englishFilesFinder->files()->name('*.yml')->in($englishDirectory); } foreach ($englishFiles as $file) { $resource = $englishDirectory . '/' . $file->getBasename(); $filename = $file->getBasename('.yml'); try { $englishFile = file_get_contents($resource); $englishFileParsed = $yaml->parse($englishFile); } catch (ParseException $e) { $io->error($filename . '.yml: ' . $e->getMessage()); continue; } foreach ($languages as $langCode => $languageName) { $languageDir = $appRoot . 'config/translations/' . $langCode; if (isset($language) && $langCode != $language) { continue; } if (!isset($statistics[$langCode])) { $statistics[$langCode] = ['total' => 0, 'equal' => 0, 'diff' => 0]; } $resourceTranslated = $languageDir . '/' . $file->getBasename(); if (!file_exists($resourceTranslated)) { file_put_contents($resourceTranslated, $englishFile); $io->info(sprintf($this->trans('commands.translation.sync.messages.created-file'), $file->getBasename(), $languageName)); continue; } try { //print $resourceTranslated . "\n"; $resourceTranslatedParsed = $yaml->parse(file_get_contents($resourceTranslated)); } catch (ParseException $e) { $io->error($resourceTranslated . ':' . $e->getMessage()); continue; } $resourceTranslatedParsed = array_replace_recursive($englishFileParsed, $resourceTranslatedParsed); try { $resourceTranslatedParsedYaml = $dumper->dump($resourceTranslatedParsed, 10); } catch (\Exception $e) { $io->error(sprintf($this->trans('commands.translation.sync.messages.error-generating'), $resourceTranslated, $languageName, $e->getMessage())); continue; } try { file_put_contents($resourceTranslated, $resourceTranslatedParsedYaml); } catch (\Exception $e) { $io->error(sprintf('%s: %s', $this->trans('commands.translation.sync.messages.error-writing'), $resourceTranslated, $languageName, $e->getMessage())); return 1; } } } }
/** * {@inheritDoc} */ public function collect() : AssetCollection { $files = []; $this->finder->files()->ignoreDotFiles(false)->in((string) $this->srcDir)->name('/\\.txt$/')->sortByType(); foreach ($this->finder as $file) { $files[] = new TextFile(new File($file->getPathname()), $this->filesystem, dirname(Path::makeRelative($file->getPathname(), (string) $this->srcDir))); } return new AssetCollection($files); }
/** * {@inheritdoc} */ public function load(ClassMetadata $metadata, ParserInterface $parser) { $this->finder->files()->in($this->dir); $content = array(); foreach ($this->finder as $file) { $content[] = $parser->parse($metadata, $file->getRelativePathname(), $file->getContents()); } return $content; }
/** * {@inheritDoc} */ public function collect() : AssetCollection { $templates = []; $this->finder->files()->ignoreDotFiles(false)->in((string) $this->srcDir)->name('/\\.twig$/')->sortByType(); foreach ($this->finder as $template) { $templates[] = new TwigTemplateFile(Path::makeRelative($template->getPathname(), (string) $this->srcDir), $this->twigData, $this->twig, $this->filesystem); } return new AssetCollection($templates); }
public function getFiles() { $files = []; foreach ($this->finder->files()->name('*.php')->in($this->configPath) as $file) { $nesting = $this->getConfigurationNesting($file); $files[$nesting . basename($file->getRealPath(), '.php')] = $file->getRealPath(); } return $files; }
public function getIterator() { $files = array(); foreach ($this->finder->files() as $file) { $item = new StorageSelection(new \SplFileInfo($file), $file->getFilename(), $file->getFilename()); $files[] = $item; } return new \ArrayIterator($files); }
protected function execute(InputInterface $input, OutputInterface $output) { $finder = new Finder(); $finder->files()->in(__DIR__ . '/../Resources/public/')->name('/(js$)|(css$)/')->sortByName(); foreach ($finder->files() as $file) { unlink($file->getRealPath()); $output->writeln('<comment>Delete ' . $file->getFilename() . '</comment>'); } $output->writeln('<info>Success every files had been removed</info>'); }
/** * @Then /^I should get no file$/ */ public function iShouldGetNoFile() { $finder = new Finder(); $finder->files()->in(__DIR__ . '/../../Resources/public/')->name('/(css$)|(js$)/'); $assert = true; foreach ($finder->files() as $key => $value) { $assert = false; break; } assertTrue($assert); }
/** * @param Event $event */ public function run(Event $event) { $result = array(); $this->finder->files()->ignoreDotFiles(false)->name($this->moduleContainer->getFilename())->in($this->moduleContainer->getPath()); /** @var SplFileInfo $file */ foreach ($this->finder as $file) { $moduleInfo = $this->parser->extractRegisterInformation($file); $result[$moduleInfo['namespace']] = $moduleInfo['source_dir']; } $this->dumper->dumpAutoloadPsr4($result); $this->dumper->dumpModulesInstalled($this->parser); }
/** * @param string $dir The base directory * @param \Symfony\Component\Finder\Finder $finder The finder instance to be used. If none is given a new will be * created */ public function __construct($dir, Finder $finder = null) { if (!is_dir($dir) || !is_readable($dir)) { throw new RuntimeException(sprintf('"%s" is not a valid directory', $dir)); } if ($finder === null) { $this->finder = new Finder(); } else { $this->finder = $finder; } $this->finder->files()->in($dir)->ignoreDotFiles(true)->ignoreVCS(true); }
protected function _loadFiles() { if (!$this->_finder) { $this->_setFinder(); } $this->writeln('Loading files from ' . self::FILE_LOCATION); foreach ($this->_finder->files()->in(self::FILE_LOCATION) as $file) { $this->_files[] = new File($file); $this->writeln('Found <info>' . $file->getRealPath() . '</info>'); } $this->writeln(count($this->_files) . ' files found'); return $this; }
/** * * $type = image || sound */ public function getFiles($type) { $finder = new Finder(); if ($type == 'image') { $finder->files()->name('*.jpg')->name('*.png')->in(__DIR__ . "/../../../web/uploads/"); } else { $finder->files()->name('*.mp3')->name('*.wav')->in(__DIR__ . "/../../../web/uploads/"); } $return = array(); foreach ($finder as $file) { $return[$file->getBasename()] = $file->getBasename(); } return $return; }
/** * Check a given directory recursively if all files are writeable. * * @throws \Exception * * @return bool */ protected function hasCorrectPermissionForUpdate() : bool { if (!$this->pathToUpdate) { throw new \Exception('No directory set for update. Please set the update with: setPathToUpdate(path).'); } $collection = collect($this->pathToUpdate->files())->each(function ($file) { /* @var \SplFileInfo $file */ if (!File::isWritable($file->getRealPath())) { event(new HasWrongPermissions($this)); return false; } }); return true; }
/** * Search on views folder for templates * * @return array */ protected function getTemplates() { $finder = new Finder(); $finder->files()->in(__DIR__ . '/../Resources/views/Template'); if (is_dir('../app/Resources/LansolePagesBundle/views/Template')) { $finder->in('../app/Resources/LansolePagesBundle/views/Template'); } $templates = array(); foreach ($finder->files() as $file) { $name = str_replace(array('.html.twig', '.html.php'), '', $file->getFileName()); $templates[$name] = ucwords(str_replace('_', ' ', $name)); } asort($templates); return $templates; }
/** * @param string $path * * @return $this */ public function parse($path) { if (!$this->fileSystem->isAbsolutePath($path)) { $path = getcwd() . DIRECTORY_SEPARATOR . $path; } if (!is_file($path)) { $this->finder->files()->in($path)->ignoreDotFiles(true)->ignoreVCS(true)->ignoreUnreadableDirs(true); foreach ($this->finder as $file) { $this->parseFile($file); } return $this; } $this->parseFile($path); return $this; }
/** * Get status records, parse new records * and remove processed xml files * * @throws \Exception */ public function collection() { $finder = new Finder(); $finder->files()->in($this->source); if ($finder->files()->count()) { $parser = new Parser($finder, function ($file) use($filesystem) { if (!\phpQuery::newDocumentFileXML($file)) { throw new \Exception('Can not create php query object'); } return (new Record())->setName(pq('task')->text())->setDate(pq('date')->text())->setDescription("<p>Status: " . pq('status')->text() . "</p>" . "<p>Command: " . pq('command')->text() . "</p>" . "<p>Error: " . pq('error')->text() . "</p>"); }); $this->cache->refresh($parser->collection()); } return $this->cache->load(); }
/** * @inheritdoc */ public function searchString($stringToSearch, $searchFolder) { $this->finder = $this->finderFactory->create(); $result = new FileSearchResult($searchFolder); $this->finder->ignoreUnreadableDirs()->in($searchFolder); foreach ($this->finder->files()->contains($stringToSearch) as $file) { /** @var \Symfony\Component\Finder\SplFileInfo $file */ $fileLocation = new FileLocation(); $fileLocation->setFolder($file->getPath()); $fileLocation->setName($file->getFilename()); $fileLocation->setExtension($file->getExtension()); $result->add($fileLocation); } return $result; }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $type = $input->getArgument('type'); if (!in_array($type, array('picture', 'sound'))) { throw new InvalidArgumentException($type . ' is invalid. Only sound or picture are supported'); } $dir = $input->getArgument('folder'); if (!file_exists($dir)) { $dir = getcwd() . DIRECTORY_SEPARATOR . $dir; if (!file_exists($dir)) { throw new InvalidArgumentException($dir . ' is not exist.'); } } $done_folder = $dir . DIRECTORY_SEPARATOR . 'done'; @mkdir($done_folder, 0777); $client = new Client(['cookies' => true, 'track_redirects' => true, 'headers' => ['User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1']]); $http = new GuzzleHttpRequest($client); $course = new MoverCourse(); $page = new LoginPage($http); $page->doLogin(); $finder = new Finder(); $cell_id = NULL; if ('picture' == $type) { $finder->files()->name('/\\.(jpg|jpeg|png|gif|bmp|tif)$/')->sortByName()->in($dir)->exclude('done'); $cell_id = 4; } elseif ('sound' == $type) { $finder->files()->name('/\\.(mp3)$/')->sortByName()->in($dir)->exclude('done'); $cell_id = 3; } foreach ($finder as $file) { /** @var SplFileInfo $file */ $output->writeln($file->getRealPath()); // extract the WORD from filename $word = str_replace('.' . $file->getExtension(), '', $file->getFilename()); // find the word and extract its id $page = new WordSearchPage($http, $course, $word); $thing_id = $page->getThingId(); if ($thing_id) { $csrf_token = $page->getCsrfToken(); $referer = $page->getFullUrl(); // upload pictures $page = new UploadPage($http); if ($page->upload($csrf_token, $thing_id, $cell_id, $file->getRealPath())) { rename($file->getRealPath(), $done_folder . DIRECTORY_SEPARATOR . $file->getFilename()); } } } }
/** * Compiles phar archive. * * @param string $version */ public function compile($version) { if (file_exists($package = "behat-{$version}.phar")) { unlink($package); } // create phar $phar = new \Phar($package, 0, 'behat.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.xsd')->name('*.xml')->name('LICENSE')->notName('PharCompiler.php')->notName('PearCompiler.php')->in($this->libPath . '/src')->in($this->libPath . '/vendor'); foreach ($finder as $file) { // don't compile test suites if (!preg_match('/\\/tests\\/|\\/test\\//i', $file->getRealPath())) { $this->addFileToPhar($file, $phar); } } // license and autoloading $this->addFileToPhar(new \SplFileInfo($this->libPath . '/LICENSE'), $phar); $this->addFileToPhar(new \SplFileInfo($this->libPath . '/i18n.php'), $phar); // stub $phar->setStub($this->getStub($version)); $phar->stopBuffering(); unset($phar); }
/** * @return \Symfony\Component\Finder\Finder|\Symfony\Component\Finder\SplFileInfo[] */ private function getBundleTransferSchemas() { $testBundleSchemaDirectory = Configuration::projectDir() . DIRECTORY_SEPARATOR . 'src'; $finder = new Finder(); $finder->files()->in($testBundleSchemaDirectory)->name('*.transfer.xml'); return $finder; }
/** * Prepares test environment. */ public function setUp() { $finder = new Finder(); $finder->files()->in(__DIR__ . '/config/'); $finder->name('*.yml'); $this->dummyParser = $this->getMock('Symfony\\Component\\Yaml\\Parser'); $this->dummyDumper = $this->getMock('Symfony\\Component\\Yaml\\Dumper'); $this->dummyFilesystem = $this->getMock('Symfony\\Component\\Filesystem\\Filesystem'); $dummyDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $dummyDispatcher->expects($this->once())->method('dispatch')->willReturnCallback(function ($name, $event) { /** @var GroupOptionTypeEvent $event */ $optionTypes = ['acp' => ['twomartens.core' => ['access' => new BooleanOptionType()]]]; $event->addOptions($optionTypes); }); $this->yamlData = []; $this->optionData = []; foreach ($finder as $file) { /** @var SplFileInfo $file */ $basename = $file->getBasename('.yml'); $this->yamlData[$basename] = Yaml::parse($file->getContents()); $this->optionData[$basename] = ConfigUtil::convertToOptions($this->yamlData[$basename]); } $this->dummyParser->expects($this->any())->method('parse')->willReturnCallback(function ($content) { return Yaml::parse($content); }); /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dummyDispatcher */ $this->groupService = new GroupService($finder, $this->dummyParser, $this->dummyDumper, $this->dummyFilesystem, $dummyDispatcher); }