Source for file Boolean.class.php

Documentation is available at Boolean.class.php

  1. <?php
  2.  
  3. require_once(dirname(__FILE__)."/../Objects/SObject.class.php");
  4.  
  5.  
  6. /**
  7. * A simple Boolean data type.
  8. *
  9. * @package harmoni.primitives
  10. *
  11. * @copyright Copyright &copy; 2005, Middlebury College
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  13. *
  14. * @version $Id: Boolean.class.php,v 1.10 2007/09/04 20:25:28 adamfranco Exp $
  15. */
  16. class Boolean
  17. extends SObject
  18. {
  19. var $_bool;
  20. /*******************************************************
  21. * Class Methods - Virtual Constructors
  22. *********************************************************/
  23.  
  24.  
  25. /**
  26. * Instantiates a new Boolean object with the passed value.
  27. * @param string $value
  28. * @return ref object
  29. * @access public
  30. * @static
  31. */
  32. function withValue($value) {
  33. $temp = new Boolean($value);
  34. return $temp;
  35. }
  36.  
  37. /**
  38. * Instantiates a new Boolean object from a known string
  39. *
  40. * @param string $aString true(case insensitive) is true if not, it's false
  41. * @return ref object
  42. * @access public
  43. * @since 3/14/06
  44. */
  45. function fromString ($aString) {
  46. $temp = new Boolean(((strtolower($aString) == "true")?true:false));
  47. return $temp;
  48. }
  49. /**
  50. * Instantiates a new Boolean object with the value, false.
  51. *
  52. * @return object Boolean
  53. * @access public
  54. * @since 8/11/05
  55. * @static
  56. */
  57. function false () {
  58. $temp = new Boolean(false);
  59. return $temp;
  60. }
  61. /**
  62. * Instantiates a new Boolean object with the value, true.
  63. *
  64. * @return object Boolean
  65. * @access public
  66. * @since 8/11/05
  67. * @static
  68. */
  69. function true () {
  70. $temp = new Boolean(true);
  71. return $temp;
  72. }
  73.  
  74. /*******************************************************
  75. * Instance Methods
  76. *********************************************************/
  77.  
  78.  
  79. function Boolean($value=true) {
  80. $this->_bool = (bool) $value;
  81. }
  82. /**
  83. * Returns the boolean value.
  84. * @access public
  85. * @return boolean
  86. */
  87. function value()
  88. {
  89. return $this->_bool;
  90. }
  91. /**
  92. * Answer a String whose characters are a description of the receiver.
  93. * Override this method as needed to provide a better representation
  94. *
  95. * @return string
  96. * @access public
  97. * @since 7/11/05
  98. */
  99. function printableString () {
  100. return $this->_bool?"true":"false";
  101. }
  102. /**
  103. * Answer whether the receiver and the argument are the same.
  104. * If = is redefined in any subclass, consider also redefining the
  105. * message hash.
  106. *
  107. * @param object $anObject
  108. * @return boolean
  109. * @access public
  110. * @since 7/11/05
  111. */
  112. function isEqualTo ( $anObject ) {
  113. if (!method_exists($anObject, 'value'))
  114. return false;
  115. return ($this->_bool===$anObject->value())?true:false;
  116. }
  117. /**
  118. * Answer true if this object represents a 'true' value, false otherwise.
  119. *
  120. * @return boolean
  121. * @access public
  122. * @since 9/29/05
  123. */
  124. function isTrue () {
  125. return $this->_bool;
  126. }
  127. /**
  128. * Answer true if this object represents a 'false' value, false otherwise.
  129. *
  130. * @return boolean
  131. * @access public
  132. * @since 9/29/05
  133. */
  134. function isFalse () {
  135. return $this->_bool?false:true;
  136. }
  137. }

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