@@ -93,19 +93,50 @@ protected function write($path, $data, $timeout)
93
93
return true ;
94
94
}
95
95
96
- protected function getBasepath (sfRoute $ pattern )
96
+ protected function getPathEnd (sfRoute $ pattern )
97
97
{
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 = '' ;
99
115
foreach ($ pattern ->getTokens () as $ token )
100
116
{
101
117
if ('text ' == $ token [0 ] || 'separator ' == $ token [0 ])
102
118
{
103
- $ basepath .= $ token [2 ];
119
+ $ path .= $ token [2 ];
104
120
continue ;
105
121
}
106
122
break ;
107
123
}
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 ;
109
140
}
110
141
111
142
/**
@@ -118,16 +149,13 @@ public function removePattern($pattern)
118
149
return parent ::removePattern ($ pattern );
119
150
}
120
151
121
- $ basepath = $ this ->getBasepath ($ pattern );
122
-
123
- if (file_exists ($ basepath ))
152
+ $ paths = $ this ->getGlobPatterns ($ pattern );
153
+ foreach ($ paths as $ path )
124
154
{
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 )
129
157
{
130
- @unlink ($ path -> getRealpath () );
158
+ @unlink ($ file );
131
159
}
132
160
}
133
161
}
0 commit comments