Exemple #1
0
 /**
  * Converts value for some column types
  *
  * @param  mixed     $value  The value to convert
  * @param  ColumnMap $colMap The ColumnMap object
  * @return mixed     The converted value
  */
 protected function convertValueForColumn($value, ColumnMap $colMap)
 {
     if ($colMap->getType() == 'OBJECT' && is_object($value)) {
         if (is_array($value)) {
             $value = array_map('serialize', $value);
         } else {
             $value = serialize($value);
         }
     } elseif ('ARRAY' === $colMap->getType() && is_array($value)) {
         $value = '| ' . implode(' | ', $value) . ' |';
     } elseif (PropelTypes::ENUM === $colMap->getType() && !is_null($value)) {
         if (is_array($value)) {
             $value = array_map([$colMap, 'getValueSetKey'], $value);
         } else {
             $value = $colMap->getValueSetKey($value);
         }
     } elseif ($colMap->isSetType() && !is_null($value)) {
         try {
             $value = SetColumnConverter::convertToInt($value, $colMap->getValueSet());
         } catch (SetColumnConverterException $e) {
             throw new PropelException(sprintf('Value "%s" is not accepted in this set column', $e->getValue()), $e->getCode(), $e);
         }
     }
     return $value;
 }