Alpha Framework alpha--model--types
[ class tree: alpha--model--types ] [ index: alpha--model--types ] [ all elements ]

Source for file Boolean.inc

Documentation is available at Boolean.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/exceptions/AlphaException.inc';
  4. require_once $config->get('sysRoot').'alpha/model/types/AlphaType.inc';
  5. require_once $config->get('sysRoot').'alpha/model/types/AlphaTypeInterface.inc';
  6.  
  7. /**
  8.  * The Boolean complex data type
  9.  * 
  10.  * @package alpha::model::types
  11.  * @since 1.0
  12.  * @author John Collins <dev@alphaframework.org>
  13.  * @version $Id: Boolean.inc 1341 2011-03-17 15:02:02Z johnc $
  14.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  15.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  16.  *  All rights reserved.
  17.  * 
  18.  *  <pre>
  19.  *  Redistribution and use in source and binary forms, with or
  20.  *  without modification, are permitted provided that the
  21.  *  following conditions are met:
  22.  * 
  23.  *  * Redistributions of source code must retain the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer.
  26.  *  * Redistributions in binary form must reproduce the above
  27.  *    copyright notice, this list of conditions and the
  28.  *    following disclaimer in the documentation and/or other
  29.  *    materials provided with the distribution.
  30.  *  * Neither the name of the Alpha Framework nor the names
  31.  *    of its contributors may be used to endorse or promote
  32.  *    products derived from this software without specific
  33.  *    prior written permission.
  34.  *   
  35.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  36.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  37.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  38.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  40.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  45.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  46.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  47.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48.  *  </pre>
  49.  *  
  50.  */
  51. class Boolean extends AlphaType implements AlphaTypeInterface {
  52.     /**
  53.      * The value of the Boolean
  54.      *
  55.      * @var boolean 
  56.      * @since 1.0
  57.      * 
  58.      */
  59.     private $booleanValue;
  60.     
  61.     /**
  62.      * The binary (1/0) value of the Boolean.  This is the value stored in the database.
  63.      *
  64.      * @var integer 
  65.      * @since 1.0
  66.      */
  67.     private $value;
  68.     
  69.     /**
  70.      * The error message returned for invalid values
  71.      *
  72.      * @var string 
  73.      * @since 1.0
  74.      */
  75.     protected $helper = 'Not a valid Boolean value!';
  76.     
  77.     /**
  78.      * Constructor
  79.      *
  80.      * @param boolean $val 
  81.      * @since 1.0
  82.      * @throws IllegalArguementException
  83.      */
  84.     public function __construct($val=true{
  85.         if(!AlphaValidator::isBoolean($val))
  86.             throw new IllegalArguementException($this->helper);
  87.  
  88.         $acceptableTrueValues array(true"true"1"1");
  89.         
  90.         if(in_array($val$acceptableTrueValuestrue)) {
  91.             $this->value 1;
  92.             $this->booleanValue true;
  93.         }else {
  94.             $this->value 0;
  95.             $this->booleanValue false;
  96.         }
  97.     }
  98.     
  99.     /**
  100.      * Used to set the Boolean value.
  101.      *
  102.      * @param mixed $val Will accept a boolean true/false or integer 1/0.
  103.      * @since 1.0
  104.      * @throws IllegalArguementException
  105.      */
  106.     public function setValue($val{
  107.         if(!AlphaValidator::isBoolean($val))
  108.             throw new IllegalArguementException($this->helper);
  109.             
  110.         $acceptableTrueValues array(true"true"1"1");
  111.         
  112.         if(in_array($val$acceptableTrueValuestrue)) {
  113.             $this->value 1;
  114.             $this->booleanValue true;
  115.         }else {
  116.             $this->value 0;
  117.             $this->booleanValue false;
  118.         }
  119.     }
  120.     
  121.     /**
  122.      * Used to get the binary (1/0) value of the Boolean.  This is the value stored in the database.
  123.      *
  124.      * @return integer 
  125.      * @since 1.0
  126.      */
  127.     public function getValue({
  128.         return $this->value;
  129.     }
  130.     
  131.     /**
  132.      * Used to get the boolean value of the Boolean
  133.      *
  134.      * @return boolean 
  135.      * @since 1.0
  136.      */
  137.     public function getBooleanValue({
  138.         return $this->booleanValue;
  139.     }
  140.     
  141.     /**
  142.      * Used to convert the object to a printable string
  143.      *
  144.      * @return string 
  145.      * @since 1.0
  146.      */
  147.     public function __toString({        
  148.         return ($this->value 'true' 'false');
  149.     }
  150. }
  151.  
  152. ?>

Documentation generated on Thu, 17 Mar 2011 16:43:55 +0000 by phpDocumentor 1.4.3