示例#1
0
文件: Tests.php 项目: halfer/Meshing
 public function testAll($testDir)
 {
     // Iterate across this dir for files matching *_test.php
     $directory = new RecursiveDirectoryIterator($testDir);
     $iterator = new RecursiveIteratorIterator($directory);
     $regex = new RegexIterator($iterator, '/^.+_test\\.php$/i', RecursiveRegexIterator::GET_MATCH);
     $regex->next();
     while ($regex->valid()) {
         $item = $regex->current();
         require_once $item[0];
         $regex->next();
     }
 }
示例#2
0
文件: Utils.php 项目: halfer/Meshing
 protected static function readCommands($incHidden = false)
 {
     static $commands = array();
     static $hidden = array();
     if (!$commands) {
         $projectRoot = Meshing_Utils::getProjectRoot();
         $consoleRoot = $projectRoot . Meshing_Utils::getPaths()->getPathMeshingCommands();
         $directory = new RecursiveDirectoryIterator($consoleRoot);
         $iterator = new RecursiveIteratorIterator($directory);
         $regex = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
         $regex->next();
         $i++;
         while ($regex->valid()) {
             // For safety!
             if ($i > 50) {
                 break;
             }
             // Get the full pathname of the class
             $item = $regex->current();
             $item = $item[0];
             // Strip out the full path bit, and generally tidy
             $item = str_replace($consoleRoot . DIRECTORY_SEPARATOR, '', $item);
             $item = str_replace('.php', '', $item);
             $className = 'Meshing_Console_Command_' . str_replace(DIRECTORY_SEPARATOR, '_', $item);
             $item = strtolower(str_replace(DIRECTORY_SEPARATOR, ':', $item));
             // Classes without this method are not commands at all
             $realCommand = method_exists($className, 'getDescription');
             // We consult a special method to determine whether to show the command
             if ($realCommand) {
                 $cmdClass = new $className();
                 $commands[$className] = $item;
                 if ($cmdClass->isHiddenCommand()) {
                     $hidden[] = $className;
                 }
             }
             $regex->next();
         }
         // Preserve the keys when sorting
         asort($commands);
     }
     // Strip out hidden commands
     if (!$incHidden) {
         foreach ($hidden as $removeClass) {
             unset($commands[$removeClass]);
         }
     }
     return $commands;
 }
示例#3
0
 /**
  * @test
  * @group QA
  * @dataProvider dirs_to_parse
  */
 function some_files_are_missing_the_copyright_statement($dir)
 {
     $Directory = new RecursiveDirectoryIterator($dir);
     $Iterator = new RecursiveIteratorIterator($Directory);
     $Regex = new RegexIterator($Iterator, '/\\.php$/i', RecursiveRegexIterator::GET_MATCH);
     $result = array();
     $Regex->next();
     while ($Regex->valid()) {
         $path = $Regex->getPathname();
         $copy = 'Copyright (c) 2015 Gregory Vinčić, The MIT License (MIT)';
         if (!$this->file_contains($path, $copy)) {
             $result[] = $path;
         }
         $Regex->next();
     }
     $this->assertEquals('', implode("\n", $result));
 }
示例#4
0
 /**
  * Returns if a given directory has tests (recursively)
  *
  * @param string $dir full path to the directory to look for phpunit tests
  * @param string $testtype phpunit|behat
  * @return bool if a given directory has tests (true) or no (false)
  */
 private static function directory_has_tests($dir, $testtype)
 {
     if (!is_dir($dir)) {
         return false;
     }
     $dirite = new RecursiveDirectoryIterator($dir);
     $iteite = new RecursiveIteratorIterator($dirite);
     $regexp = self::get_regexp($testtype);
     $regite = new RegexIterator($iteite, $regexp);
     $regite->rewind();
     if ($regite->valid()) {
         return true;
     }
     return false;
 }
