Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::util::search
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaType
  • Boolean
  • Date
  • DEnum
  • DEnumItem
  • Double
  • Enum
  • Integer
  • Relation
  • RelationLookup
  • Sequence
  • String
  • Text
  • Timestamp

Interfaces

  • AlphaTypeInterface
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * The Text complex data type
  5:  *
  6:  * @package alpha::model::types
  7:  * @since 1.0
  8:  * @author John Collins <dev@alphaframework.org>
  9:  * @version $Id: Text.inc 1693 2013-12-09 23:33:24Z alphadevx $
 10:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 11:  * @copyright Copyright (c) 2013, John Collins (founder of Alpha Framework).
 12:  * All rights reserved.
 13:  *
 14:  * <pre>
 15:  * Redistribution and use in source and binary forms, with or
 16:  * without modification, are permitted provided that the
 17:  * following conditions are met:
 18:  *
 19:  * * Redistributions of source code must retain the above
 20:  *   copyright notice, this list of conditions and the
 21:  *   following disclaimer.
 22:  * * Redistributions in binary form must reproduce the above
 23:  *   copyright notice, this list of conditions and the
 24:  *   following disclaimer in the documentation and/or other
 25:  *   materials provided with the distribution.
 26:  * * Neither the name of the Alpha Framework nor the names
 27:  *   of its contributors may be used to endorse or promote
 28:  *   products derived from this software without specific
 29:  *   prior written permission.
 30:  *
 31:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 32:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 33:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 35:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 36:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 37:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 38:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 39:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 40:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 41:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 42:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 43:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 44:  * </pre>
 45:  *
 46:  */
 47: class Text extends AlphaType implements AlphaTypeInterface {
 48:     /**
 49:      * The value of the Text object
 50:      *
 51:      * @var string
 52:      * @since 1.0
 53:      */
 54:     private $value;
 55: 
 56:     /**
 57:      * The validation rule for the Text type
 58:      *
 59:      * @var string
 60:      * @since 1.0
 61:      */
 62:     private $validationRule;
 63: 
 64:     /**
 65:      * Used to determine if the Text object can support HTML content or not.  Defaults to true, if set to false
 66:      * then HTML content should be filtered.
 67:      *
 68:      * @var boolean
 69:      * @since 1.0
 70:      */
 71:     private $allowHTML = true;
 72: 
 73:     /**
 74:      * The error message for the string type when validation fails
 75:      *
 76:      * @var string
 77:      * @since 1.0
 78:      */
 79:     protected $helper = 'Not a valid text value!';
 80: 
 81:     /**
 82:      * The size of the value for the this Text
 83:      *
 84:      * @var integer
 85:      * @since 1.0
 86:      */
 87:     private $size = 65535;
 88: 
 89:     /**
 90:      * The absolute maximum size of the value for the this Text
 91:      *
 92:      * @var integer
 93:      * @since 1.0
 94:      */
 95:     const MAX_SIZE = 65535;
 96: 
 97:     /**
 98:      * Constructor
 99:      *
100:      * @param string $val
101:      * @since 1.0
102:      * @throws IllegalArguementException
103:      */
104:     public function __construct($val='') {
105: 
106:         $this->validationRule = AlphaValidator::ALLOW_ALL;
107: 
108:         if (mb_strlen($val) <= $this->size) {
109:             if (preg_match($this->validationRule, $val)) {
110:                 $this->value = $val;
111:             }else{
112:                 throw new IllegalArguementException($this->helper);
113:             }
114:         }else{
115:             throw new IllegalArguementException($this->helper);
116:         }
117:     }
118: 
119:     /**
120:      * Setter for the value
121:      *
122:      * @param string $val
123:      * @since 1.0
124:      * @throws IllegalArguementException
125:      */
126:     public function setValue($val) {
127:         if (mb_strlen($val) <= $this->size) {
128:             if (preg_match($this->validationRule, $val)) {
129:                 $this->value = $val;
130:             }else{
131:                 throw new IllegalArguementException($this->helper);
132:             }
133:         }else{
134:             throw new IllegalArguementException($this->helper);
135:         }
136:     }
137: 
138:     /**
139:      * Getter for the value
140:      *
141:      * @return string
142:      * @since 1.0
143:      */
144:     public function getValue() {
145:         return $this->value;
146:     }
147: 
148:     /**
149:      * Setter to override the default validation rule
150:      *
151:      * @param string $rule
152:      * @since 1.0
153:      */
154:     public function setRule($rule) {
155:         $this->validationRule = $rule;
156:     }
157: 
158:     /**
159:      * Get the validation rule
160:      *
161:      * @return string
162:      * @since 1.0
163:      */
164:     public function getRule() {
165:         return $this->validationRule;
166:     }
167: 
168:     /**
169:      * Used to set the allowable size of the Text in the database field
170:      *
171:      * @param integer $size
172:      * @since 1.0
173:      * @throws IllegalArguementException
174:      */
175:     public function setSize($size) {
176:         if ($size <= self::MAX_SIZE) {
177:             $this->size = $size;
178:         }else{
179:             throw new IllegalArguementException('The value '.$size.' provided by setSize is greater than the MAX_SIZE '.self::MAX_SIZE.' of this data type.');
180:         }
181:     }
182: 
183:     /**
184:      * Get the allowable size of the Double in the database field
185:      *
186:      * @return integer
187:      * @since 1.0
188:      */
189:     public function getSize(){
190:         return $this->size;
191:     }
192: 
193:     /**
194:      * Set the $allowHTML value
195:      *
196:      * @param boolean $allowHTML
197:      * @since 1.0
198:      */
199:     public function setAllowHTML($allowHTML) {
200:         $this->allowHTML = $allowHTML;
201:     }
202: 
203:     /**
204:      * Get the $allowHTML value
205:      *
206:      * @return boolean
207:      * @since 1.0
208:      */
209:     public function getAllowHTML() {
210:         return $this->allowHTML;
211:     }
212: }
213: 
214: ?>
Alpha Framework 1.2.4 API Documentation API documentation generated by ApiGen 2.8.0