TPropertyValue is a utility class that provides static methods to convert component property values to specific types. TPropertyValue is commonly used in component setter methods to ensure the new property value is of specific type. For example, a boolean-typed property setter method would be as follows, function setPropertyName($value) { $value=TPropertyValue::ensureBoolean($value); $value is now of boolean type } Properties can be of the following types with specific type conversion rules: - string: a boolean value will be converted to 'true' or 'false'. - boolean: string 'true' (case-insensitive) will be converted to true, string 'false' (case-insensitive) will be converted to false. - integer - float - array: string starting with '(' and ending with ')' will be considered as as an array expression and will be evaluated. Otherwise, an array with the value to be ensured is returned. - object - enum: enumerable type, represented by an array of strings.
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
コード例 #1
0
 public function setTotalRowCount($value)
 {
     if (($value = TPropertyValue::ensureInteger($value)) < 0) {
         $value = 0;
     }
     $this->_totalRowCount = $value;
 }
コード例 #2
0
ファイル: Translation.php プロジェクト: pradosoft/prado
 /**
  * Initialize the TTranslate translation components
  */
 public static function init($catalogue = 'messages')
 {
     static $saveEventHandlerAttached = false;
     //initialized the default class wide formatter
     if (!isset(self::$formatters[$catalogue])) {
         $app = Prado::getApplication()->getGlobalization();
         $config = $app->getTranslationConfiguration();
         $source = MessageSource::factory($config['type'], $config['source'], $config['filename']);
         $source->setCulture($app->getCulture());
         if (isset($config['cache'])) {
             $source->setCache(new MessageCache($config['cache']));
         }
         self::$formatters[$catalogue] = new MessageFormat($source, $app->getCharset());
         //mark untranslated text
         if ($ps = $config['marker']) {
             self::$formatters[$catalogue]->setUntranslatedPS(array($ps, $ps));
         }
         //save the message on end request
         // Do it only once !
         if (!$saveEventHandlerAttached && TPropertyValue::ensureBoolean($config['autosave'])) {
             Prado::getApplication()->attachEventHandler('OnEndRequest', array('Translation', 'saveMessages'));
             $saveEventHandlerAttached = true;
         }
     }
 }
コード例 #3
0
 /**
  * @param integer maximum number of page states that should be kept in session
  * @throws TInvalidDataValueException if the number is smaller than 1.
  */
 public function setHistorySize($value)
 {
     if (($value = TPropertyValue::ensureInteger($value)) > 0) {
         $this->_historySize = $value;
     } else {
         throw new TInvalidDataValueException('sessionpagestatepersister_historysize_invalid');
     }
 }
コード例 #4
0
 /**
  * Sets the decay rate between callback. Default is 0;
  * @param float decay rate between callbacks.
  */
 public function setDecayRate($value)
 {
     $decay = TPropertyValue::ensureFloat($value);
     if ($decay < 0) {
         throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
     }
     $this->setViewState('Decay', $decay);
 }
コード例 #5
0
 /**
  * Updates the options of the jQueryUI widget.
  * @param array list of widget options to change.
  */
 protected function updateJuiOptions($options)
 {
     foreach ($options as $key => $value) {
         $options[$key] = $key . ': ' . (is_string($value) ? "'{$value}'" : TPropertyValue::ensureString($value));
     }
     $code = "jQuery('#{$this->_control->getWidgetID()}').{$this->_control->getWidget()}('option', { " . implode(', ', $options) . " });";
     $this->_control->getPage()->getClientScript()->registerEndScript(sprintf('%08X', crc32($code)), $code);
 }
コード例 #6
0
 protected function createBooleanControl($container, $column, $record)
 {
     $value = $this->getRecordPropertyValue($column, $record);
     $control = new TCheckBox();
     $control->setChecked(TPropertyValue::ensureBoolean($value));
     $control->setCssClass('boolean-checkbox');
     $this->setDefaultProperty($container, $control, $column, $record);
     return $control;
 }
コード例 #7
0
 public function __construct($dropParams)
 {
     $this->_dragElementId = $dropParams->DragElementID;
     $this->_screenX = $dropParams->ScreenX;
     $this->_screenY = $dropParams->ScreenY;
     $this->_offsetX = isset($dropParams->OffsetX) ? $dropParams->OffsetX : false;
     $this->_offsetY = isset($dropParams->OffsetY) ? $dropParams->OffsetY : false;
     $this->_clientX = $dropParams->ClientX;
     $this->_clientY = $dropParams->ClientY;
     $this->_shiftKey = TPropertyValue::ensureBoolean($dropParams->ShiftKey);
     $this->_ctrlKey = TPropertyValue::ensureBoolean($dropParams->CtrlKey);
     $this->_altKey = TPropertyValue::ensureBoolean($dropParams->AltKey);
 }
