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

Source for file Text.inc

Documentation is available at Text.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 Text complex data type
  9.  * 
  10.  * @package alpha::model::types
  11.  * @since 1.0
  12.  * @author John Collins <dev@alphaframework.org>
  13.  * @version $Id: Text.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 Text extends AlphaType implements AlphaTypeInterface {
  52.     /**
  53.      * The value of the Text object
  54.      * 
  55.      * @var string 
  56.      * @since 1.0
  57.      */
  58.     private $value;
  59.     
  60.     /**
  61.      * The validation rule for the Text type
  62.      * 
  63.      * @var string 
  64.      * @since 1.0
  65.      */
  66.     private $validationRule;
  67.     
  68.     /**
  69.      * Used to determine if the Text object can support HTML content or not.  Defaults to true, if set to false
  70.      * then HTML content should be filtered.
  71.      * 
  72.      * @var boolean 
  73.      * @since 1.0
  74.      */
  75.     private $allowHTML true;
  76.     
  77.     /**
  78.      * The error message for the string type when validation fails
  79.      * 
  80.      * @var string 
  81.      * @since 1.0
  82.      */
  83.     protected $helper = 'Not a valid text value!';
  84.     
  85.     /**
  86.      * The size of the value for the this Text
  87.      * 
  88.      * @var integer 
  89.      * @since 1.0
  90.      */
  91.     private $size 65535;
  92.     
  93.     /**
  94.      * The absolute maximum size of the value for the this Text
  95.      * 
  96.      * @var integer 
  97.      * @since 1.0
  98.      */
  99.     const MAX_SIZE = 65535;
  100.     
  101.     /**
  102.      * Constructor
  103.      *
  104.      * @param string $val 
  105.      * @since 1.0
  106.      * @throws IllegalArguementException
  107.      */
  108.     public function __construct($val=''{
  109.         
  110.         $this->validationRule AlphaValidator::ALLOW_ALL;
  111.         
  112.         if (strlen($val<= $this->size{            
  113.             if (preg_match($this->validationRule$val)) {                
  114.                 $this->value $val;                
  115.             }else{
  116.                 throw new IllegalArguementException($this->helper);
  117.             }
  118.         }else{
  119.             throw new IllegalArguementException($this->helper);
  120.         }
  121.     }
  122.     
  123.     /**
  124.      * Setter for the value
  125.      *
  126.      * @param string $val 
  127.      * @since 1.0
  128.      * @throws IllegalArguementException
  129.      */
  130.     public function setValue($val{    
  131.         if (strlen($val<= $this->size{            
  132.             if (preg_match($this->validationRule$val)) {                
  133.                 $this->value $val;                
  134.             }else{
  135.                 throw new IllegalArguementException($this->helper);
  136.             }
  137.         }else{
  138.             throw new IllegalArguementException($this->helper);
  139.         }
  140.     }
  141.     
  142.     /**
  143.      * Getter for the value
  144.      *
  145.      * @return string 
  146.      * @since 1.0
  147.      */
  148.     public function getValue({        
  149.         return $this->value;
  150.     }    
  151.     
  152.     /**
  153.      * Setter to override the default validation rule
  154.      *
  155.      * @param string $rule 
  156.      * @since 1.0
  157.      */
  158.     public function setRule($rule{
  159.         $this->validationRule $rule;
  160.     }
  161.     
  162.     /**
  163.       * Get the validation rule
  164.       *
  165.       * @return string 
  166.       * @since 1.0
  167.       */
  168.      public function getRule({
  169.         return $this->validationRule;
  170.     }    
  171.     
  172.     /**
  173.      * Used to set the allowable size of the Text in the database field
  174.      *
  175.      * @param integer $size 
  176.      * @since 1.0
  177.      * @throws IllegalArguementException
  178.      */
  179.     public function setSize($size{
  180.         if ($size <= self::MAX_SIZE{
  181.             $this->size $size;
  182.         }else{
  183.             throw new IllegalArguementException('The value '.$size.' provided by setSize is greater than the MAX_SIZE '.self::MAX_SIZE.' of this data type.');
  184.         }    
  185.     }
  186.     
  187.     /**
  188.      * Get the allowable size of the Double in the database field
  189.      *    
  190.      * @return integer 
  191.      * @since 1.0
  192.      */
  193.     public function getSize(){
  194.         return $this->size;
  195.     }
  196.     
  197.     /**
  198.      * Set the $allowHTML value
  199.      * 
  200.      * @param boolean $allowHTML 
  201.      * @since 1.0
  202.      */
  203.     public function setAllowHTML($allowHTML{
  204.         $this->allowHTML $allowHTML;
  205.     }
  206.     
  207.     /**
  208.      * Get the $allowHTML value
  209.      * 
  210.      * @return boolean 
  211.      * @since 1.0
  212.      */
  213.     public function getAllowHTML({
  214.         return $this->allowHTML;
  215.     }
  216. }
  217.  
  218. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:59 +0000 by phpDocumentor 1.4.3