/** * Generate new key * * @return string */ protected function generateNewId() { $newId = substr($this->keygen->generate(), 0, 8); if (!preg_match('/[^0-9]/', $newId)) { $newId = $this->generateNewId(); } return $newId; }
/** * Set setting information * * @param array $data setting data * @return void */ public function set(array $data) { $this->config = $this->cfg->set($this->key, $data); if (!$this->config->get('uuid')) { $this->config->set('uuid', $this->keygen->generate()); $this->cfg->modify($this->config); } }
/** * insert new document revision * * @param DocumentEntity $doc inserted document entity * @param ConfigEntity $config document config entity * @return DocumentEntity */ public function insert(DocumentEntity $doc, ConfigEntity $config) { $doc->revisionId = $this->keygen->generate(); $doc->revisionNo = $this->nextNo($doc->id); $this->connection->dynamic($this->table)->insert($doc->getAttributes()); $configs = $this->revisionManager->getHandler()->getConfigHandler()->gets($config->get('group')); $this->revisionManager->add($configs, $doc->getAttributes()); return $doc; }
/** * comment 저장 * * @param CommentEntity $comment comment object * @return CommentEntity */ public function insert(CommentEntity $comment) { $id = $this->keygen->generate(); $timestamp = time(); $now = date('Y-m-d H:i:s', $timestamp); $attributes = array_merge($comment->getAttributes(), ['id' => $id, 'createdAt' => $now, 'updatedAt' => $now]); if (isset($attributes['publishedAt']) === false) { $attributes['publishedAt'] = $now; } if (isset($attributes['parentId']) === false) { $attributes['head'] = $timestamp . '-' . $id; } $this->conn->dynamic($this->table, ['id' => $comment->instanceId])->insert($attributes); return $this->findBaseInstanceId($comment->instanceId, $id); }
/** * create file * * @param string $content file content * @param string $path directory for saved * @param string $name saved name * @param string|null $disk disk for saved * @param string|null $originId original file id * @param UserInterface $user user instance * @return File */ public function create($content, $path, $name, $disk = null, $originId = null, UserInterface $user = null) { $id = $this->keygen->generate(); $path = $this->makePath($id, $path); $tempFile = $this->tempFiles->create($content); $disk = $disk ?: $this->distributor->allot($tempFile); $user = $user ?: $this->auth->user(); if (!$this->files->store($content, $path . '/' . $name, $disk)) { throw new WritingFailException(); } $file = $this->createModel(); $file->id = $id; $file->userId = $user->getId(); $file->disk = $disk; $file->path = $path; $file->filename = $name; $file->clientname = $name; $file->mime = $tempFile->getMimeType(); $file->size = $tempFile->getSize(); if ($originId !== null) { $file->originId = $originId; } $file->save(); $tempFile->destroy(); return $file; }
/** * 새로운 임시저장 데이터 레코드를 삽입 * * @param TemporaryEntity $temporary 임시저장 객체 * @return TemporaryEntity */ public function insert(TemporaryEntity $temporary) { $attributes = array_merge($temporary->getAttributes(), ['id' => $this->keygen->generate(), 'createdAt' => date('Y-m-d H:i:s')]); $this->conn->table($this->table)->insert($attributes); return $this->createItem($attributes); }
/** * generateNewId * * @return string */ protected function generateNewId() { $newId = substr($this->keyGen->generate(), 0, 8); return $newId; }
/** * create file * * @param string $content file content * @param string $path directory for saved * @param string $name saved name * @param string|null $disk disk for saved * @param string|null $parentId original file id * @return File */ public function create($content, $path, $name, $disk = null, $parentId = null) { $id = $this->keygen->generate(); $file = $this->files->store($content, $this->makePathname($id, $path, $name), $disk); $file->id = $id; $file->clientname = $name; if ($parentId !== null) { $file->parentId = $parentId; } return $this->repo->insert($file); }
/** * Xpressengine의 Keygen을 사용하여 고유 아이디를 생성한후 주어진 entity의 id로 지정한다. * * @param Entity $entity id를 지정할 entkty * * @return void */ protected function generateId($entity) { $entity->id = $this->generator->generate(); }