'setPrimaryKeyValue', ]; } public function setPrimaryKeyValue() : bool { if ($this->owner->getPrimaryKey() === null) { $this->refreshPrimaryKeyValue(); } return true; } public function refreshPrimaryKeyValue() { do { $key = $this->generateValue(); } while ($this->isValueExists($key)); $this->owner->{$this->getPrimaryKeyName()} = $key; } protected function generateValue() : string { return (string)call_user_func($this->value); } protected function isValueExists(string $key) : bool { return $this->owner->find()->andWhere([$this->getPrimaryKeyName() => $key])->exists(); } protected function getPrimaryKeyName() : string { $owner = $this->owner; $primaryKeys = $owner->primaryKey(); if (!isset($primaryKeys[0])) { throw new InvalidConfigException('"' . get_class($owner) . '" must have a primary key.'); } elseif (count($primaryKeys) > 1) { throw new InvalidConfigException('Current behavior don\'t support models with more then one primary key.'); } /** @noinspection PhpIncompatibleReturnTypeInspection да как бы оно всё нормально, но шторм мне не верит */ return $primaryKeys[0]; } }