示例#5
0
文件: util.php 项目: nigeli/moodle
 /**
  * Returns if a given directory has tests (recursively)
  *
  * @param $dir string full path to the directory to look for phpunit tests
  * @return bool if a given directory has tests (true) or no (false)
  */
 private static function directory_has_tests($dir)
 {
     if (!is_dir($dir)) {
         return false;
     }
     $dirite = new RecursiveDirectoryIterator($dir);
     $iteite = new RecursiveIteratorIterator($dirite);
     $sep = preg_quote(DIRECTORY_SEPARATOR, '|');
     $regite = new RegexIterator($iteite, '|' . $sep . 'tests' . $sep . '.*_test\\.php$|');
     $regite->rewind();
     if ($regite->valid()) {
         return true;
     }
     return false;
 }
        echo '>' . $this->_valeur . '</div>' . PHP_EOL;
    }
}
?>

<style>
    .vert{ color: green; margin-left: 25px; }
    .bleu{color: blue; }
</style>
<h2>Mon Filtre avec while</h2>

<?php 
$DirectoryIterator = new MonDI('./');
//print_r($DirectoryIterator);
$Iterator_iterator = new MonFilter($DirectoryIterator);
$Iterator_iterator->rewind();
while ($Iterator_iterator->valid()) {
    $Iterator_iterator->afficher_valeur();
    $Iterator_iterator->next();
}
echo '<h2>RegexIterator avec while</h2>';
$RegexIterator = new RegexIterator($DirectoryIterator, '#rep#');
$RegexIterator->rewind();
while ($RegexIterator->valid()) {
    echo $RegexIterator->current()->getFilename() . '<br />';
    $RegexIterator->next();
}
echo '<h2>RegexIterator avec foreach</h2>';
foreach ($RegexIterator as $Resultat) {
    echo $Resultat . '<br />';
}
示例#7
0
$ext_badge = array('php' => 'success', 'xml' => 'info', 'css' => 'warning', 'js' => 'important', 'ini' => 'info');
$file_tip = array('item.css' => 'Contains CSS specific to this item layout', 'category.css' => 'Contains CSS specific to this category layout', 'item.xml' => 'Layout\'s structure: including display parameters, field positions, file list, etc', 'category.xml' => 'Layout\'s structure: including display parameters, field positions, file list, etc', 'item.php' => 'PHP/HTML to display item\'s fields', 'category_items.php' => 'Item list filtering form, and Item loop (displaying every item)', 'category.php' => 'Top-level container of the layout', 'category_category.php' => 'Displays category information: title, description, image, etc', 'category_category_html5.php' => 'Displays category information: title, description, image, etc', 'category_alpha.php' => 'Displays the alphanumerical index of the item list', 'category_peercategories.php' => 'Displays the peer categories list', 'category_subcategories.php' => 'Display the sub-categories list');
$file_tip['item_html5.php'] = $file_tip['item.php'] . ' (HTML5 version)';
$file_tip['category_items_html5.php'] = $file_tip['category_items.php'] . ' (HTML5 version)';
$file_tip['category_html5.php'] = $file_tip['category.php'] . ' (HTML5 version)';
$file_tip['category_category_html5.php'] = $file_tip['category_category.php'] . ' (HTML5 version)';
$file_tip['category_alpha_html5.php'] = $file_tip['category_alpha.php'] . ' (HTML5 version)';
$file_tip['category_peercategories_html5.php'] = $file_tip['category_peercategories.php'] . ' (HTML5 version)';
$file_tip['category_subcategories_html5.php'] = $file_tip['category_subcategories.php'] . ' (HTML5 version)';
$file_tip_extra = array('item.xml' => 'This file contains layout\' s structure: including <br/> - <b>display parameters, field positions, file list, etc</b>, <br/> - you can add extra parameters/positions, <br/>-- if you add a new position, you will need to also add the dispay -LOOP- of the new position inside files: <br/><b>item.php</b> <br/><b>item_html5.php</b> <br/><br/>(click to edit file and then use the code button)', 'category.xml' => 'This file contains layout\' s structure: including <br/> - <b>display parameters, field positions, file list, etc</b>, <br/> - you can add extra parameters/positions, <br/>-- if you add a new position, you will need to also add the dispay -LOOP- of the new position inside files: <br/><b>category_items.php</b> <br/><b>category_items_html5.php</b> <br/><br/>(click to edit file and then use the code button)', 'item.php' => 'This file display the item, thus has display LOOPs of for every position to show fields of every position, if you add new position in the XML file, then make sure that you ADD the display loop here <br/><br/>(click to edit file and then use the code button)', 'category_items.php' => 'This file includes: <br/><br/>- Item list filtering form, <br/>- Item loop (that displays every item\'s fields), <br/><br/>if you add new field position in the XML file, then make sure that you ADD here, the display loop that displays the fields of the position <br/><br/>(click to edit file and then use the code button)');
$file_tip_extra['item_html5.php'] = $file_tip_extra['item.php'];
$file_tip_extra['category_items_html5.php'] = $file_tip_extra['category_items.php'];
$file_code_btns = array('item.xml' => array('fieldPosXML' => 1, 'paramTextXML' => 1, 'paramRadioXML' => 1, 'paramSelectXML' => 1), 'category.xml' => array('fieldPosXML' => 1, 'paramTextXML' => 1, 'paramRadioXML' => 1, 'paramSelectXML' => 1), 'item.php' => array('itemPosHTML' => 1, 'itemFieldDisplay' => 1), 'category_items.php' => array('catPosHTML' => 1, 'catFieldDisplay' => 1));
$file_code_btns['item_html5.php'] = $file_code_btns['item.php'];
$file_code_btns['category_items_html5.php'] = $file_code_btns['category_items.php'];
while ($it->valid()) {
    if (!$it->isDot()) {
        //echo '<span class="label">SubPathName</span> '. $it->getSubPathName();
        //echo ' -- <span class="label">SubPath</span> '. $it->getSubPath();
        //echo ' -- <span class="label">Key</span> '. $it->key();
        $subpath = $it->getSubPath();
        $subpath_highlighted = $subpath ? '<span class="label">' . $subpath . '/</span>' : '';
        $subpath_file = $it->getSubPathName();
        $filename = preg_replace('#^' . $subpath . '\\' . DS . '#', '', $subpath_file);
        $pi = pathinfo($it->key());
        $ext = $pi['extension'];
        $file_type = isset($ext_badge[$ext]) ? '<span class="badge badge-' . $ext_badge[$ext] . '">' . $ext . '</span> ' : '<span class="badge">---</span> ';
        $btns_handle_class = isset($ext_badge[$ext]) ? '<span class="badge badge-' . $ext_badge[$ext] . '">' . $ext . '</span> ' : '<span class="badge">---</span> ';
        $btn_allowed = isset($file_code_btns[$filename]) ? array_keys($file_code_btns[$filename]) : array();
        echo '
						' . $file_type . (!isset($file_tip_extra[$filename]) ? '<img src="components/com_flexicontent/assets/images/tick_f2.png" alt="Edit file">' : '<img src="components/com_flexicontent/assets/images/comment.png" data-placement="bottom" class="' . $tip_class . '" title="' . $file_tip_extra[$filename] . '" alt="Edit file"/>') . '
 private function folderContains($folderPath, $filePattern)
 {
     if (!is_dir($folderPath)) {
         return false;
     }
     $directoryIterator = new \RecursiveDirectoryIterator($folderPath);
     $flatIterator = new \RecursiveIteratorIterator($directoryIterator);
     $fileIterator = new \RegexIterator($flatIterator, $filePattern, \RegexIterator::GET_MATCH);
     $fileIterator->rewind();
     return $fileIterator->valid();
 }
 /**
  * Method to get files having the given extensions from a given folder
  *
  * @access private
  * @return integer
  * @since 1.0
  */
 function getFilesFromPath($itemid, $fieldid, $append_item = 1, $append_field = 0, $folder_param_name = 'dir', $exts = 'bmp,csv,doc,docx,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,pptx,swf,txt,xcf,xls,xlsx,zip,ics')
 {
     $app = JFactory::getApplication();
     $option = JRequest::getVar('option');
     $imageexts = array('jpg', 'gif', 'png', 'bmp', 'jpeg');
     // Common image extensions
     $gallery_folder = $this->getFieldFolderPath($itemid, $fieldid, $append_item, $append_field, $folder_param_name);
     //echo $gallery_folder ."<br />";
     // Create folder for current language
     if (!is_dir($gallery_folder)) {
         mkdir($gallery_folder, $mode = 0755, $recursive = true);
     }
     // Get file list according to filtering
     $exts = preg_replace("/[\\s]*,[\\s]*/", '|', $exts);
     $it = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($gallery_folder)), '#(.*\\.)(' . $exts . ')#i');
     $it->rewind();
     // Get file information
     $rows = array();
     $i = 1;
     while ($it->valid()) {
         if ($it->isDot()) {
             $it->next();
             continue;
         }
         $filesubpath = $it->getSubPathName();
         // filename including the folder subpath
         $filepath = $it->key();
         $pinfo = pathinfo($filepath);
         $row = new stdClass();
         $row->ext = $pinfo['extension'];
         $row->filename = $filesubpath;
         //$pinfo['filename'].".".$pinfo['extension'];
         $row->size = sprintf("%.0f KB", filesize($filepath) / 1024);
         $row->altname = $pinfo['filename'];
         $row->uploader = '-';
         $row->uploaded = date("F d Y H:i:s.", filectime($filepath));
         $row->id = $i;
         if (in_array(strtolower($row->ext), $imageexts)) {
             $row->icon = JURI::root() . "components/com_flexicontent/assets/images/mime-icon-16/image.png";
         } elseif (file_exists(JPATH_SITE . "/components/com_flexicontent/assets/images/mime-icon-16/" . $row->ext . ".png")) {
             $row->icon = JURI::root() . "components/com_flexicontent/assets/images/mime-icon-16/" . $row->ext . ".png";
         } else {
             $row->icon = JURI::root() . "components/com_flexicontent/assets/images/mime-icon-16/unknown.png";
         }
         $rows[] = $row;
         $i++;
         $it->next();
     }
     return $rows;
 }
