public function testIteratorNegative() { $directoryPath = 'directory/path'; $filePath = $this->filePaths[0]; $this->setExpectedException('UnexpectedValueException', sprintf("Unable to determine a module, file '%s' belongs to.", $filePath)); $this->directoryMock->expects($this->at(0))->method('getAbsolutePath')->with($filePath)->will($this->returnValue($directoryPath . $filePath)); $this->moduleDirResolverMock->expects($this->at(0))->method('getModuleName')->with($directoryPath . $filePath)->will($this->returnValue(false)); $this->directoryMock->expects($this->never())->method('readFile'); $this->fileIterator->current(); }
public function testToArray() { $contents = ['content1', 'content2']; $expectedArray = []; $index = 0; foreach ($this->filePaths as $filePath) { $expectedArray[$filePath] = $contents[$index]; $this->directoryMock->expects($this->at($index))->method('readFile')->with($filePath)->will($this->returnValue($contents[$index++])); } $this->assertEquals($expectedArray, $this->fileIterator->toArray()); }
/** * {@inheritdoc} */ public function valid() { $current = $this->current(); if ($this->names) { return count($current) == count($this->names); } return parent::valid(); }
$humanBowtieStats = BowtieStatsFinder::getBowtieStatsLogFile($dir->getPathname(), BowtieStatsFinder::HUMAN_FILE); if (!$humanBowtieStats || !($humanMappingPercent = $humanBowtieStats->getAlignedReadsPercent())) { $humanMappingPercent = 'NA'; } $referenceBowtieStats = BowtieStatsFinder::getBowtieStatsLogFile($dir->getPathname(), BowtieStatsFinder::REFERENCE_FILE); if (!$referenceBowtieStats || !($refernceMappingPercent = $referenceBowtieStats->getAlignedReadsPercent())) { $relativeToUnmappedMappingPercent = 'NA'; } else { $relativeToUnmappedMappingPercent = round((100 - $humanMappingPercent) * $refernceMappingPercent / 100, 2); } // search for reads filtering stats $nReadsTotal = 'NA'; $nReadsFiltered = $humanBowtieStats ? $humanBowtieStats->getProcessedReadsCount() : 'NA'; $percentFiltered = 'NA'; $path = $dir->getPathname() . DIRECTORY_SEPARATOR . 'log'; $file = FileIterator::getFileByPattern('/reads-filter\\.pl\\.o\\d+/', $path); $filepath = $path . DIRECTORY_SEPARATOR . $file; if ($file == null) { printf("Warning: file reads-filter.pl.o[:digits:] not found in [%s/log] directory\n", basename($dir->getPathname())); } else { if (!file_exists($filepath)) { printf("Warning: file [%s] not found\n", $filepath); } else { $content = file_get_contents($filepath); $result = preg_match('/Filtered (\\d+) of (\\d+) reads/', $content, $matches); if ($result == 0) { printf("Warning: file [%s] has no statistics\n", $filepath); } else { $nReadsTotal = $matches[2]; } }
} public function fetch() { if (!isset($this->fp)) { $this->fp = fopen($this->filename, "r"); } if (!feof($this->fp)) { return $line = fgets($this->fp, 4096); } else { fclose($this->fp); $this->fp = NULL; return false; } } } $file = new FileIterator("colors-iterator.php"); while (($line = $file->fetch()) !== false) { //echo$line."<br/>"; } class FileIterator2 implements Iterator { private $filename; private $fp = NULL; public function __construct($file) { $this->filename = $file; } public function __destruct() { fclose($this->fp); }
/** * Returns an FileIterator for the files directly in this folder (not recursive). * * The returned Iterator will return objects of the type File, but if the second parameter is * set to FileSystem::RETURN_PATHS just the paths are returned. * * The first argument is a regular expression pattern that is used to filter the result. The * pattern is applied only on the file name, not on the whole path. * If the first parameter starts with a dot a faster filter only on the file extension will be * set. This causes that a regular expression pattern can't start with a dot! * * @param int Whether to return objects or paths * @param string Search pattern (regular expression or a file extension starting with a dot) * @return array Returns the array or null on failrue */ public function getFileIterator($pattern = null, $mode = FileSystem::RETURN_OBJECTS) { $iterator = new FileIterator($this->path); $iterator->setMode($mode); if ($pattern !== null) { if ($pattern !== null && strlen($pattern) > 0 && $pattern[0] == '.') { $extension = substr($pattern, 1); $iterator->setExtensionFilter($extension); } elseif ($pattern !== null) { $iterator->setFilter($pattern); } } return $iterator; }
public function __construct($query, $mysqli_connection) { $this->outfile = $mysqli_connection->select_into_outfile($query); parent::__construct($this->outfile, true); }
/** * Define o objeto que serĂ¡ Iterado * @param File $file */ public function setFileObject( File $file ) { $this->iterator->setFileObject( $file ); }
/** * @group single */ public function testIgnoreNonCompletePaths() { $expected = realpath(self::expand('dir2/file.php')); $iterator = new FileIterator(self::$expectedFiles, [self::expand('dir')]); $this->assertArrayHasKey($expected, $iterator->toArray(), "'{$expected}' should not be ignored as 'dir' should not match 'dir2'"); }