Piwik\Filesystem::globr PHP Method

globr() public static method

See {@link http://php.net/manual/en/function.glob.php glob} for more info.
public static globr ( string $sDir, string $sPattern, integer $nFlags = null ) : array
$sDir string directory The directory to glob in.
$sPattern string pattern The pattern to match paths against.
$nFlags integer `glob()` . See {@link http://php.net/manual/en/function.glob.php glob()}.
return array The list of paths that match the pattern.
    public static function globr($sDir, $sPattern, $nFlags = null)
    {
        if (($aFiles = \_glob("{$sDir}/{$sPattern}", $nFlags)) == false) {
            $aFiles = array();
        }
        if (($aDirs = \_glob("{$sDir}/*", GLOB_ONLYDIR)) != false) {
            foreach ($aDirs as $sSubDir) {
                if (is_link($sSubDir)) {
                    continue;
                }
                $aSubFiles = self::globr($sSubDir, $sPattern, $nFlags);
                $aFiles = array_merge($aFiles, $aSubFiles);
            }
        }
        return $aFiles;
    }

Usage Example

 /**
  * @param string $templateFolder  full path like /home/...
  * @param string $pluginName
  * @param array $replace         array(key => value) $key will be replaced by $value in all templates
  * @param array $whitelistFiles  If not empty, only given files/directories will be copied.
  *                               For instance array('/Controller.php', '/templates', '/templates/index.twig')
  */
 protected function copyTemplateToPlugin($templateFolder, $pluginName, array $replace = array(), $whitelistFiles = array())
 {
     $replace['PLUGINNAME'] = $pluginName;
     $files = array_merge(Filesystem::globr($templateFolder, '*'), Filesystem::globr($templateFolder, '.*'));
     foreach ($files as $file) {
         $fileNamePlugin = str_replace($templateFolder, '', $file);
         if (!empty($whitelistFiles) && !in_array($fileNamePlugin, $whitelistFiles)) {
             continue;
         }
         if (is_dir($file)) {
             $this->createFolderWithinPluginIfNotExists($pluginName, $fileNamePlugin);
         } else {
             $template = file_get_contents($file);
             foreach ($replace as $key => $value) {
                 $template = str_replace($key, $value, $template);
             }
             foreach ($replace as $key => $value) {
                 $fileNamePlugin = str_replace($key, $value, $fileNamePlugin);
             }
             $this->createFileWithinPluginIfNotExists($pluginName, $fileNamePlugin, $template);
         }
     }
 }
All Usage Examples Of Piwik\Filesystem::globr