Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.

Commit 7179b80

Browse files
committed
* removePattern() is now using glob instead of RecursiveDirectoryIterator
1 parent 6fde25a commit 7179b80

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

lib/cache/sfRawFileCache.class.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,50 @@ protected function write($path, $data, $timeout)
9393
return true;
9494
}
9595

96-
protected function getBasepath(sfRoute $pattern)
96+
protected function getPathEnd(sfRoute $pattern)
9797
{
98-
$basepath = $this->getOption('cache_dir');
98+
$path = '';
99+
$tokens = array_reverse($pattern->getTokens());
100+
foreach($tokens as $token)
101+
{
102+
if('text' == $token[0] || 'separator' == $token[0])
103+
{
104+
$path = $token[2].$path;
105+
continue;
106+
}
107+
break;
108+
}
109+
return $path;
110+
}
111+
112+
protected function getPathStart(sfRoute $pattern)
113+
{
114+
$path = '';
99115
foreach($pattern->getTokens() as $token)
100116
{
101117
if('text' == $token[0] || 'separator' == $token[0])
102118
{
103-
$basepath .= $token[2];
119+
$path .= $token[2];
104120
continue;
105121
}
106122
break;
107123
}
108-
return $basepath;
124+
return $path;
125+
}
126+
127+
protected function getGlobPatterns(sfRoute $route)
128+
{
129+
$routeOptions = $route->getOptions();
130+
$pathBase = $this->getOption('cache_dir');
131+
$pathStart = $this->getPathStart($route);
132+
$pathEnd = $this->getPathEnd($route);
133+
$depth = substr_count($pathStart.'*'.$pathEnd, '/');
134+
$paths = array();
135+
for($i=$depth; $i<=$routeOptions['max_folder_depth']; $i++)
136+
{
137+
$paths[] = $pathBase.$pathStart.str_repeat('*/', $i - $depth).'*'.$pathEnd;;
138+
}
139+
return $paths;
109140
}
110141

111142
/**
@@ -118,16 +149,13 @@ public function removePattern($pattern)
118149
return parent::removePattern($pattern);
119150
}
120151

121-
$basepath = $this->getBasepath($pattern);
122-
123-
if(file_exists($basepath))
152+
$paths = $this->getGlobPatterns($pattern);
153+
foreach($paths as $path)
124154
{
125-
$flags = defined('RecursiveDirectoryIterator::FOLLOW_SYMLINKS') ? RecursiveDirectoryIterator::FOLLOW_SYMLINKS : 0;
126-
127-
$iterator = new sfRouteFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basepath, $flags)), $pattern);
128-
foreach ($iterator as $path)
155+
$files = glob($path, GLOB_BRACE);
156+
foreach($files as $file)
129157
{
130-
@unlink($path->getRealpath());
158+
@unlink($file);
131159
}
132160
}
133161
}

0 commit comments

Comments
 (0)