public function getSrcDirectoryIterators()
 {
     $iterators = array();
     foreach ($this->srcDirectories as $srcDirectory => $closures) {
         $iterators[] = $iterator = new \recursiveIteratorIterator(new iterators\filters\recursives\closure(new \recursiveDirectoryIterator($srcDirectory, \filesystemIterator::SKIP_DOTS | \filesystemIterator::CURRENT_AS_FILEINFO)), \recursiveIteratorIterator::LEAVES_ONLY);
         foreach ($closures as $closure) {
             $iterator->addClosure($closure);
         }
     }
     return $iterators;
 }
 public function __toString()
 {
     $string = '';
     if (sizeof($this->coverage) > 0) {
         try {
             $nodes = array('coverage' => round($this->coverage->getValue() * 100, 2), 'project' => $this->projectName, 'name' => '', 'fullname' => '', 'htmlReportBaseUrl' => $this->htmlReportBaseUrl, 'date' => time(), 'children' => array());
             foreach ($this->coverage->getClasses() as $className => $classPath) {
                 $node =& $nodes;
                 $class = new \reflectionClass($className);
                 $namespaces = explode('\\', $class->getNamespaceName());
                 foreach ($namespaces as $namespace) {
                     $childFound = false;
                     foreach ($node['children'] as $key => $child) {
                         $childFound = $child['name'] === $namespace;
                         if ($childFound === true) {
                             break;
                         }
                     }
                     if ($childFound === false) {
                         $key = sizeof($node['children']);
                         $node['children'][] = array('name' => $namespace, 'fullname' => $node['fullname'] . ($node['fullname'] == '' ? '' : '\\') . $namespace, 'children' => array());
                     }
                     $node =& $node['children'][$key];
                 }
                 $child = array('name' => $class->getShortName(), 'fullname' => $node['fullname'] . '\\' . $class->getShortName(), 'covered' => $this->coverage->getNumberOfCoveredLinesInClass($className), 'coverable' => $this->coverage->getNumberOfCoverableLinesInClass($className), 'pourcent' => round($this->coverage->getValueForClass($className) * 100, 2), 'children' => array());
                 $node['children'][] = $child;
             }
             if (@file_put_contents($this->destinationDirectory . DIRECTORY_SEPARATOR . self::dataFile, json_encode($nodes)) === false) {
                 throw new exceptions\runtime($this->locale->_('Unable to write in \'' . $this->destinationDirectory . '\''));
             }
             try {
                 $resourcesDirectoryIterator = new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\dot($this->resourcesDirectory));
             } catch (\exception $exception) {
                 throw new exceptions\runtime($this->locale->_('Directory \'' . $this->resourcesDirectory . '\' does not exist'));
             }
             foreach ($resourcesDirectoryIterator as $file) {
                 if (@copy($file, $this->destinationDirectory . DIRECTORY_SEPARATOR . $resourcesDirectoryIterator->getSubPathname()) === false) {
                     throw new exceptions\runtime($this->locale->_('Unable to write in \'' . $this->destinationDirectory . '\''));
                 }
             }
             $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Treemap of code coverage are available at %s.'), $this->treemapUrl)) . PHP_EOL;
         } catch (\exception $exception) {
             $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Unable to generate code coverage at %s: %s.'), $this->treemapUrl, $exception->getMessage())) . PHP_EOL;
         }
     }
     return $string;
 }
示例#3
0
文件: html.php 项目: ronan-gloo/atoum
 public function getSrcDirectoryIterators()
 {
     $iterators = array();
     foreach ($this->srcDirectories as $srcDirectory => $closures) {
         $iterators[] = $iterator = new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($srcDirectory)));
         foreach ($closures as $closure) {
             $iterator->addClosure($closure);
         }
     }
     return $iterators;
 }
示例#4
0
<?php

try {
    $rdi = new recursiveDirectoryIterator(dirname(__FILE__), FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS);
    $it = new recursiveIteratorIterator($rdi);
    $it->seek(1);
    while ($it->valid()) {
        if ($it->isFile()) {
            $it->current();
        }
        $it->next();
    }
    $it->current();
} catch (Exception $e) {
}
echo "okey";
示例#5
0
/**
 * \brief given a directory name, return a array of subdir paths and an array of
 * the files under the last subdir.
 *
 * @param string $dir
 * @return array ByDir, an array of arrays.
 *
 * array[dirpath]=>(array)list of files under leaf dir
 *
 * \todo test this routine with files other than the leaf dirs, does it work?
 *
 */
function filesByDir($dir)
{
    $ByDir = array();
    $fileList = array();
    $subPath = '';
    if (empty($dir)) {
        return $fileList;
        // nothing to process, return empty list.
    }
    try {
        $dirObject = new recursiveIteratorIterator(new recursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
        // dirobjs is recusiveIteratorIterator object
        foreach ($dirObject as $name) {
            $aSubPath = $dirObject->getSubPath();
            /*
             * if we changed subpaths, we are in a new sub-dir, reset the file list
             */
            if ($aSubPath != $subPath) {
                //print "DB: fileByDir: asb != sb, Init fileList!\n";
                $fileList = array();
            }
            if (is_file($name)) {
                $subPath = $dirObject->getSubPath();
                $spn = $dirObject->getSubPathName();
                $subDir = dirname($spn);
                if ($subDir == $aSubPath) {
                    $fileName = $dirObject->getFilename();
                    $fileList[] = $fileName;
                }
            }
            if (empty($subPath)) {
                continue;
            } else {
                if (empty($fileList)) {
                    continue;
                }
                $ByDir[$subPath] = $fileList;
            }
            /* Debug
                   *
                   $subPath = $dirObject->getSubPath();
                   print "DB: fileByDir: subpath is:$subPath\n";
                   $sbn = $dirObject->getSubPathName();
                   print "DB: fileByDir: subpathname is:$sbn\n";
                   $dirpath = $dirObject->getPath();
                   print "DB: fileByDir: dirpath is:$dirpath\n";
            
                   */
        }
        // foreach
        //print "DB: fileByDir: ByDir is:\n ";print_r($ByDir) . "\n";
        return $ByDir;
    } catch (Exception $e) {
        //print "in exception!\n$e\n";
        return array();
    }
}