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. |
/** * @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); } } }
/** * Deletes all existing .htaccess files and web.config files that Piwik may have created, */ public static function deleteHtAccessFiles() { $files = Filesystem::globr(PIWIK_INCLUDE_PATH, ".htaccess"); // that match the list of directories we create htaccess files // (ie. not the root /.htaccess) $directoriesWithAutoHtaccess = array('/js', '/libs', '/vendor', '/plugins', '/misc/user', '/config', '/core', '/lang', '/tmp'); foreach ($files as $file) { foreach ($directoriesWithAutoHtaccess as $dirToDelete) { // only delete the first .htaccess and not the ones in sub-directories $pathToDelete = $dirToDelete . '/.htaccess'; if (strpos($file, $pathToDelete) !== false) { @unlink($file); } } } }
/** * @param $directoryWithinPlugin * @param $expectedSubclass * @return array */ private function doFindMultipleComponents($directoryWithinPlugin, $expectedSubclass) { $components = array(); $baseDir = PIWIK_INCLUDE_PATH . '/plugins/' . $this->pluginName . '/' . $directoryWithinPlugin; $files = Filesystem::globr($baseDir, '*.php'); foreach ($files as $file) { require_once $file; $fileName = str_replace(array($baseDir . '/', '.php'), '', $file); $klassName = sprintf('Piwik\\Plugins\\%s\\%s\\%s', $this->pluginName, $directoryWithinPlugin, str_replace('/', '\\', $fileName)); if (!class_exists($klassName)) { continue; } if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) { continue; } $klass = new \ReflectionClass($klassName); if ($klass->isAbstract()) { continue; } $components[$file] = $klassName; } return $components; }
private static function getCurrentDimensionFileChanges() { $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/*/Columns', '*.php'); $times = array(); foreach ($files as $file) { $times[$file] = filemtime($file); } return $times; }
/** * @group Core */ public function testEndOfLines() { foreach (Filesystem::globr(PIWIK_DOCUMENT_ROOT, '*') as $file) { // skip files in these folders if (strpos($file, '/.git/') !== false || strpos($file, '/documentation/') !== false || strpos($file, '/tests/') !== false || strpos($file, '/lang/') !== false || strpos($file, 'yuicompressor') !== false || strpos($file, '/tmp/') !== false) { continue; } // skip files with these file extensions if (preg_match('/\\.(bmp|fdf|gif|deb|deflate|exe|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf|so|dat|eps|phar|pyc)$/', $file)) { continue; } if (!is_dir($file)) { $contents = file_get_contents($file); // expect CRLF if (preg_match('/\\.(bat|ps1)$/', $file)) { $contents = str_replace("\r\n", '', $contents); $this->assertTrue(strpos($contents, "\n") === false, 'Incorrect line endings in ' . $file); } else { // expect native $hasWindowsEOL = strpos($contents, "\r\n"); // overwrite translations files with incorrect line endings $this->assertTrue($hasWindowsEOL === false, 'Incorrect line endings \\r\\n found in ' . $file); } } } }
try { document.documentElement.doScroll('left'); } catch (error) { setTimeout(ready, 0); return; } f(); } }()); } } else { customAddEventListener(window, 'load', f, false); } })(PiwikTest); </script> <?php include_once $root . '/core/Filesystem.php'; $files = \Piwik\Filesystem::globr($root . '/plugins/*/tests/javascript', 'index.php'); foreach ($files as $file) { include_once $file; } ?> <div id="jashDiv"> <a href="#" onclick="javascript:loadJash();" title="Open JavaScript Shell"><img id="title" src="gnome-terminal.png" border="0" width="24" height="24" /></a> </div> </body> </html>
private function doesFolderContainUITests($folderPath) { $testFiles = Filesystem::globr($folderPath, "*_spec.js"); return !empty($testFiles); }
/** * @return array * @throws Exception */ private function getAllFilesizes() { $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*'); $filesizes = array(); foreach ($files as $file) { if (!$this->isFileIncludedInFinalRelease($file)) { continue; } $filesize = filesize($file); if ($filesize === false) { throw new Exception("Error getting filesize for file: {$file}"); } $filesizes[$file] = $filesize; } return $filesizes; }
private function findCommandsInPlugin($pluginName) { $commands = array(); $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName . '/Commands', '*.php'); foreach ($files as $file) { $klassName = sprintf('Piwik\\Plugins\\%s\\Commands\\%s', $pluginName, basename($file, '.php')); if (!class_exists($klassName) || !is_subclass_of($klassName, 'Piwik\\Plugin\\ConsoleCommand')) { continue; } $klass = new \ReflectionClass($klassName); if ($klass->isAbstract()) { continue; } $commands[] = $klassName; } return $commands; }