コード例 #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->logicalFormat === null) {
         $format = $this->type . 'Format';
         $pattern = Yii::$app->formatter->{$format};
     } else {
         $pattern = $this->logicalFormat;
     }
     if (substr($pattern, 0, 4) === 'php:') {
         $this->_phpLogicalFormat = substr($pattern, 4);
     } else {
         $this->_phpLogicalFormat = FormatConverter::convertDateIcuToPhp($pattern, $this->type);
     }
     if ($this->physicalFormat === null) {
         $driverName = Yii::$app->db->driverName;
         if (isset(static::$dbDatetimeFormat[$driverName])) {
             $pattern = static::$dbDatetimeFormat[$driverName][$this->type];
         } else {
             $pattern = static::$dbDatetimeFormat['default'][$this->type];
         }
     } else {
         $pattern = $this->physicalFormat;
     }
     if (substr($pattern, 0, 4) === 'php:') {
         $this->_phpPhysicalFormat = substr($pattern, 4);
     } else {
         $this->_phpPhysicalFormat = FormatConverter::convertDateIcuToPhp($pattern, $this->type);
     }
     parent::init();
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     /* @var $owner \yii\db\ActiveRecord */
     foreach ($this->attributes as $attribute => $defition) {
         list($relation, $field) = $defition;
         if (is_string($relation)) {
             $r = $owner->getRelation($relation);
             $class = $r->modelClass;
             $link = $r->link;
         } elseif (is_array($relation)) {
             $class = $relation[0];
             $link = array_slice($relation, 1);
         } else {
             throw new InvalidConfigException("Invalid attribute definision for \"{$attribute}\"");
         }
         foreach ($link as $from => $to) {
             $this->_relations[$attribute] = [$class, $field, $from];
             $this->attributes[$attribute] = $to;
             break;
         }
     }
     parent::attach($owner);
 }