Source for file PHPConfigValueRequirement.class.php

Documentation is available at PHPConfigValueRequirement.class.php

  1. <?php
  2. /**
  3. * @package polyphony.startupcheck
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: PHPConfigValueRequirement.class.php,v 1.6 2007/09/19 14:04:50 adamfranco Exp $
  9. */
  10.  
  11. /**
  12. * @name PHPINI_EQUAL
  13. */
  14. define("PHPINI_EQUAL",0);
  15.  
  16. /**
  17. * @name PHPINI_BOOLEAN
  18. */
  19. define("PHPINI_BOOLEAN",1);
  20.  
  21. /**
  22. * @name PHPINI_LESS
  23. */
  24. define("PHPINI_LESS",2);
  25.  
  26. /**
  27. * @name PHPINI_GREATER
  28. */
  29. define("PHPINI_GREATER",3);
  30.  
  31.  
  32. /**
  33. * A {@link StartupRequirement} that checks the value of a PHP config option. If the check fails, it will output an error message.
  34. *
  35. * @package polyphony.startupcheck
  36. *
  37. * @copyright Copyright &copy; 2005, Middlebury College
  38. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  39. *
  40. * @version $Id: PHPConfigValueRequirement.class.php,v 1.6 2007/09/19 14:04:50 adamfranco Exp $
  41. */
  42. class PHPConfigValueRequirement extends StartupRequirement {
  43.  
  44. var $_key;
  45. var $_value;
  46. var $_opt;
  47.  
  48. /**
  49. * Constructor
  50. * @param string $key The php.ini option to look for (ie, 'register_globals')
  51. * @param mixed $value The value that is required.
  52. * @param optional int $opt An optional flag specifying how we should check the requirement. Options are: PHPINI_EQUAL (check for $key=$value, except for booleans), PHPINI_GREATER (check for $key>$value), PHPINI_LESS (check for $key<$value), PHPINI_BOOLEAN (will make sure the $key is true or false, depending on $value, which can be: "on", "off", true, false, 0, 1, "yes", "no", case insensitive)
  53. */
  54. function PHPConfigValueRequirement($key, $value, $opt=PHPINI_EQUAL) {
  55. // for boolean values, we have to treat the $value specially
  56. if ($opt == PHPINI_BOOLEAN) {
  57. do {
  58. if (is_string($value)) {
  59. $value = strtolower($value);
  60. if ($value=="yes" || $value=="on") $value="1";
  61. else if ($value=="no" || $value=="off") $value="";
  62. } else if (is_bool($value)) {
  63. if ($value == true) $value="1";
  64. else $value="";
  65. } else if (is_numeric($value)) {
  66. if ($value==1) $value="1";
  67. else if ($value==0) $value="";
  68. }
  69. } while (0);
  70. }
  71.  
  72. // otherwise, we'll just leave it be.
  73. $this->_key = strtolower($key);
  74. $this->_value = $value;
  75. $this->_opt = $opt;
  76. }
  77.  
  78. /**
  79. * Checks the environment and returns a status value. Return value is one of STARTUP_STATUS_* defines.
  80. * @access public
  81. * @return integer
  82. */
  83. function getStatus()
  84. {
  85. debug::output("PHPConfigValueRequirement - checking config directive $this->_key.",7,"StartupCheck");
  86. // let's check if the value is good or not
  87. if ($this->_opt == PHPINI_EQUAL || $this->_opt == PHPINI_BOOLEAN) {
  88. if (($curr=ini_get($this->_key)) === $this->_value) {
  89. return STARTUP_STATUS_OK;
  90. } else {
  91. StartupCheck::error(
  92. sprintf(dgettext("polyphony","PHPConfigValueRequirement - program could not proceed: a required php.ini value is not set properly for this program. I checked the <b>%s</b> directive and got <i>%s</i> when I wanted to get <i>%s</i>."),
  93. $this->_key,
  94. ($this->_opt==PHPINI_BOOLEAN)?($curr=="1"?"true":"false"):$curr,
  95. ($this->_opt==PHPINI_BOOLEAN)?($this->_value=="1"?"true":"false"):$curr)
  96. );
  97. return STARTUP_STATUS_ERROR;
  98. }
  99. } else if ($this->_opt == PHPINI_GREATER) {
  100. $curr = ini_get($this->_key);
  101. if ($curr > $this->_value)
  102. return STARTUP_STATUS_OK;
  103. else {
  104. StartupCheck::error(
  105. sprintf(dgettext("polyphony","PHPConfigValueRequirement - program could not proceed: a required php.ini value is not set properly for this program. I checked the <b>%s</b> directive and got <i>%s</i> when I wanted it to be greater than <i>%s</i>."),
  106. $this->_key,
  107. ($this->_opt==PHPINI_BOOLEAN)?($curr=="1"?"true":"false"):$curr,
  108. ($this->_opt==PHPINI_BOOLEAN)?($this->_value=="1"?"true":"false"):$curr)
  109. );
  110. return STARTUP_STATUS_ERROR;
  111. }
  112. } else if ($this->_opt == PHPINI_LESS) {
  113. $curr = ini_get($this->_key);
  114. if ($curr < $this->_value)
  115. return STARTUP_STATUS_OK;
  116. else {
  117. StartupCheck::error(
  118. sprintf(dgettext("polyphony","PHPConfigValueRequirement - program could not proceed: a required php.ini value is not set properly for this program. I checked the <b>%s</b> directive and got <i>%s</i> when I wanted it to be less than <i>%s</i>."),
  119. $this->_key,
  120. ($this->_opt==PHPINI_BOOLEAN)?($curr=="1"?"true":"false"):$curr,
  121. ($this->_opt==PHPINI_BOOLEAN)?($this->_value=="1"?"true":"false"):$curr)
  122. );
  123. return STARTUP_STATUS_ERROR;
  124. }
  125. } else {
  126. // ?
  127. }
  128. }
  129.  
  130. /**
  131. * Returns this requirement's display name.
  132. * @access public
  133. * @return string
  134. */
  135. function getDisplayName()
  136. {
  137. return sprintf(dgettext("polyphony","PHP.ini Setting (%s) Check"),$this->_key);
  138. }
  139.  
  140. /**
  141. * Returns a {@link Wizard} object containing fields for user input to complete installation process.
  142. * @access public
  143. * @return ref object
  144. */
  145. function createWizard()
  146. {
  147. $null = null;
  148. return $null;
  149. }
  150.  
  151. /**
  152. * Tells the requirement class to perform its update/install operation. If user input is required, it is passed in the form of a {@link WizardStep} containing field values.
  153. * @param optional array $properties An array of {@link WizardProperty} objects corresponding to the {@link Wizard} as created by {@link createWizard()}.
  154. * @access public
  155. * @return int Returns the new status of this requirement after attempting update.
  156. */
  157. function doUpdate( $properties = null )
  158. {
  159. // we don't do any updating!
  160. return STARTUP_STATUS_NOT_CHECKED;
  161. }
  162. }

Documentation generated on Wed, 19 Sep 2007 10:25:30 -0400 by phpDocumentor 1.3.0RC3