示例#10
0
 /**
  * Find templates/resources for the given path.
  *
  * <p><strong>Example:</strong></p>
  *
  * <p>Find all styles in a particular folder (<em>style</em>).</p>
  * <code><pre>
  *   $styles = $this->find('style', '/css/');
  *   foreach ($styles as $name => $url) {
  *    echo '<link rel="stylesheet" type="text/css" href="'.$url.'"/>';
  *   }
  * </pre></code>
  *
  * <p>Alternatively, using the build in $resource manager, it would look like this:</p>
  * <code><pre>
  *   $styles = $this->find('style', '/css/');
  *   foreach ($styles as $name => $url) {
  *    $resourceManager->cssFile($name);
  *   }
  * </pre></code>
  *
  * @param string path The base path, relative to the template/resource path.
  * @param string regexp Optional filter expression; default is <code>null</code> for none.
  * @param string type The resource type; default is <code>View::RESOURCE</code>.
  * @return array A map of matching filenames.
  */
 public function find($path, $regexp = null, $type = View::RESOURCE)
 {
     list($path, $type) = $this->resolveType($path, $type);
     $locations = $this->getLocationsFor($type);
     // iterate in ascending priority, so the more important come first
     $files = array();
     foreach ($locations as $location) {
         $base = $location . '/' . $path;
         if (file_exists($base) && is_dir($base)) {
             $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($base));
             if (null != $regexp) {
                 $it = new \RegexIterator($it, $regexp, \RegexIterator::MATCH);
             }
             for ($it->rewind(); $it->valid(); $it->next()) {
                 $name = str_replace(array($base, '\\'), array('', '/'), $it->current()->getPathname());
                 $files[] = $name;
             }
         }
     }
     return $files;
 }