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