Varien_Directory_Collection Class Reference

Inheritance diagram for Varien_Directory_Collection:

Varien_Data_Collection IFactory Mage_Core_Model_Mysql4_Design_Theme

List of all members.

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()


Detailed Description

Definition at line 6 of file Collection.php.


Constructor & Destructor Documentation

__construct ( path,
isRecursion = true,
recursionLevel = 0 
)

Constructor

Parameters:
string $path - path to directory
bool $is_recursion - use or not recursion
Returns:
none

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     }


Member Function Documentation

__toArray (  ) 

display this collection as array

Returns:
array

Definition at line 267 of file Collection.php.

00268     {
00269         $arr = array();
00270         $this->toArray($arr);
00271         return $arr;
00272     }

__toXml ( addOpenTag = true,
rootName = 'Struct' 
)

get this collection as xml

Parameters:
bool $addOpenTag - add or not header of xml
string $rootName - root element name
Returns:
none

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

Returns:
none

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

Returns:
none

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

Parameters:
IFactory $item - item of collection
Returns:
none

Definition at line 133 of file Collection.php.

00134     {
00135         $this->_items[] = $item;
00136     }

dirsName (  ) 

get names of dirs of current collection

Returns:
array - array of names of dirs

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

Returns:
array - 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

Returns:
array - array of SplFileObject objects

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

Returns:
array - 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

Returns:
string - name of this directory

Definition at line 35 of file Collection.php.

00036     {
00037         return $this->_dirName;
00038     }

getDirsName ( &$  dirs  ) 

get names of dirs of current collection

Parameters:
array $dirs - array of names of dirs
Returns:
none

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

Parameters:
array $files - array of files names
Returns:
none

Implements IFactory.

Definition at line 183 of file Collection.php.

00184     {
00185         $this->walk('getFilesName', array(&$files));
00186     }

getFilesObj ( &$  objs  ) 

get SplFileObject objects of files of current collection

Parameters:
array $objs - array of SplFileObject objects
Returns:
none

Implements IFactory.

Definition at line 225 of file Collection.php.

00226     {
00227         $this->walk('getFilesObj', array(&$objs));
00228     }

getFilesPaths ( &$  paths  ) 

get files paths of current collection

Parameters:
array $files - array of files paths
Returns:
none

Implements IFactory.

Definition at line 204 of file Collection.php.

00205     {
00206         $this->walk('getFilesPaths', array(&$paths));
00207     }

static getLastDir ( path  )  [static]

get latest dir in the path

Parameters:
string $path - path to directory
Returns:
string - latest dir in the path

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 (  ) 

Get path

Returns:
string - path to this directory

Definition at line 62 of file Collection.php.

00063     {
00064         return $this->_path;
00065     }

getRecursion (  ) 

Get recursion

Returns:
bool - is or not recursion

Definition at line 44 of file Collection.php.

00045     {
00046         return $this->_isRecursion;
00047     }

getRecursionLevel (  ) 

Get recursion level

Returns:
int - recursion level

Definition at line 53 of file Collection.php.

00054     {
00055         return $this->_recursionLevel;
00056     }

lastDir (  ) 

get latest dir in the path

Parameters:
string $path - path to directory
Returns:
string - latest dir in the path

Definition at line 112 of file Collection.php.

00113     {
00114         return self::getLastDir($this->getPath());
00115     }

parseDir (  )  [protected]

parse this directory

Returns:
none

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

Parameters:
array $filter - array of filters
Returns:
none

Definition at line 258 of file Collection.php.

00259     {
00260         $this->walk('setFilesFilter', array($filter));
00261     }

setPath ( path,
isRecursion = '' 
)

Set path to this directory

Parameters:
string $path - path to this directory
bool $isRecursion - use or not recursion
Returns:
none

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

Parameters:
bool $isRecursion - use or not recursion
Returns:
none

Definition at line 92 of file Collection.php.

00093     {
00094         $this->_isRecursion = $isRecursion;
00095     }

setRecursionLevel ( recursionLevel  ) 

Set level of recursion

Parameters:
int $recursionLevel - level of recursion
Returns:
none

Definition at line 102 of file Collection.php.

00103     {
00104         $this->_recursionLevel = $recursionLevel;
00105     }

toArray ( &$  arr  ) 

display this collection as array

Parameters:
array &$arr - this collection array
Returns:
none

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

Parameters:
string &$xml - xml
bool $addOpenTag - add or not header of xml
string $rootName - root element name
Returns:
none

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

Parameters:
bool $useFilter - filter using
Returns:
none

Implements IFactory.

Definition at line 160 of file Collection.php.

00161     {
00162         $this->_renderFilters();
00163         $this->walk('useFilter', array($useFilter));
00164     }


Member Data Documentation

$_dirName = '' [protected]

Definition at line 8 of file Collection.php.

$_filters = array() [protected]

Reimplemented from Varien_Data_Collection.

Definition at line 11 of file Collection.php.

$_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.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:25:01 2009 for Magento by  doxygen 1.5.8