コード例 #1
0
 /** @inheridoc */
 protected function validateValue($value)
 {
     if ($this->type == FormatHelper::TYPE_LIST) {
         throw new NotSupportedException("TypeValidator not support '{$this->type}' validation" . ' out of model context');
     }
     try {
         $format = FormatHelper::typeToFormat($this->type);
         $this->filteredAttribute = Yii::$app->getFormatter()->format($value, $format);
     } catch (\Exception $e) {
         Yii::warning('Type validation error' . PHP_EOL . $e->__toString(), __METHOD__);
         return $this->buildMessage($this->type);
     }
 }
コード例 #2
0
 /**
  * @param $name
  * @param $config
  * @return object
  * @throws \LogicException
  * @SuppressWarnings(PHPMD.ElseExpression)
  */
 protected function createActiveParam($name, $config)
 {
     $param = Yii::createObject($config);
     if (empty($param->description)) {
         $param->description = 'Active param';
     }
     if (empty($param->value)) {
         $param->value = Yii::$app->formatter->format('', FormatHelper::typeToFormat($param->type));
     }
     if (empty($param->category)) {
         $param->category = $this->uniqueId;
     }
     Yii::info("Creating active param '{$name}' with config " . VarDumper::dumpAsString($param->getAttributes()), __METHOD__);
     if (!$this->lazyPersistence || !$param->lazyPersistence) {
         $param->set($param->value);
         $this->cacheValid = false;
     } else {
         Yii::info("Skipping add query to storage for param '{$name}' due to lazy persistence", __METHOD__);
     }
     return $param;
 }