/library/Cream/Environment.php

https://github.com/WebTricks/WebTricks-CMS · PHP · 195 lines · 64 code · 15 blank · 116 comment · 0 complexity · cbedfb2f93fe14b432be5a6e54bd94a1 MD5 · raw file

  1. <?php
  2. /**
  3. * WebTricks - PHP Framework
  4. *
  5. * LICENSE
  6. *
  7. * For the full copyright and license information, please view the
  8. * following URL: http://www.webtricksframework.com/license
  9. *
  10. * DISCLAIMER
  11. *
  12. * Do not edit or add to this file if you wish to upgrade to newer versions in
  13. * the future. If you wish to customize WebTricks for your needs please go to
  14. * http://www.webtricksframework.com for more information.
  15. *
  16. * @copyright Copyright (c) 2007-2010 Cream (http://www.cream.nl)
  17. * @license http://www.webtricksframework.com/license
  18. */
  19. /**
  20. * Provides information about, and means to manipulate, the current PHP
  21. * environment and platform.
  22. *
  23. * @package Cream
  24. * @author Danny Verkade
  25. */
  26. class Cream_Environment extends Cream_ApplicationComponent
  27. {
  28. /**
  29. * Create an instance of this class
  30. *
  31. * @return Cream_Environment
  32. */
  33. public static function instance()
  34. {
  35. return Cream::instance(__CLASS__);
  36. }
  37. /**
  38. * Gets the information about a setting an returns it.
  39. *
  40. * @param string $name
  41. * @return string|integer|boolean
  42. */
  43. protected function getSetting($name)
  44. {
  45. return ini_get($name);
  46. }
  47. /**
  48. * Sets an environment setting. Returns true if it has been completed
  49. * succesfully, otherwise returns false.
  50. *
  51. * @param string $name
  52. * @param string|integer|boolean $value
  53. * @return boolean
  54. */
  55. protected function setSetting($name, $value)
  56. {
  57. return ini_set($name, $value);
  58. }
  59. /**
  60. * This sets the maximum amount of memory in bytes that a script is allowed
  61. * to allocate. This helps prevent poorly written scripts for eating up all
  62. * available memory on a server. Note that to have no memory limit, set this
  63. * directive to -1. Example: 128M for 128 Megabyte of memory limit.
  64. *
  65. * @param string $memoryLimit
  66. */
  67. public function setMemoryLimit($memoryLimit)
  68. {
  69. return $this->setSetting('memory_limit', $memoryLimit);
  70. }
  71. /**
  72. * Returns the memory limit which can be used by the PHP script
  73. *
  74. * @return string
  75. */
  76. public function getMemoryLimit()
  77. {
  78. return $this->getSetting('memory_limit');
  79. }
  80. /**
  81. * This sets the maximum time in seconds a script is allowed to run before
  82. * it is terminated by the parser. This helps prevent poorly written scripts
  83. * from tying up the server.
  84. *
  85. * @param integer $maxExecutionTime
  86. * @return boolean
  87. */
  88. public function setMaxExecutionTime($maxExecutionTime)
  89. {
  90. return $this->setSetting('max_execution_time', $maxExecutionTime);
  91. }
  92. /**
  93. * Returns the maximum time in seconds when a script is terminated.
  94. *
  95. * @return integer
  96. */
  97. public function getMaxExecutionTime()
  98. {
  99. return $this->getSetting('max_execution_time');
  100. }
  101. /**
  102. * Sets max size of post data allowed.
  103. *
  104. * @param string $maxPostSize
  105. * @return boolean
  106. */
  107. public function setMaxPostSize($maxPostSize)
  108. {
  109. return $this->setSetting('max_post_size', $maxPostSize);
  110. }
  111. /**
  112. * Returns the max post size
  113. *
  114. * @return string
  115. */
  116. public function getMaxPostSize()
  117. {
  118. return $this->getSetting('max_post_size');
  119. }
  120. /**
  121. * The maximum size of an uploaded file.
  122. *
  123. * @param string $maxUploadFilesize
  124. * @return boolean
  125. */
  126. public function MaxUploadFilesize($maxUploadFilesize)
  127. {
  128. return $this->setSetting('upload_max_filesize', $maxUploadFilesize);
  129. }
  130. /**
  131. * Returns the maximum upload size
  132. *
  133. * @return string
  134. */
  135. public function getMaxUploadFilesize()
  136. {
  137. return $this->getSetting('upload_max_filesize');
  138. }
  139. /**
  140. * Used under Windows only: host name or IP address of the SMTP server PHP
  141. * should use for mail sent with the mail() function.
  142. *
  143. * @param string $smtpServer
  144. * @return boolean
  145. */
  146. public function setSmtpServer($smtpServer)
  147. {
  148. return $this->setSetting('SMTP', $smtpServer);
  149. }
  150. /**
  151. * Returns the name of the SMTP server currently used
  152. *
  153. * @return string
  154. */
  155. public function getSmtpServer()
  156. {
  157. return $this->getSetting('SMTP');
  158. }
  159. /**
  160. * Used under Windows only: Number of the port to connect to the server
  161. * specified with the SMTP setting when sending mail with mail(); defaults
  162. * to 25.
  163. *
  164. * @param integer $smtpPort
  165. * @return boolean
  166. */
  167. public function setSmtpPort($smtpPort)
  168. {
  169. return $this->setSetting('smtp_port', $smtpPort);
  170. }
  171. /**
  172. * Returns the SMTP port currently used.
  173. *
  174. * @return integer
  175. */
  176. public function getSmtpPort()
  177. {
  178. return $this->getSetting('smtp_port');
  179. }
  180. }