Beispiel #1
0
 function getEmptyValue($field, $fieldType)
 {
     if (str_equals_icase($fieldType, 'boolean')) {
         return FALSE;
     } else {
         if (is_array_type($fieldType)) {
             return array();
         } else {
             return null;
         }
     }
 }
Beispiel #2
0
function str_bool($text)
{
    if ($text == null) {
        return null;
    }
    if (str_equals_icase($text, 'true') || str_equals_icase($text, 'on') || str_equals_icase($text, 'yes') || str_equals_icase($text, '1')) {
        return true;
    } else {
        if (str_equals_icase($text, 'false') || str_equals_icase($text, 'off') || str_equals_icase($text, 'no') || str_equals_icase($text, '0')) {
            return false;
        }
    }
    return null;
}
Beispiel #3
0
 function setValue($val)
 {
     if (is_array($val)) {
         $time = array_merge(array('year' => '1970', 'month' => '01', 'day' => '01', 'hour' => '00', 'minute' => '00', 'second' => '00'), $val);
         if (isset($time['ampm'])) {
             $time['hour'] = str_equals_icase($time['ampm'], 'pm') ? $time['hour'] + 12 : $time['hour'];
         }
         $this->value =& new Time(mktime($time['hour'], $time['minute'], $time['second'], $time['month'], $time['day'], $time['year']));
     } else {
         if (is_a($val, 'Time')) {
             $this->value =& $val;
         } else {
             $this->value = new Time(time());
         }
     }
 }
Beispiel #4
0
function checkbox($path, $value = null, $options = array())
{
    $result = '';
    $name = _get_complete_bind_path($path);
    $bindStatus =& new BindStatus(_get_bind_path($path));
    $boundValue = $bindStatus->getValue();
    $valueType = $bindStatus->getValueType();
    if (str_equals_icase($valueType, 'boolean')) {
        if (is_string($boundValue)) {
            $boundValue = str_bool($boundValue);
        }
        $booleanValue = $boundValue != null ? $boundValue : false;
        $result .= checkbox_tag($name, 'true', $booleanValue, $options);
    } else {
        assert_not_null($value, "Attribute 'value' is required when binding to non-boolean values");
        $result .= checkbox_tag($name, specialchars($value, true), SelectedValueComparator::isSelected($bindStatus, $value), $options);
    }
    if (!isset($options['disabled']) || $options['disabled'] != 'disabled') {
        $result .= input_hidden_tag('_' . $name, '1');
    }
    return $result;
}
Beispiel #5
0
 function &convertIfNecessary(&$propertyName, &$oldValue, &$newValue, &$requiredType, &$descriptor)
 {
     $convertedValue = $newValue;
     // Custom editor for this type?
     $pe = $this->findCustomEditor($requiredType, $propertyName);
     // Value not of required type?
     if (!is_null($pe) || !is_null($requiredType) && !is_assignable($requiredType, $convertedValue)) {
         if (is_null($pe) && !is_null($descriptor)) {
             $pe = $descriptor->getPropertyEditor();
         }
         if (is_null($pe) && !is_null($requiredType)) {
             // No custom editor -> check BeanWrapper's default editors.
             $pe = $this->getDefaultEditor($requiredType);
         }
         // For string types, NULL = ''
         if ($requiredType != null && str_equals_icase($requiredType, 'string') && is_null($convertedValue)) {
             $convertedValue = '';
         }
         $convertedValue =& $this->_convertValue(&$convertedValue, &$requiredType, &$pe, &$oldValue);
     }
     if ($requiredType != null) {
         // Try to apply some standard type conversion rules if appropriate.
         if (!is_null($convertedValue) && is_array_type($requiredType)) {
             // Array required -> apply appropriate conversion of elements.
             return $this->_convertToArray($convertedValue, $propertyName, get_array_component_type($requiredType));
         }
         if (!is_assignable($requiredType, $convertedValue)) {
             // Definitely doesn't match: throw IllegalArgumentException.
             $iae = new IllegalArgumentException("Cannot convert value of type [" . get_qualified_type($newValue) . "] to required type [" . $requiredType . "] for property '" . $propertyName . "': no matching editors or conversion strategy found.  Converted value was: " . $convertedValue);
             if (log_enabled(LOG_DEBUG)) {
                 log_message(LOG_DEBUG, 'IllegalArgumentException in convertIfNecessary: ' . $iae->getMessage());
             }
             return $iae;
         }
     }
     return $convertedValue;
 }