Example #1
0
 public function getColumntConfig(Column $column)
 {
     $config = $this->getOption('config');
     $configFields = isset($config['fields']) ? $config['fields'] : array();
     $result = array();
     foreach ($configFields as $configField) {
         if (isset($configField['match'])) {
             $isMatched = false;
             foreach ($configField['match'] as $match) {
                 $isMatched = false;
                 if (isset($match['type'])) {
                     $matchTypes = is_array($match['type']) ? $match['type'] : array($match['type']);
                     $isMatched = in_array($column->getColumnType(), $matchTypes);
                 }
                 if (isset($match['regexp'])) {
                     $isMatched = $isMatched && preg_match($match['regexp'], $column->getFullName());
                 }
                 $columnLength = $column->getCharacterMaximumLength() ? $column->getCharacterMaximumLength() : $column->getNumericPrecision();
                 if ($isMatched && isset($match['length'])) {
                     foreach ($match['length'] as $operation => $lengthMatch) {
                         $operation = preg_replace('#\\s+#', '', $operation);
                         switch ($operation) {
                             case '<':
                                 $isMatched = $columnLength < $lengthMatch;
                                 break;
                             case '>':
                                 $isMatched = $columnLength > $lengthMatch;
                                 break;
                             case '>=':
                                 $isMatched = $columnLength >= $lengthMatch;
                                 break;
                             case '<=':
                                 $isMatched = $columnLength <= $lengthMatch;
                                 break;
                             case '==':
                                 $isMatched = $columnLength == $lengthMatch;
                                 break;
                             case '=':
                                 $isMatched = $columnLength == $lengthMatch;
                                 break;
                             default:
                                 $isMatched = false;
                         }
                     }
                 }
                 if ($isMatched) {
                     break;
                 }
             }
             if ($isMatched) {
                 $result = ArrayUtils::merge($result, $configField);
             }
         }
     }
     return $result;
 }
Example #2
0
 /**
  * Apply default values for some data set
  *
  * @param array $inputData   Входные данные
  * @param array $defaultData Нужные поля
  * @return array
  */
 public function applyDefaultValues($inputData, array $defaultData = null)
 {
     if (!$defaultData) {
         $defaultData = $this->getDefaultsRules();
     }
     if (!$defaultData) {
         return $inputData;
     }
     $result = ArrayUtils::merge($defaultData, $inputData);
     return $result;
 }