PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/magento/app/code/core/Mage/Core/Model/Config/Options.php

https://bitbucket.org/jit_bec/shopifine
PHP | 233 lines | 151 code | 22 blank | 60 comment | 11 complexity | 6b76c6cf6338c1b1ae003a96f2615a9f MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Core
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Configuration options storage and logic
  28. *
  29. * @category Mage
  30. * @package Mage_Core
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Core_Model_Config_Options extends Varien_Object
  34. {
  35. /**
  36. * Var directory
  37. *
  38. * @var string
  39. */
  40. const VAR_DIRECTORY = 'var';
  41. /**
  42. * Flag cache for existing or already created directories
  43. *
  44. * @var array
  45. */
  46. protected $_dirExists = array();
  47. /**
  48. * Initialize default values of the options
  49. */
  50. protected function _construct()
  51. {
  52. $appRoot= Mage::getRoot();
  53. $root = dirname($appRoot);
  54. $this->_data['app_dir'] = $appRoot;
  55. $this->_data['base_dir'] = $root;
  56. $this->_data['code_dir'] = $appRoot.DS.'code';
  57. $this->_data['design_dir'] = $appRoot.DS.'design';
  58. $this->_data['etc_dir'] = $appRoot.DS.'etc';
  59. $this->_data['lib_dir'] = $root.DS.'lib';
  60. $this->_data['locale_dir'] = $appRoot.DS.'locale';
  61. $this->_data['media_dir'] = $root.DS.'media';
  62. $this->_data['skin_dir'] = $root.DS.'skin';
  63. $this->_data['var_dir'] = $this->getVarDir();
  64. $this->_data['tmp_dir'] = $this->_data['var_dir'].DS.'tmp';
  65. $this->_data['cache_dir'] = $this->_data['var_dir'].DS.'cache';
  66. $this->_data['log_dir'] = $this->_data['var_dir'].DS.'log';
  67. $this->_data['session_dir'] = $this->_data['var_dir'].DS.'session';
  68. $this->_data['upload_dir'] = $this->_data['media_dir'].DS.'upload';
  69. $this->_data['export_dir'] = $this->_data['var_dir'].DS.'export';
  70. }
  71. public function getDir($type)
  72. {
  73. $method = 'get'.ucwords($type).'Dir';
  74. $dir = $this->$method();
  75. if (!$dir) {
  76. throw Mage::exception('Mage_Core', 'Invalid dir type requested: '.$type);
  77. }
  78. return $dir;
  79. }
  80. public function getAppDir()
  81. {
  82. //return $this->getDataSetDefault('app_dir', Mage::getRoot());
  83. return $this->_data['app_dir'];
  84. }
  85. public function getBaseDir()
  86. {
  87. //return $this->getDataSetDefault('base_dir', dirname($this->getAppDir()));
  88. return $this->_data['base_dir'];
  89. }
  90. public function getCodeDir()
  91. {
  92. //return $this->getDataSetDefault('code_dir', $this->getAppDir().DS.'code');
  93. return $this->_data['code_dir'];
  94. }
  95. public function getDesignDir()
  96. {
  97. //return $this->getDataSetDefault('design_dir', $this->getAppDir().DS.'design');
  98. return $this->_data['design_dir'];
  99. }
  100. public function getEtcDir()
  101. {
  102. //return $this->getDataSetDefault('etc_dir', $this->getAppDir().DS.'etc');
  103. return $this->_data['etc_dir'];
  104. }
  105. public function getLibDir()
  106. {
  107. //return $this->getDataSetDefault('lib_dir', $this->getBaseDir().DS.'lib');
  108. return $this->_data['lib_dir'];
  109. }
  110. public function getLocaleDir()
  111. {
  112. //return $this->getDataSetDefault('locale_dir', $this->getAppDir().DS.'locale');
  113. return $this->_data['locale_dir'];
  114. }
  115. public function getMediaDir()
  116. {
  117. //return $this->getDataSetDefault('media_dir', $this->getBaseDir().DS.'media');
  118. return $this->_data['media_dir'];
  119. }
  120. public function getSkinDir()
  121. {
  122. //return $this->getDataSetDefault('skin_dir', $this->getBaseDir().DS.'skin');
  123. return $this->_data['skin_dir'];
  124. }
  125. public function getSysTmpDir()
  126. {
  127. return sys_get_temp_dir();
  128. }
  129. public function getVarDir()
  130. {
  131. //$dir = $this->getDataSetDefault('var_dir', $this->getBaseDir().DS.'var');
  132. $dir = isset($this->_data['var_dir']) ? $this->_data['var_dir']
  133. : $this->_data['base_dir'] . DS . self::VAR_DIRECTORY;
  134. if (!$this->createDirIfNotExists($dir)) {
  135. $dir = $this->getSysTmpDir().DS.'magento'.DS.'var';
  136. if (!$this->createDirIfNotExists($dir)) {
  137. throw new Mage_Core_Exception('Unable to find writable var_dir');
  138. }
  139. }
  140. return $dir;
  141. }
  142. public function getTmpDir()
  143. {
  144. //$dir = $this->getDataSetDefault('tmp_dir', $this->getVarDir().DS.'tmp');
  145. $dir = $this->_data['tmp_dir'];
  146. if (!$this->createDirIfNotExists($dir)) {
  147. $dir = $this->getSysTmpDir().DS.'magento'.DS.'tmp';
  148. if (!$this->createDirIfNotExists($dir)) {
  149. throw new Mage_Core_Exception('Unable to find writable tmp_dir');
  150. }
  151. }
  152. return $dir;
  153. }
  154. public function getCacheDir()
  155. {
  156. //$dir = $this->getDataSetDefault('cache_dir', $this->getVarDir().DS.'cache');
  157. $dir = $this->_data['cache_dir'];
  158. $this->createDirIfNotExists($dir);
  159. return $dir;
  160. }
  161. public function getLogDir()
  162. {
  163. //$dir = $this->getDataSetDefault('log_dir', $this->getVarDir().DS.'log');
  164. $dir = $this->_data['log_dir'];
  165. $this->createDirIfNotExists($dir);
  166. return $dir;
  167. }
  168. public function getSessionDir()
  169. {
  170. //$dir = $this->getDataSetDefault('session_dir', $this->getVarDir().DS.'session');
  171. $dir = $this->_data['session_dir'];
  172. $this->createDirIfNotExists($dir);
  173. return $dir;
  174. }
  175. public function getUploadDir()
  176. {
  177. //$dir = $this->getDataSetDefault('upload_dir', $this->getMediaDir().DS.'upload');
  178. $dir = $this->_data['upload_dir'];
  179. $this->createDirIfNotExists($dir);
  180. return $dir;
  181. }
  182. public function getExportDir()
  183. {
  184. //$dir = $this->getDataSetDefault('export_dir', $this->getVarDir().DS.'export');
  185. $dir = $this->_data['export_dir'];
  186. $this->createDirIfNotExists($dir);
  187. return $dir;
  188. }
  189. public function createDirIfNotExists($dir)
  190. {
  191. if (!empty($this->_dirExists[$dir])) {
  192. return true;
  193. }
  194. if (file_exists($dir)) {
  195. if (!is_dir($dir)) {
  196. return false;
  197. }
  198. if (!is_dir_writeable($dir)) {
  199. return false;
  200. }
  201. } else {
  202. $oldUmask = umask(0);
  203. if (!@mkdir($dir, 0777, true)) {
  204. return false;
  205. }
  206. umask($oldUmask);
  207. }
  208. $this->_dirExists[$dir] = true;
  209. return true;
  210. }
  211. }