Exemple #1
0
 /**
  * Generate GUID. It will check if the generated GUID existed in database
  * table, if existed, it will regenerate one.
  * @return string the generated GUID.
  */
 public static function generateGuid()
 {
     return Number::guid();
 }
 /**
  * Remove invalid blame guid from provided guid array.
  * @param array $guids guid array of blames.
  * @return array guid array of blames unset invalid.
  */
 protected function unsetInvalidBlames($guids)
 {
     $checkedGuids = Number::unsetInvalidUuids($guids);
     $multiBlamesClass = $this->multiBlamesClass;
     foreach ($checkedGuids as $key => $guid) {
         $blame = $multiBlamesClass::findOne($guid);
         if (!$blame) {
             unset($checkedGuids[$key]);
         }
     }
     $diff = array_diff($guids, $checkedGuids);
     $eventName = static::$eventMultipleBlamesChanged;
     $this->trigger($eventName, new MultipleBlameableEvent(['blamesChanged' => !empty($diff)]));
     return $checkedGuids;
 }
Exemple #3
0
 /**
  * Generate the ID. You can override this method to implement your own
  * generation algorithm.
  * @return string the generated ID.
  */
 public function generateId()
 {
     if ($this->idAttributeType == self::$idTypeInteger) {
         do {
             $result = Number::randomNumber($this->idAttributePrefix, $this->idAttributeLength);
         } while ($this->checkIdExists((int) $result));
         return $result;
     }
     if ($this->idAttributeType == self::$idTypeString) {
         return $this->idAttributePrefix . Yii::$app->security->generateRandomString($this->idAttributeLength - strlen($this->idAttributePrefix));
     }
     if ($this->idAttributeType == self::$idTypeAutoIncrement) {
         return null;
     }
     return false;
 }