コード例 #8
0
ファイル: TException.php プロジェクト: pradosoft/prado
 /**
  * Constructor.
  * @param string error message. This can be a string that is listed
  * in the message file. If so, the message in the preferred language
  * will be used as the error message. Any rest parameters will be used
  * to replace placeholders ({0}, {1}, {2}, etc.) in the message.
  */
 public function __construct($errorMessage)
 {
     $this->_errorCode = $errorMessage;
     $errorMessage = $this->translateErrorMessage($errorMessage);
     $args = func_get_args();
     array_shift($args);
     $n = count($args);
     $tokens = array();
     for ($i = 0; $i < $n; ++$i) {
         $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]);
     }
     parent::__construct(strtr($errorMessage, $tokens));
 }
コード例 #9
0
ファイル: TSqlMapException.php プロジェクト: pradosoft/prado
 /**
  * Constructor, similar to the parent constructor. For parameters that
  * are of SimpleXmlElement, the tag name and its attribute names and values
  * are expanded into a string.
  */
 public function __construct($errorMessage)
 {
     $this->setErrorCode($errorMessage);
     $errorMessage = $this->translateErrorMessage($errorMessage);
     $args = func_get_args();
     array_shift($args);
     $n = count($args);
     $tokens = array();
     for ($i = 0; $i < $n; ++$i) {
         if ($args[$i] instanceof SimpleXMLElement) {
             $tokens['{' . $i . '}'] = $this->implodeNode($args[$i]);
         } else {
             $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]);
         }
     }
     parent::__construct(strtr($errorMessage, $tokens));
 }
コード例 #10
0
ファイル: TPriorityMap.php プロジェクト: pradosoft/prado
 /**
  * Removes an item from the map by its key. If no priority, or false, is specified
  * then priority is irrelevant. If null is used as a parameter for priority, then
  * the priority will be the default priority.  If a priority is specified, or
  * the default priority is specified, only key-value pairs in that priority
  * will be affected.
  * @param mixed the key of the item to be removed
  * @param numeric|false|null priority.  False is any priority, null is the
  * default priority, and numeric is a specific priority
  * @return mixed the removed value, null if no such key exists.
  * @throws TInvalidOperationException if the map is read-only
  */
 public function remove($key, $priority = false)
 {
     if (!$this->_r) {
         if ($priority === null) {
             $priority = $this->getDefaultPriority();
         }
         if ($priority === false) {
             $this->sortPriorities();
             foreach ($this->_d as $priority => $items) {
                 if (array_key_exists($key, $items)) {
                     $value = $this->_d[$priority][$key];
                     unset($this->_d[$priority][$key]);
                     $this->_c--;
                     if (count($this->_d[$priority]) === 0) {
                         unset($this->_d[$priority]);
                         $this->_o = false;
                     }
                     $this->_fd = null;
                     return $value;
                 }
             }
             return null;
         } else {
             $priority = (string) round(TPropertyValue::ensureFloat($priority), $this->_p);
             if (isset($this->_d[$priority]) && (isset($this->_d[$priority][$key]) || array_key_exists($key, $this->_d[$priority]))) {
                 $value = $this->_d[$priority][$key];
                 unset($this->_d[$priority][$key]);
                 $this->_c--;
                 if (count($this->_d[$priority]) === 0) {
                     unset($this->_d[$priority]);
                     $this->_o = false;
                 }
                 $this->_fd = null;
                 return $value;
             } else {
                 return null;
             }
         }
     } else {
         throw new TInvalidOperationException('map_readonly', get_class($this));
     }
 }
コード例 #11
0
ファイル: TDbConnection.php プロジェクト: pradosoft/prado
 /**
  * @param boolean whether the connection is persistent or not
  * Some DBMS (such as sqlite) may not support this feature.
  */
 public function setPersistent($value)
 {
     return $this->setAttribute(PDO::ATTR_PERSISTENT, TPropertyValue::ensureBoolean($value));
 }
コード例 #12
0
ファイル: TListItem.php プロジェクト: pradosoft/prado
 /**
  * @param string value of the item
  */
 public function setValue($value)
 {
     $this->_value = TPropertyValue::ensureString($value);
 }
