コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function &addValueExtractor(ValueExtractorInterface $extractor)
 {
     $extract_as_field = $extractor->getFieldName();
     foreach ($this->value_extractors as $value_extractor) {
         if ($value_extractor->getFieldName() === $extract_as_field) {
             throw new InvalidArgumentException("Field name '{$extract_as_field}' is taken");
         }
     }
     $this->value_extractors[] = $extractor;
     return $this;
 }
コード例 #2
0
 /**
  * Prpeare generated field statement.
  *
  * @param  FieldInterface          $source_field
  * @param  ValueExtractorInterface $extractor
  * @return string
  */
 public function prepareGeneratedFieldStatement(FieldInterface $source_field, ValueExtractorInterface $extractor)
 {
     $generated_field_name = $this->getConnection()->escapeFieldName($extractor->getFieldName());
     switch ($extractor->getValueCaster()) {
         case ValueCasterInterface::CAST_INT:
             $field_type = 'INT';
             break;
         case ValueCasterInterface::CAST_FLOAT:
             $field_type = 'DECIMAL(12, 2)';
             break;
         case ValueCasterInterface::CAST_BOOL:
             $field_type = 'TINYINT(1) UNSIGNED';
             break;
         case ValueCasterInterface::CAST_DATE:
             $field_type = 'DATE';
             break;
         case ValueCasterInterface::CAST_DATETIME:
             $field_type = 'DATETIME';
             break;
         case ValueCasterInterface::CAST_JSON:
             $field_type = 'JSON';
             break;
         default:
             $field_type = 'VARCHAR(191)';
     }
     $expression = $this->prepareGeneratedFieldExpression($this->getConnection()->escapeFieldName($source_field->getName()), var_export($extractor->getExpression(), true), $extractor->getValueCaster(), $this->getConnection()->escapeValue($extractor->getDefaultValue()));
     $storage = $extractor->getStoreValue() ? 'STORED' : 'VIRTUAL';
     return trim("{$generated_field_name} {$field_type} AS ({$expression}) {$storage}");
 }