示例#1
0
 public static function generate()
 {
     if (function_exists('com_create_guid') === true) {
         return Guid::parse(com_create_guid());
     }
     $data = openssl_random_pseudo_bytes(16);
     $data[6] = chr(ord($data[6]) & 0xf | 0x40);
     // set version to 0100
     $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
     // set bits 6-7 to 10
     return Guid::parseBinaryString($data);
 }
 /**
  * @param ActiveRecord $contract
  *
  * @return \yii\base\Object
  */
 public function entityToContract(ActiveRecord $entity)
 {
     /** @var $contract ObjectHistoryItem */
     if (!$entity instanceof ObjectHistoryEntity) {
         throw new ManagerException("Wrong type of mapping entity");
     }
     $objectHistory = new ObjectHistoryItem();
     $objectHistory->guid = Guid::parseBinaryString($entity->id);
     $objectHistory->category = $contract->category;
     $objectHistory->type = new HistoryTypeEnum($contract->type);
     if ($contract->changeDateTime !== null) {
         $objectHistory->changeDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $contract->changeDateTime);
     }
     return $objectHistory;
 }
 /**
  * @param Guid $guid
  * @return ObjectHistoryItem
  */
 private function getById(Guid $guid)
 {
     $entity = ObjectHistoryEntity::findOne($guid->toBinaryString());
     return $entity !== null ? $this->_mapper->entityToContract($entity) : null;
 }
示例#4
0
 /**
  * Возвращает GUID
  *
  * @return Guid
  */
 protected function createGuid()
 {
     return Guid::generate();
 }