Go to the documentation of this file.00001 <?php
00002
00009 class oxModuleFilesValidator implements oxIModuleValidator
00010 {
00011
00017 private $_aMissingFiles = array();
00018
00024 private $_sPathToModuleDirectory = null;
00025
00031 public function getPathToModuleDirectory()
00032 {
00033 if (is_null($this->_sPathToModuleDirectory)) {
00034 $this->setPathToModuleDirectory(oxRegistry::getConfig()->getModulesDir());
00035 }
00036
00037 return $this->_sPathToModuleDirectory;
00038 }
00039
00045 public function setPathToModuleDirectory($sPathToModuleDirectory)
00046 {
00047 $this->_sPathToModuleDirectory = $sPathToModuleDirectory;
00048 }
00049
00059 public function validate(oxModule $oModule)
00060 {
00061 $this->_resetMissingFiles();
00062 $blModuleValid = $this->_allModuleExtensionsExists($oModule);
00063 $blModuleValid = $this->_allModuleFilesExists($oModule) && $blModuleValid;
00064
00065 return $blModuleValid;
00066 }
00067
00073 public function getMissingFiles()
00074 {
00075 return $this->_aMissingFiles;
00076 }
00077
00081 protected function _resetMissingFiles()
00082 {
00083 $this->_aMissingFiles = array();
00084 }
00085
00093 protected function _allModuleExtensionsExists($oModule)
00094 {
00095 $aModuleExtendedFiles = $oModule->getExtensions();
00096 $blAllModuleExtensionsExists = $this->_allFilesExists($aModuleExtendedFiles, true, 'extensions');
00097
00098 return $blAllModuleExtensionsExists;
00099 }
00100
00108 protected function _allModuleFilesExists($oModule)
00109 {
00110 $aModuleExtendedFiles = $oModule->getFiles();
00111 $blAllModuleFilesExists = $this->_allFilesExists($aModuleExtendedFiles);
00112
00113 return $blAllModuleFilesExists;
00114
00115 }
00116
00126 private function _allFilesExists($aModuleExtendedFiles, $blAddExtension = false, $sListName = 'files')
00127 {
00128 $blAllModuleFilesExists = true;
00129 foreach ($aModuleExtendedFiles as $sModuleName => $sModulePath) {
00130 $sPathToModuleDirectory = $this->getPathToModuleDirectory();
00131 $sPathToModuleDirectory = $this->_addDirectorySeparatorAtTheEndIfNeeded($sPathToModuleDirectory);
00132 $sExtPath = $sPathToModuleDirectory . $sModulePath;
00133 if ($blAddExtension) {
00134 $sExtPath .= '.php';
00135 }
00136 if (!file_exists($sExtPath)) {
00137 $blAllModuleFilesExists = false;
00138 $this->_aMissingFiles[$sListName][$sModuleName] = $sModulePath;
00139 }
00140 }
00141
00142 return $blAllModuleFilesExists;
00143 }
00144
00152 private function _addDirectorySeparatorAtTheEndIfNeeded($sPathToModuleDirectory)
00153 {
00154 if (substr($sPathToModuleDirectory, -1) != DIRECTORY_SEPARATOR) {
00155 $sPathToModuleDirectory .= DIRECTORY_SEPARATOR;
00156
00157 return $sPathToModuleDirectory;
00158 }
00159
00160 return $sPathToModuleDirectory;
00161 }
00162 }