Exemplo n.º 1
0
 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();
     }
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 private function findFile(string $fileName, string $extension)
 {
     $iterator = new \RegexIterator(new \DirectoryIterator($this->downloadPath), sprintf('/%s\\.%s$/ui', preg_quote(pathinfo($fileName, PATHINFO_FILENAME), '/'), '(' . $extension . ')'), \RegexIterator::GET_MATCH);
     $iterator->rewind();
     return $iterator->current()[0];
 }
Exemplo n.º 4
0
        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 />';
}
Exemplo n.º 5
0
 /**
  * WpMenuPages constructor.
  *
  * @param string        $pluginBaseFile  Absolute path to plugin main file
  * @param array|Options $options         An instance of {@link Options} or an array with default options
  * @param string        $optionsBaseName In case the $options param is an array this should be a string
  *                                       defining the name of the options array as stored in DB
  *
  * @throws \InvalidArgumentException If $pluginBaseFile is empty or pointing to non readable file
  * @throws \InvalidArgumentException If $options isn't an instance of {@link Options} and is not an array
  *                                   and $optionsBaseName is empty
  * @throws \Exception If symlinks are used and couldn't resolve $pluginBaseFile path
  * @since  1.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function __construct($pluginBaseFile, $options, $optionsBaseName = '')
 {
     if (empty($pluginBaseFile) || !file_exists($pluginBaseFile) || !is_readable($pluginBaseFile)) {
         throw new \InvalidArgumentException('Invalid argument $pluginBaseFile in ' . __METHOD__);
     }
     $pluginBaseFile = wp_normalize_path($pluginBaseFile);
     $pluginIsSymlink = strpos($pluginBaseFile, ABSPATH) !== 0;
     $pagesIsSymlink = strpos(__FILE__, ABSPATH) !== 0;
     if ($pluginIsSymlink) {
         $pluginFolderName = dirname(plugin_basename($pluginBaseFile));
         $this->pluginBasePath = trailingslashit(WP_PLUGIN_DIR) . $pluginFolderName;
         $this->pluginBaseFile = trailingslashit($this->pluginBasePath) . basename($pluginBaseFile);
     } else {
         $this->pluginBasePath = dirname($pluginBaseFile);
         $this->pluginBaseFile = realpath($pluginBaseFile);
     }
     if ($pagesIsSymlink) {
         $this->basePath = dirname(dirname(dirname(__FILE__)));
         $this->basePathRelToPlugin = str_replace($this->pluginBasePath, '', $this->basePath);
         $dirItr = new \RecursiveDirectoryIterator($this->pluginBasePath, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \RecursiveDirectoryIterator::SKIP_DOTS);
         $itr = new \RecursiveIteratorIterator($dirItr);
         $res = new \RegexIterator($itr, '/WpMenuPages\\.php/', \RecursiveIteratorIterator::LEAVES_ONLY);
         $res->next();
         /** @var \SplFileInfo $wpMenuPagesFile */
         $wpMenuPagesFile = $res->current();
         if (!$wpMenuPagesFile instanceof \SplFileInfo) {
             // TODO Message
             throw new \Exception('Something went awfully wrong!');
         }
         $this->basePath = dirname(dirname($wpMenuPagesFile->getPath()));
     } else {
         $this->basePath = dirname(dirname(dirname(__FILE__)));
     }
     $this->basePathRelToPlugin = str_replace($this->pluginBasePath, '', $this->basePath);
     if ($options instanceof Options) {
         $this->options = $options;
     } elseif (is_array($options) && !empty($optionsBaseName)) {
         $this->options = Options::getInstance($optionsBaseName, $options);
     } else {
         throw new \InvalidArgumentException('Invalid argument $options in ' . __METHOD__);
     }
     add_action('admin_init', function () {
         $this->pluginMetaData = get_plugin_data($this->pluginBaseFile);
     });
 }
Exemplo n.º 6
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;
 }