コード例 #13
0
 /**
  * @param TWizardNavigationButtonType button type.
  */
 public function setButtonType($value)
 {
     $this->_buttonType = TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TWizardNavigationButtonType');
 }
コード例 #14
0
ファイル: TClientScript.php プロジェクト: pradosoft/prado
 /**
  * @param bool whether to flush script files using TClientScriptManager::flushScriptFiles() before rendering the script block
  */
 public function setFlushScriptFiles($value)
 {
     $this->setViewState('FlushScriptFiles', TPropertyValue::ensureBoolean($value));
 }
コード例 #15
0
 /**
  * @param integer the line number at which the template has error
  */
 public function setLineNumber($value)
 {
     $this->_lineNumber = TPropertyValue::ensureInteger($value);
 }
コード例 #16
0
 /**
  * Sets a value indicating the depth of the subdirectories to be checked.
  * This is meaningful only when {@link getRecursiveCheck RecursiveCheck}
  * is true.
  * @param int the depth of the subdirectories to be checked.
  * If the value is less than 0, it means unlimited depth.
  * If the value is 0, it means checking the files directly under the specified directory.
  */
 public function setRecursiveLevel($value)
 {
     $this->_recursiveLevel = TPropertyValue::ensureInteger($value);
 }
コード例 #17
0
ファイル: TRepeatInfo.php プロジェクト: pradosoft/prado
 /**
  * @param TRepeatLayout how the repeated items should be displayed, using table or using line breaks.
  */
 public function setRepeatLayout($value)
 {
     $this->_repeatLayout = TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TRepeatLayout');
 }
コード例 #18
0
ファイル: TDiscriminator.php プロジェクト: pradosoft/prado
 /**
  * The columnIndex attribute value is the index of the column in the
  * ResultSet from which the value will be used to populate the object property.
  * @param int index of the column in the ResultSet
  */
 public function setColumnIndex($value)
 {
     $this->_columnIndex = TPropertyValue::ensureInteger($value);
 }
コード例 #19
0
ファイル: TDataBoundControl.php プロジェクト: pradosoft/prado
 /**
  * Validates if the parameter is a valid data source.
  * If it is a string or an array, it will be converted as a TList object.
  * @param Traversable|array|string data source to be validated
  * @return Traversable the data that is traversable
  * @throws TInvalidDataTypeException if the data is neither null nor Traversable
  */
 protected function validateDataSource($value)
 {
     if (is_string($value)) {
         $list = new TList();
         foreach (TPropertyValue::ensureArray($value) as $key => $value) {
             if (is_array($value)) {
                 $list->add($value);
             } else {
                 $list->add(array($value, is_string($key) ? $key : $value));
             }
         }
         return $list;
     } else {
         if (is_array($value)) {
             return new TMap($value);
         } else {
             if ($value instanceof TDbDataReader) {
                 // read array from TDbDataReader since it's forward-only stream and can only be traversed once
                 return $value->readAll();
             } else {
                 if ($value instanceof \Traversable || $value === null) {
                     return $value;
                 } else {
                     throw new TInvalidDataTypeException('databoundcontrol_datasource_invalid', get_class($this));
                 }
             }
         }
     }
 }
コード例 #20
0
ファイル: TDraggable.php プロジェクト: pradosoft/prado
 /**
  * Set wether the element should be constrainted in one direction
  * @param CDraggableConstraint
  */
 public function setConstraint($value)
 {
     $this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\ActiveControls\\DraggableConstraint'), TDraggableConstraint::None);
 }
コード例 #21
0
 /**
  * Set the opacity on a html element or control.
  * This effect doesn't need jQueryUI.
  * @param TControl control element or element id
  * @param float opacity value between 1 and 0
  */
 public function fadeTo($element, $value, $duration = 500)
 {
     $value = TPropertyValue::ensureFloat($value);
     $this->visualEffect('fadeTo', $element, array($duration, $value));
 }
コード例 #22
0
ファイル: TOutputCache.php プロジェクト: pradosoft/prado
 /**
  * Sets a value indicating whether cached output will be used on postback requests.
  * By default, this is disabled. Be very cautious when enabling it.
  * If the cached content including interactive user controls such as
  * TTextBox, TDropDownList, your page may fail to render on postbacks.
  * @param boolean whether cached output will be used on postback requests.
  */
 public function setCachingPostBack($value)
 {
     $this->_cachePostBack = TPropertyValue::ensureBoolean($value);
 }
