OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
oxmodulefilesvalidator.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
17  private $_aMissingFiles = array();
18 
24  private $_sPathToModuleDirectory = null;
25 
31  public function getPathToModuleDirectory()
32  {
33  if (is_null($this->_sPathToModuleDirectory)) {
34  $this->setPathToModuleDirectory(oxRegistry::getConfig()->getModulesDir());
35  }
36 
38  }
39 
45  public function setPathToModuleDirectory($sPathToModuleDirectory)
46  {
47  $this->_sPathToModuleDirectory = $sPathToModuleDirectory;
48  }
49 
59  public function validate(oxModule $oModule)
60  {
61  $this->_resetMissingFiles();
62  $blModuleValid = $this->_allModuleExtensionsExists($oModule);
63  $blModuleValid = $this->_allModuleFilesExists($oModule) && $blModuleValid;
64 
65  return $blModuleValid;
66  }
67 
73  public function getMissingFiles()
74  {
75  return $this->_aMissingFiles;
76  }
77 
81  protected function _resetMissingFiles()
82  {
83  $this->_aMissingFiles = array();
84  }
85 
93  protected function _allModuleExtensionsExists($oModule)
94  {
95  $aModuleExtendedFiles = $oModule->getExtensions();
96  $blAllModuleExtensionsExists = $this->_allFilesExists($aModuleExtendedFiles, true, 'extensions');
97 
98  return $blAllModuleExtensionsExists;
99  }
100 
108  protected function _allModuleFilesExists($oModule)
109  {
110  $aModuleExtendedFiles = $oModule->getFiles();
111  $blAllModuleFilesExists = $this->_allFilesExists($aModuleExtendedFiles);
112 
113  return $blAllModuleFilesExists;
114 
115  }
116 
126  private function _allFilesExists($aModuleExtendedFiles, $blAddExtension = false, $sListName = 'files')
127  {
128  $blAllModuleFilesExists = true;
129  foreach ($aModuleExtendedFiles as $sModuleName => $sModulePath) {
130  $sPathToModuleDirectory = $this->getPathToModuleDirectory();
131  $sPathToModuleDirectory = $this->_addDirectorySeparatorAtTheEndIfNeeded($sPathToModuleDirectory);
132  $sExtPath = $sPathToModuleDirectory . $sModulePath;
133  if ($blAddExtension) {
134  $sExtPath .= '.php';
135  }
136  if (!file_exists($sExtPath)) {
137  $blAllModuleFilesExists = false;
138  $this->_aMissingFiles[$sListName][$sModuleName] = $sModulePath;
139  }
140  }
141 
142  return $blAllModuleFilesExists;
143  }
144 
152  private function _addDirectorySeparatorAtTheEndIfNeeded($sPathToModuleDirectory)
153  {
154  if (substr($sPathToModuleDirectory, -1) != DIRECTORY_SEPARATOR) {
155  $sPathToModuleDirectory .= DIRECTORY_SEPARATOR;
156 
157  return $sPathToModuleDirectory;
158  }
159 
160  return $sPathToModuleDirectory;
161  }
162 }