00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Core_Model_Config_Options extends Varien_Object
00035 {
00036
00037
00038
00039
00040
00041 protected $_dirExists = array();
00042
00043
00044
00045
00046 protected function _construct()
00047 {
00048 $appRoot= Mage::getRoot();
00049 $root = dirname($appRoot);
00050
00051 $this->_data['app_dir'] = $appRoot;
00052 $this->_data['base_dir'] = $root;
00053 $this->_data['code_dir'] = $appRoot.DS.'code';
00054 $this->_data['design_dir'] = $appRoot.DS.'design';
00055 $this->_data['etc_dir'] = $appRoot.DS.'etc';
00056 $this->_data['lib_dir'] = $root.DS.'lib';
00057 $this->_data['locale_dir'] = $appRoot.DS.'locale';
00058 $this->_data['media_dir'] = $root.DS.'media';
00059 $this->_data['skin_dir'] = $root.DS.'skin';
00060 $this->_data['var_dir'] = $this->getVarDir();
00061 $this->_data['tmp_dir'] = $this->_data['var_dir'].DS.'tmp';
00062 $this->_data['cache_dir'] = $this->_data['var_dir'].DS.'cache';
00063 $this->_data['log_dir'] = $this->_data['var_dir'].DS.'log';
00064 $this->_data['session_dir'] = $this->_data['var_dir'].DS.'session';
00065 $this->_data['upload_dir'] = $this->_data['media_dir'].DS.'upload';
00066 $this->_data['export_dir'] = $this->_data['var_dir'].DS.'export';
00067 }
00068
00069 public function getDir($type)
00070 {
00071 $this->_construct();
00072 $method = 'get'.ucwords($type).'Dir';
00073 $dir = $this->$method();
00074 if (!$dir) {
00075 throw Mage::exception('Mage_Core', 'Invalid dir type requested: '.$type);
00076 }
00077 return $dir;
00078 }
00079
00080 public function getAppDir()
00081 {
00082
00083 return $this->_data['app_dir'];
00084 }
00085
00086 public function getBaseDir()
00087 {
00088
00089 return $this->_data['base_dir'];
00090 }
00091
00092 public function getCodeDir()
00093 {
00094
00095 return $this->_data['code_dir'];
00096 }
00097
00098 public function getDesignDir()
00099 {
00100
00101 return $this->_data['design_dir'];
00102 }
00103
00104 public function getEtcDir()
00105 {
00106
00107 return $this->_data['etc_dir'];
00108 }
00109
00110 public function getLibDir()
00111 {
00112
00113 return $this->_data['lib_dir'];
00114 }
00115
00116 public function getLocaleDir()
00117 {
00118
00119 return $this->_data['locale_dir'];
00120 }
00121
00122 public function getMediaDir()
00123 {
00124
00125 return $this->_data['media_dir'];
00126 }
00127
00128 public function getSkinDir()
00129 {
00130
00131 return $this->_data['skin_dir'];
00132 }
00133
00134 public function getSysTmpDir()
00135 {
00136 return sys_get_temp_dir();
00137 }
00138
00139 public function getVarDir()
00140 {
00141
00142 $dir = isset($this->_data['var_dir']) ? $this->_data['var_dir'] : $this->_data['base_dir'].DS.'var';
00143 if (!$this->createDirIfNotExists($dir)) {
00144 $dir = $this->getSysTmpDir().DS.'magento'.DS.'var';
00145 if (!$this->createDirIfNotExists($dir)) {
00146 throw new Mage_Core_Exception('Unable to find writable var_dir');
00147 }
00148 }
00149 return $dir;
00150 }
00151
00152 public function getTmpDir()
00153 {
00154
00155 $dir = $this->_data['tmp_dir'];
00156 if (!$this->createDirIfNotExists($dir)) {
00157 $dir = $this->getSysTmpDir().DS.'magento'.DS.'tmp';
00158 if (!$this->createDirIfNotExists($dir)) {
00159 throw new Mage_Core_Exception('Unable to find writable tmp_dir');
00160 }
00161 }
00162 return $dir;
00163 }
00164
00165 public function getCacheDir()
00166 {
00167
00168 $dir = $this->_data['cache_dir'];
00169 $this->createDirIfNotExists($dir);
00170 return $dir;
00171 }
00172
00173 public function getLogDir()
00174 {
00175
00176 $dir = $this->_data['log_dir'];
00177 $this->createDirIfNotExists($dir);
00178 return $dir;
00179 }
00180
00181 public function getSessionDir()
00182 {
00183
00184 $dir = $this->_data['session_dir'];
00185 $this->createDirIfNotExists($dir);
00186 return $dir;
00187 }
00188
00189 public function getUploadDir()
00190 {
00191
00192 $dir = $this->_data['upload_dir'];
00193 $this->createDirIfNotExists($dir);
00194 return $dir;
00195 }
00196
00197 public function getExportDir()
00198 {
00199
00200 $dir = $this->_data['export_dir'];
00201 $this->createDirIfNotExists($dir);
00202 return $dir;
00203 }
00204
00205 public function createDirIfNotExists($dir)
00206 {
00207 if (!empty($this->_dirExists[$dir])) {
00208 return true;
00209 }
00210 if (file_exists($dir)) {
00211 if (!is_dir($dir)) {
00212 return false;
00213 }
00214 if (!is_dir_writeable($dir)) {
00215 return false;
00216 }
00217 } else {
00218 if (!@mkdir($dir, 0777, true)) {
00219 return false;
00220 }
00221 }
00222 $this->_dirExists[$dir] = true;
00223 return true;
00224 }
00225 }