OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxfilecollector.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
17  protected $_sBaseDirectory;
18 
24  protected $_aFiles;
25 
31  public function setBaseDirectory($sDir)
32  {
33  if (!empty($sDir)) {
34  $this->_sBaseDirectory = $sDir;
35  }
36  }
37 
43  public function getFiles()
44  {
45  return $this->_aFiles;
46  }
47 
56  public function addFile($sFile)
57  {
58  if (empty($sFile)) {
59  throw new Exception('Parameter $sFile is empty!');
60  }
61 
62  if (empty($this->_sBaseDirectory)) {
63  throw new Exception('Base directory is not set, please use setter setBaseDirectory!');
64  }
65 
66  if (is_file($this->_sBaseDirectory . $sFile)) {
67 
68  $this->_aFiles[] = $sFile;
69 
70  return true;
71  }
72 
73  return false;
74  }
75 
76 
87  public function addDirectoryFiles($sFolder, $aExtensions = array(), $blRecursive = false)
88  {
89  if (empty($sFolder)) {
90  throw new Exception('Parameter $sFolder is empty!');
91  }
92 
93  if (empty($this->_sBaseDirectory)) {
94  throw new Exception('Base directory is not set, please use setter setBaseDirectory!');
95  }
96 
97  $aCurrentList = array();
98 
99  if (!is_dir($this->_sBaseDirectory . $sFolder)) {
100  return;
101  }
102 
103  $handle = opendir($this->_sBaseDirectory . $sFolder);
104 
105  while ($sFile = readdir($handle)) {
106 
107  if ($sFile != "." && $sFile != "..") {
108  if (is_dir($this->_sBaseDirectory . $sFolder . $sFile)) {
109  if ($blRecursive) {
110  $aResultList = $this->addDirectoryFiles($sFolder . $sFile . '/', $aExtensions, $blRecursive);
111 
112  if (is_array($aResultList)) {
113  $aCurrentList = array_merge($aCurrentList, $aResultList);
114  }
115  }
116  } else {
117  $sExt = substr(strrchr($sFile, '.'), 1);
118 
119  if ((!empty($aExtensions) && is_array($aExtensions) && in_array($sExt, $aExtensions)) ||
120  (empty($aExtensions))
121  ) {
122 
123  $this->addFile($sFolder . $sFile);
124  }
125  }
126  }
127  }
128  closedir($handle);
129  }
130 }