コード例 #23
0
ファイル: TCheckBox.php プロジェクト: pradosoft/prado
 /**
  * @param boolean whether to render javascript.
  */
 public function setEnableClientScript($value)
 {
     $this->setViewState('EnableClientScript', TPropertyValue::ensureBoolean($value), true);
 }
コード例 #24
0
ファイル: TCompareValidator.php プロジェクト: pradosoft/prado
 /**
  * Sets the comparison operation to perform
  * @param TValidationCompareOperator the comparison operation
  */
 public function setOperator($value)
 {
     $this->setViewState('Operator', TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TValidationCompareOperator'), TValidationCompareOperator::Equal);
 }
コード例 #25
0
ファイル: TPage.php プロジェクト: pradosoft/prado
 /**
  * @param boolean whether page state should be compressed.
  * @since 3.1.6
  */
 public function setEnableStateCompression($value)
 {
     $this->_enableStateCompression = TPropertyValue::ensureBoolean($value);
 }
コード例 #26
0
ファイル: TRatingList.php プロジェクト: pradosoft/prado
 /**
  * Sets the interval such that those rating values within the interval
  * will be considered as a half star rating.
  * @param array rating display half value interval, default is array(0.3, 0.7);
  */
 public function setHalfRatingInterval($value)
 {
     $this->setViewState('HalfRating', TPropertyValue::ensureArray($value), array(0.3, 0.7));
 }
コード例 #27
0
ファイル: TTextBox.php プロジェクト: pradosoft/prado
 /**
  * Sets the value indicating whether the text content wraps within a multiline text box.
  * @param boolean whether the text content wraps within a multiline text box.
  */
 public function setWrap($value)
 {
     $this->setViewState('Wrap', TPropertyValue::ensureBoolean($value), true);
 }
コード例 #28
0
ファイル: TMultiView.php プロジェクト: pradosoft/prado
 /**
  * Processes the events bubbled from child controls.
  * The method handles view-related command events.
  * @param TControl sender of the event
  * @param mixed event parameter
  * @return boolean whether this event is handled
  */
 public function bubbleEvent($sender, $param)
 {
     if (!$this->_ignoreBubbleEvents && $param instanceof \Prado\Web\UI\TCommandEventParameter) {
         switch ($param->getCommandName()) {
             case self::CMD_NEXTVIEW:
                 if (($index = $this->getActiveViewIndex()) < $this->getViews()->getCount() - 1) {
                     $this->setActiveViewIndex($index + 1);
                 } else {
                     $this->setActiveViewIndex(-1);
                 }
                 return true;
             case self::CMD_PREVIOUSVIEW:
                 if (($index = $this->getActiveViewIndex()) >= 0) {
                     $this->setActiveViewIndex($index - 1);
                 }
                 return true;
             case self::CMD_SWITCHVIEWID:
                 $view = $this->findControl($viewID = $param->getCommandParameter());
                 if ($view !== null && $view->getParent() === $this) {
                     $this->setActiveView($view);
                     return true;
                 } else {
                     throw new TInvalidDataValueException('multiview_viewid_invalid', $viewID);
                 }
             case self::CMD_SWITCHVIEWINDEX:
                 $index = TPropertyValue::ensureInteger($param->getCommandParameter());
                 $this->setActiveViewIndex($index);
                 return true;
         }
     }
     return false;
 }
コード例 #29
0
ファイル: TLiteral.php プロジェクト: pradosoft/prado
 /**
  * @param boolean  whether the rendered text should be HTML-encoded.
  */
 public function setEncode($value)
 {
     $this->setViewState('Encode', TPropertyValue::ensureBoolean($value), false);
 }
コード例 #30
0
ファイル: TStyle.php プロジェクト: pradosoft/prado
 /**
  * @param TDisplayStyle control display style, default is TDisplayStyle::Fixed
  */
 public function setDisplayStyle($value)
 {
     $this->_displayStyle = TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TDisplayStyle');
     switch ($this->_displayStyle) {
         case TDisplayStyle::None:
             $this->_fields['display'] = 'none';
             break;
         case TDisplayStyle::Dynamic:
             $this->_fields['display'] = '';
             //remove the display property
             break;
         case TDisplayStyle::Fixed:
             $this->_fields['visibility'] = 'visible';
             break;
         case TDisplayStyle::Hidden:
             $this->_fields['visibility'] = 'hidden';
             break;
     }
 }