Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for directories in xdebug.profiler_output_name #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static function xdebugOutputFormat() {
if ($outputName=='') // Ini value not defined
$outputName = '/^cachegrind\.out\..+$/';
else
$outputName = '/^'.preg_replace('/(%[^%])+/', '.+', $outputName).'$/';
$outputName = '/^'.preg_replace('/(%[^%])+/', '.+', str_replace('/', '\/', $outputName)).'$/';
return $outputName;
}

Expand Down
13 changes: 11 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,18 @@ class Webgrind_MasterConfig
unlink(Webgrind_Config::xdebugOutputDir().$file['filename']);
$format[] = preg_quote($file['filename'], '/');
}
$files = preg_grep('/'.implode('|', $format).'/', scandir(Webgrind_Config::storageDir()));
$iterator = new RegexIterator (
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
Webgrind_Config::storageDir(),
FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_PATHNAME
)
),
'/'.implode('|', $format).'/'
);
$files = iterator_to_array($iterator, false);
foreach ($files as $file) {
unlink(Webgrind_Config::storageDir().$file);
unlink($file);
}
sendJson(array('done' => true));
break;
Expand Down
15 changes: 13 additions & 2 deletions library/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ private function getInvokeUrl($file) {
* @return array Files
*/
private function getFiles($format, $dir) {
$list = preg_grep($format,scandir($dir));
// Since RecursiveDirectoryIterator returns absolute path - we need to add $dir and escape slashes
$format = str_replace('/^', "/^" . str_replace('/', '\/', $dir), $format);
$iterator = new RegexIterator (
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_PATHNAME)
),
$format
);

$list = iterator_to_array($iterator, false);
$files = array();

# Moved this out of loop to run faster
Expand All @@ -85,7 +94,9 @@ private function getFiles($format, $dir) {
$selfFile = '';

foreach ($list as $file) {
$absoluteFilename = $dir.$file;
$absoluteFilename = $file;
//getting back relative path
$file = preg_replace('#^'.$dir.'#', '', $file, 1);

// Exclude webgrind preprocessed files
if (false !== strstr($absoluteFilename, Webgrind_Config::$preprocessedSuffix))
Expand Down