Public Member Functions | |
__construct ($path, $isRecursion=true, $recursionLevel=0) | |
getDirName () | |
getRecursion () | |
getRecursionLevel () | |
getPath () | |
setPath ($path, $isRecursion='') | |
setRecursion ($isRecursion) | |
setRecursionLevel ($recursionLevel) | |
lastDir () | |
addItem (IFactory $item) | |
useFilter ($useFilter) | |
filesName () | |
getFilesName (&$files) | |
filesPaths () | |
getFilesPaths (&$paths) | |
filesObj () | |
getFilesObj (&$objs) | |
dirsName () | |
getDirsName (&$dirs) | |
__toArray () | |
toArray (&$arr) | |
__toXml ($addOpenTag=true, $rootName='Struct') | |
toXml (&$xml, $recursionLevel=0, $addOpenTag=true, $rootName='Struct') | |
addFilter ($field, $value) | |
Static Public Member Functions | |
static | getLastDir ($path) |
Protected Member Functions | |
parseDir () | |
setFilesFilter ($filter) | |
_renderFilters () | |
Protected Attributes | |
$_path = '' | |
$_dirName = '' | |
$_recursionLevel = 0 | |
$_isRecursion | |
$_filters = array() |
Definition at line 6 of file Collection.php.
__construct | ( | $ | path, | |
$ | isRecursion = true , |
|||
$ | recursionLevel = 0 | |||
) |
Constructor
string | $path - path to directory | |
bool | $is_recursion - use or not recursion |
Definition at line 19 of file Collection.php.
00020 { 00021 parent::__construct(); 00022 $this->setPath($path); 00023 $this->_dirName = $this->lastDir(); 00024 $this->setRecursion($isRecursion); 00025 $this->setRecursionLevel($recursionLevel); 00026 if($this->getRecursion() || $this->getRecursionLevel()==0){ 00027 $this->parseDir(); 00028 } 00029 }
__toArray | ( | ) |
__toXml | ( | $ | addOpenTag = true , |
|
$ | rootName = 'Struct' | |||
) |
get this collection as xml
bool | $addOpenTag - add or not header of xml | |
string | $rootName - root element name |
Definition at line 293 of file Collection.php.
00294 { 00295 $xml=''; 00296 $this->toXml($xml,$addOpenTag,$rootName); 00297 return $xml; 00298 }
_renderFilters | ( | ) | [protected] |
apply filters
Reimplemented from Varien_Data_Collection.
Definition at line 326 of file Collection.php.
00327 { 00328 $exts = array(); 00329 $names = array(); 00330 $regName = array(); 00331 foreach ($this->_filters as $filter){ 00332 switch ($filter['field']){ 00333 case 'extension': 00334 if(is_array($filter['value'])){ 00335 foreach ($filter['value'] as $value){ 00336 $exts[] = $value; 00337 } 00338 } else { 00339 $exts[] = $filter['value']; 00340 } 00341 break; 00342 case 'name': 00343 if(is_array($filter['value'])){ 00344 foreach ($filter['value'] as $value){ 00345 $names[] = $filter['value']; 00346 } 00347 } else { 00348 $names[] = $filter['value']; 00349 } 00350 break; 00351 case 'regName': 00352 if(is_array($filter['value'])){ 00353 foreach ($filter['value'] as $value){ 00354 $regName[] = $filter['value']; 00355 } 00356 } else { 00357 $regName[] = $filter['value']; 00358 } 00359 break; 00360 } 00361 } 00362 $filter = array(); 00363 if(count($exts)>0) { 00364 $filter['extension'] = $exts; 00365 } else { 00366 $filter['extension'] = null; 00367 } 00368 if(count($names)>0) { 00369 $filter['name']=$names; 00370 } else { 00371 $filter['name']=null; 00372 } 00373 if(count($regName)>0) { 00374 00375 $filter['regName']=$regName; 00376 } else { 00377 $filter['regName']=null; 00378 } 00379 $this->setFilesFilter($filter); 00380 }
addFilter | ( | $ | field, | |
$ | value | |||
) |
add filter
Definition at line 385 of file Collection.php.
00386 { 00387 $filter = array(); 00388 $filter['field'] = $field; 00389 $filter['value'] = $value; 00390 $this->_filters[] = $filter; 00391 $this->_isFiltersRendered = false; 00392 $this->walk('addFilter',array($field, $value)); 00393 return $this; 00394 }
addItem | ( | IFactory $ | item | ) |
add item to collection
IFactory | $item - item of collection |
Definition at line 133 of file Collection.php.
dirsName | ( | ) |
get names of dirs of current collection
Definition at line 234 of file Collection.php.
00235 { 00236 $dir = array(); 00237 $this->getDirsName($dir); 00238 return $dir; 00239 }
filesName | ( | ) |
get files names of current collection
Definition at line 170 of file Collection.php.
00171 { 00172 $files = array(); 00173 $this->getFilesName($files); 00174 return $files; 00175 00176 }
filesObj | ( | ) |
get SplFileObject objects of files of current collection
Definition at line 213 of file Collection.php.
00214 { 00215 $objs = array(); 00216 $this->getFilesObj($objs); 00217 return $objs; 00218 }
filesPaths | ( | ) |
get files paths of current collection
Definition at line 192 of file Collection.php.
00193 { 00194 $paths = array(); 00195 $this->getFilesPaths($paths); 00196 return $paths; 00197 }
getDirName | ( | ) |
Get name of this directory
Definition at line 35 of file Collection.php.
getDirsName | ( | &$ | dirs | ) |
get names of dirs of current collection
array | $dirs - array of names of dirs |
Implements IFactory.
Definition at line 246 of file Collection.php.
00247 { 00248 $this->walk('getDirsName', array(&$dirs)); 00249 if($this->getRecursionLevel()>0) 00250 $dirs[] = $this->getDirName(); 00251 }
getFilesName | ( | &$ | files | ) |
get files names of current collection
array | $files - array of files names |
Implements IFactory.
Definition at line 183 of file Collection.php.
getFilesObj | ( | &$ | objs | ) |
get SplFileObject objects of files of current collection
array | $objs - array of SplFileObject objects |
Implements IFactory.
Definition at line 225 of file Collection.php.
getFilesPaths | ( | &$ | paths | ) |
get files paths of current collection
array | $files - array of files paths |
Implements IFactory.
Definition at line 204 of file Collection.php.
static getLastDir | ( | $ | path | ) | [static] |
get latest dir in the path
string | $path - path to directory |
Definition at line 122 of file Collection.php.
00122 { 00123 if($path=='') $path = $this->getPath(); 00124 $last = strrpos($path, "/"); 00125 return substr($path,$last+1); 00126 }
getPath | ( | ) |
getRecursion | ( | ) |
getRecursionLevel | ( | ) |
lastDir | ( | ) |
get latest dir in the path
string | $path - path to directory |
Definition at line 112 of file Collection.php.
00113 { 00114 return self::getLastDir($this->getPath()); 00115 }
parseDir | ( | ) | [protected] |
parse this directory
Definition at line 142 of file Collection.php.
00143 { 00144 $this->clear(); 00145 $iter = new RecursiveDirectoryIterator($this->getPath()); 00146 while ($iter->valid()) { 00147 $curr = (string)$iter->getSubPathname(); 00148 if (!$iter->isDot() && $curr[0]!='.'){ 00149 $this->addItem(Varien_Directory_Factory::getFactory($iter->current(),$this->getRecursion(),$this->getRecursionLevel())); 00150 } 00151 $iter->next(); 00152 } 00153 }
setFilesFilter | ( | $ | filter | ) | [protected] |
set filters for files
array | $filter - array of filters |
Definition at line 258 of file Collection.php.
setPath | ( | $ | path, | |
$ | isRecursion = '' | |||
) |
Set path to this directory
string | $path - path to this directory | |
bool | $isRecursion - use or not recursion |
Definition at line 72 of file Collection.php.
00073 { 00074 if(is_dir($path)){ 00075 if(isset($this->_path) && $this->_path!=$path && $this->_path!=''){ 00076 $this->_path = $path; 00077 if($isRecursion!='')$this->_isRecursion = $isRecursion; 00078 $this->parseDir(); 00079 } else { 00080 $this->_path = $path; 00081 } 00082 } else { 00083 throw new Exception($path. 'is not dir.'); 00084 } 00085 }
setRecursion | ( | $ | isRecursion | ) |
Set recursion
bool | $isRecursion - use or not recursion |
Definition at line 92 of file Collection.php.
setRecursionLevel | ( | $ | recursionLevel | ) |
Set level of recursion
int | $recursionLevel - level of recursion |
Definition at line 102 of file Collection.php.
toArray | ( | &$ | arr | ) |
display this collection as array
array | &$arr - this collection array |
Implements IFactory.
Definition at line 278 of file Collection.php.
00279 { 00280 if($this->getRecursionLevel()>0){ 00281 $arr[$this->getDirName()] = array(); 00282 $this->walk('toArray', array(&$arr[$this->getDirName()])); 00283 } else { 00284 $this->walk('toArray', array(&$arr)); 00285 } 00286 }
toXml | ( | &$ | xml, | |
$ | recursionLevel = 0 , |
|||
$ | addOpenTag = true , |
|||
$ | rootName = 'Struct' | |||
) |
get this collection as xml
string | &$xml - xml | |
bool | $addOpenTag - add or not header of xml | |
string | $rootName - root element name |
Implements IFactory.
Definition at line 306 of file Collection.php.
00307 { 00308 if($recursionLevel==0 ){ 00309 $xml = ''; 00310 if($addOpenTag) 00311 $xml.= '<?xml version="1.0" encoding="UTF-8"?>'."\n"; 00312 $xml.= '<'.$rootName.'>'."\n"; 00313 } 00314 $recursionLevel = $this->getRecursionLevel(); 00315 $xml.= str_repeat("\t",$recursionLevel+1)."<$this->_dirName>\n"; 00316 $this->walk('toXml', array(&$xml,$recursionLevel,$addOpenTag,$rootName)); 00317 $xml.= str_repeat("\t",$recursionLevel+1)."</$this->_dirName>"."\n"; 00318 if($recursionLevel==0 ){ 00319 $xml.= '</'.$rootName.'>'."\n"; 00320 } 00321 }
useFilter | ( | $ | useFilter | ) |
set filter using
bool | $useFilter - filter using |
Implements IFactory.
Definition at line 160 of file Collection.php.
00161 { 00162 $this->_renderFilters(); 00163 $this->walk('useFilter', array($useFilter)); 00164 }
$_dirName = '' [protected] |
Definition at line 8 of file Collection.php.
$_filters = array() [protected] |
$_isRecursion [protected] |
Definition at line 10 of file Collection.php.
$_path = '' [protected] |
Definition at line 7 of file Collection.php.
$_recursionLevel = 0 [protected] |
Definition at line 9 of file Collection.php.