当前位置: 首页>>代码示例>>PHP>>正文


PHP UUID::gen方法代码示例

本文整理汇总了PHP中UUID::gen方法的典型用法代码示例。如果您正苦于以下问题:PHP UUID::gen方法的具体用法?PHP UUID::gen怎么用?PHP UUID::gen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UUID的用法示例。


在下文中一共展示了UUID::gen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testUnique

 public function testUnique()
 {
     $reps = 100;
     $ids = array();
     for ($i = 0; $i < $reps; $i++) {
         $ids[] = UUID::gen();
     }
     $this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique");
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:9,代码来源:UUIDTest.php

示例2: save

 /**
  * Save a vote on a question or answer
  *
  * @param Profile  $profile
  * @param QnA_Question the question being voted on
  * @param QnA_Answer   the answer being voted on
  * @param vote
  * @param array
  *
  * @return Void
  */
 static function save($profile, $question, $answer, $vote)
 {
     $v = new QnA_Vote();
     $v->id = UUID::gen();
     $v->profile_id = $profile->id;
     $v->question_id = $question->id;
     $v->answer_id = $answer->id;
     $v->vote = $vote;
     $v->created = common_sql_now();
     common_log(LOG_DEBUG, "Saving vote: {$v->id} {$v->vote}");
     $v->insert();
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:23,代码来源:QnA_Vote.php

示例3: onEndRevokeRole

 function onEndRevokeRole($profile, $role)
 {
     $modlog = new ModLog();
     $modlog->id = UUID::gen();
     $modlog->profile_id = $profile->id;
     $cur = common_current_user();
     if (!empty($cur)) {
         $modlog->moderator_id = $cur->id;
     }
     $modlog->role = $role;
     $modlog->is_grant = 0;
     $modlog->created = common_sql_now();
     $modlog->insert();
     return true;
 }
开发者ID:phpsource,项目名称:gnu-social,代码行数:15,代码来源:ModLogPlugin.php

示例4: onEndRevokeRole

 function onEndRevokeRole($profile, $role)
 {
     $modlog = new ModLog();
     $modlog->id = UUID::gen();
     $modlog->profile_id = $profile->id;
     $scoped = Profile::current();
     if ($scoped instanceof Profile) {
         $modlog->moderator_id = $scoped->getID();
     }
     $modlog->role = $role;
     $modlog->is_grant = 0;
     $modlog->created = common_sql_now();
     $modlog->insert();
     return true;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:15,代码来源:ModLogPlugin.php

示例5: saveNew

 static function saveNew(Profile $profile, $url, $options = array())
 {
     $vid = new Video();
     $vid->id = UUID::gen();
     $vid->profile_id = $profile->id;
     $vid->url = $url;
     $options['object_type'] = Video::OBJECT_TYPE;
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = common_local_url('showvideo', array('id' => $vid->id));
     }
     if (!array_key_exists('rendered', $options)) {
         $options['rendered'] = sprintf("<video src=\"%s\">Sorry, your browser doesn't support the video tag.</video>", $url);
     }
     $vid->uri = $options['uri'];
     $vid->insert();
     return Notice::saveNew($profile->id, '', 'web', $options);
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:17,代码来源:Video.php

示例6: saveNew

 static function saveNew(Profile $profile, $photo_uri, $thumb_uri, $title, $description, $options = array())
 {
     $photo = new Photo();
     $photo->id = UUID::gen();
     $photo->profile_id = $profile->id;
     $photo->photo_uri = $photo_uri;
     $photo->thumb_uri = $thumb_uri;
     $options['object_type'] = Photo::OBJECT_TYPE;
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = common_local_url('showphoto', array('id' => $photo->id));
     }
     if (!array_key_exists('rendered', $options)) {
         $options['rendered'] = sprintf("<img src=\"%s\" alt=\"%s\"></img>", $photo_uri, $title);
     }
     $photo->uri = $options['uri'];
     $photo->insert();
     return Notice::saveNew($profile->id, '', 'web', $options);
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:18,代码来源:Photo.php

示例7: saveNewFromNotice

 function saveNewFromNotice($notice, $event, $verb)
 {
     $other = RSVP::getKV('uri', $notice->uri);
     if (!empty($other)) {
         // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond").
         throw new ClientException(_m('RSVP already exists.'));
     }
     $profile = $notice->getProfile();
     try {
         $other = RSVP::getByKeys(['profile_id' => $profile->getID(), 'event_uri' => $event->getUri()]);
         // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond").
         throw new AlreadyFulfilledException(_m('RSVP already exists.'));
     } catch (NoResultException $e) {
         // No previous RSVP, so go ahead and add.
     }
     $rsvp = new RSVP();
     preg_match('/\\/([^\\/]+)\\/*/', $notice->uri, $match);
     $rsvp->id = $match[1] ? $match[1] : UUID::gen();
     $rsvp->profile_id = $profile->id;
     $rsvp->event_id = $event->id;
     $rsvp->response = self::codeFor($verb);
     $rsvp->created = $notice->created;
     $rsvp->uri = $notice->uri;
     $rsvp->insert();
     self::blow('rsvp:for-event:%s', $event->getUri());
     return $rsvp;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:27,代码来源:RSVP.php

示例8: saveNew

 /**
  * Save a new poll notice
  *
  * @param Profile $profile
  * @param Poll    $poll the poll being responded to
  * @param int     $selection (1-based)
  * @param array   $opts (poll responses)
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $poll, $selection, $options = null)
 {
     if (empty($options)) {
         $options = array();
     }
     if (!$poll->isValidSelection($selection)) {
         // TRANS: Client exception thrown when responding to a poll with an invalid option.
         throw new ClientException(_m('Invalid poll selection.'));
     }
     $opts = $poll->getOptions();
     $answer = $opts[$selection - 1];
     $pr = new Poll_response();
     $pr->id = UUID::gen();
     $pr->profile_id = $profile->id;
     $pr->poll_id = $poll->id;
     $pr->selection = $selection;
     if (array_key_exists('created', $options)) {
         $pr->created = $options['created'];
     } else {
         $pr->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $pr->uri = $options['uri'];
     } else {
         $pr->uri = common_local_url('showpollresponse', array('id' => $pr->id));
     }
     common_log(LOG_DEBUG, "Saving poll response: {$pr->id} {$pr->uri}");
     $pr->insert();
     // TRANS: Notice content voting for a poll.
     // TRANS: %s is the chosen option in the poll.
     $content = sprintf(_m('voted for "%s"'), $answer);
     $link = '<a href="' . htmlspecialchars($poll->uri) . '">' . htmlspecialchars($answer) . '</a>';
     // TRANS: Rendered version of the notice content voting for a poll.
     // TRANS: %s a link to the poll with the chosen option as link description.
     $rendered = sprintf(_m('voted for "%s"'), $link);
     $tags = array();
     $options = array_merge(array('urls' => array(), 'rendered' => $rendered, 'tags' => $tags, 'reply_to' => $poll->getNotice()->id, 'object_type' => PollPlugin::POLL_RESPONSE_OBJECT), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $pr->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:53,代码来源:Poll_response.php

示例9: saveNew

 /**
  * Save a new answer notice
  *
  * @param Profile  $profile
  * @param Question $Question the question being answered
  * @param array
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $question, $text, $options = null)
 {
     if (empty($options)) {
         $options = array();
     }
     $answer = new QnA_Answer();
     $answer->id = UUID::gen();
     $answer->profile_id = $profile->id;
     $answer->question_id = $question->id;
     $answer->revisions = 0;
     $answer->best = 0;
     $answer->content = $text;
     $answer->created = common_sql_now();
     $answer->uri = common_local_url('qnashowanswer', array('id' => $answer->id));
     common_log(LOG_DEBUG, "Saving answer: {$answer->id}, {$answer->uri}");
     $answer->insert();
     $content = sprintf(_m('answered "%s"'), $question->title);
     $link = '<a href="' . htmlspecialchars($answer->uri) . '">' . htmlspecialchars($question->title) . '</a>';
     // TRANS: Rendered version of the notice content answering a question.
     // TRANS: %s a link to the question with question title as the link content.
     $rendered = sprintf(_m('answered "%s"'), $link);
     $tags = array();
     $replies = array();
     $options = array_merge(array('urls' => array(), 'content' => $content, 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'reply_to' => $question->getNotice()->id, 'object_type' => self::OBJECT_TYPE), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $answer->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:39,代码来源:QnA_Answer.php

示例10: saveActivityObject

 /**
  * Store a Bookmark object
  *
  * @param Profile $profile     To save the bookmark for
  * @param string  $title       Title of the bookmark
  * @param string  $url         URL of the bookmark
  * @param string  $description Description of the bookmark
  *
  * @return Bookmark the Bookmark object
  */
 static function saveActivityObject(ActivityObject $actobj, Notice $stored)
 {
     $url = null;
     // each extra element is array('tagname', array('attr'=>'val', ...), 'content')
     foreach ($actobj->extra as $extra) {
         if ($extra[1]['rel'] !== 'related') {
             continue;
         }
         if ($url === null && strlen($extra[1]['href']) > 0) {
             $url = $extra[1]['href'];
         } elseif ($url !== null) {
             // TRANS: Client exception thrown when a bookmark is formatted incorrectly.
             throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
         }
     }
     if (is_null($url)) {
         // TRANS: Client exception thrown when a bookmark is formatted incorrectly.
         throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
     }
     if (!strlen($actobj->title)) {
         throw new ClientException(_m('You must provide a non-empty title.'));
     }
     if (!common_valid_http_url($url)) {
         throw new ClientException(_m('Only web bookmarks can be posted (HTTP or HTTPS).'));
     }
     try {
         $object = self::getByURL($stored->getProfile(), $url);
         throw new ClientException(_m('You have already bookmarked this URL.'));
     } catch (NoResultException $e) {
         // Alright, so then we have to create it.
     }
     $nb = new Bookmark();
     $nb->id = UUID::gen();
     $nb->uri = $stored->getUri();
     $nb->profile_id = $stored->getProfile()->getID();
     $nb->title = $actobj->title;
     $nb->url = $url;
     $nb->description = $actobj->summary;
     $nb->created = $stored->created;
     $result = $nb->insert();
     if ($result === false) {
         throw new ServerException('Could not insert Bookmark into database!');
     }
     return $nb;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:55,代码来源:Bookmark.php

示例11: send

 static function send($user, $group, $text)
 {
     if (!$user->hasRight(Right::NEWMESSAGE)) {
         // XXX: maybe break this out into a separate right
         // TRANS: Exception thrown when trying to send group private message without having the right to do that.
         // TRANS: %s is a user nickname.
         throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'), $user->nickname));
     }
     Group_privacy_settings::ensurePost($user, $group);
     $text = $user->shortenLinks($text);
     // We use the same limits as for 'regular' private messages.
     if (Message::contentTooLong($text)) {
         // TRANS: Exception thrown when trying to send group private message that is too long.
         // TRANS: %d is the maximum meggage length.
         throw new Exception(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()));
     }
     // Valid! Let's do this thing!
     $gm = new Group_message();
     $gm->id = UUID::gen();
     $gm->uri = common_local_url('showgroupmessage', array('id' => $gm->id));
     $gm->from_profile = $user->id;
     $gm->to_group = $group->id;
     $gm->content = $text;
     // XXX: is this cool?!
     $gm->rendered = common_render_text($text);
     $gm->url = $gm->uri;
     $gm->created = common_sql_now();
     // This throws a conniption if there's a problem
     $gm->insert();
     $gm->distribute();
     return $gm;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:32,代码来源:Group_message.php

示例12: getUpload

 function getUpload()
 {
     $imagefile = ImageFile::fromUpload('photo_upload');
     if ($imagefile === null) {
         throw new Exception(_('No file uploaded'));
     }
     $title = $this->trimmed('title');
     $description = $this->trimmed('description');
     $new_filename = UUID::gen() . image_type_to_extension($imagefile->type);
     move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $new_filename);
     // XXX: we should be using https where we can. TODO: detect whether the server
     // supports this.
     $photo_uri = 'http://' . common_config('site', 'server') . '/file/' . $new_filename;
     $thumb_uri = $photo_uri;
     $photo = Photo::saveNew($profile, $photo_uri, $thumb_uri, $title, $description, $options);
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:16,代码来源:newphoto.php

示例13: saveNew

 function saveNew($profile, $event, $verb, $options = array())
 {
     if (array_key_exists('uri', $options)) {
         $other = RSVP::staticGet('uri', $options['uri']);
         if (!empty($other)) {
             // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond").
             throw new ClientException(_m('RSVP already exists.'));
         }
     }
     $other = RSVP::pkeyGet(array('profile_id' => $profile->id, 'event_id' => $event->id));
     if (!empty($other)) {
         // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond").
         throw new ClientException(_m('RSVP already exists.'));
     }
     $rsvp = new RSVP();
     $rsvp->id = UUID::gen();
     $rsvp->profile_id = $profile->id;
     $rsvp->event_id = $event->id;
     $rsvp->response = self::codeFor($verb);
     if (array_key_exists('created', $options)) {
         $rsvp->created = $options['created'];
     } else {
         $rsvp->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $rsvp->uri = $options['uri'];
     } else {
         $rsvp->uri = common_local_url('showrsvp', array('id' => $rsvp->id));
     }
     $rsvp->insert();
     self::blow('rsvp:for-event:%s', $event->id);
     // XXX: come up with something sexier
     $content = $rsvp->asString();
     $rendered = $rsvp->asHTML();
     $options = array_merge(array('object_type' => $verb), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $rsvp->uri;
     }
     $eventNotice = $event->getNotice();
     if (!empty($eventNotice)) {
         $options['reply_to'] = $eventNotice->id;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:45,代码来源:RSVP.php

示例14: saveNew

 /**
  * Save a new question notice
  *
  * @param Profile $profile
  * @param string  $question
  * @param string  $title
  * @param string  $description
  * @param array   $option // and whatnot
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $title, $description, $options = array())
 {
     $q = new QnA_Question();
     $q->id = UUID::gen();
     $q->profile_id = $profile->id;
     $q->title = $title;
     $q->description = $description;
     if (array_key_exists('created', $options)) {
         $q->created = $options['created'];
     } else {
         $q->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $q->uri = $options['uri'];
     } else {
         $q->uri = common_local_url('qnashowquestion', array('id' => $q->id));
     }
     common_log(LOG_DEBUG, "Saving question: {$q->id} {$q->uri}");
     $q->insert();
     if (Notice::contentTooLong($q->title . ' ' . $q->uri)) {
         $max = Notice::maxContent();
         $uriLen = mb_strlen($q->uri);
         $targetLen = $max - ($uriLen + 15);
         $title = mb_substr($q->title, 0, $targetLen) . '…';
     }
     $content = $title . ' ' . $q->uri;
     $link = '<a href="' . htmlspecialchars($q->uri) . '">' . htmlspecialchars($q->title) . '</a>';
     // TRANS: Rendered version of the notice content creating a question.
     // TRANS: %s a link to the question as link description.
     $rendered = sprintf(_m('Question: %s'), $link);
     $tags = array('question');
     $replies = array();
     $options = array_merge(array('urls' => array(), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => self::OBJECT_TYPE), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $q->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:50,代码来源:QnA_Question.php

示例15: saveNew

 /**
  * Save a new poll notice
  *
  * @param Profile $profile
  * @param string  $question
  * @param array   $opts (poll responses)
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $question, $opts, $options = null)
 {
     if (empty($options)) {
         $options = array();
     }
     $p = new Poll();
     $p->id = UUID::gen();
     $p->profile_id = $profile->id;
     $p->question = $question;
     $p->options = implode("\n", $opts);
     if (array_key_exists('created', $options)) {
         $p->created = $options['created'];
     } else {
         $p->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $p->uri = $options['uri'];
     } else {
         $p->uri = common_local_url('showpoll', array('id' => $p->id));
     }
     common_log(LOG_DEBUG, "Saving poll: {$p->id} {$p->uri}");
     $p->insert();
     // TRANS: Notice content creating a poll.
     // TRANS: %1$s is the poll question, %2$s is a link to the poll.
     $content = sprintf(_m('Poll: %1$s %2$s'), $question, $p->uri);
     $link = '<a href="' . htmlspecialchars($p->uri) . '">' . htmlspecialchars($question) . '</a>';
     // TRANS: Rendered version of the notice content creating a poll.
     // TRANS: %s is a link to the poll with the question as link description.
     $rendered = sprintf(_m('Poll: %s'), $link);
     $tags = array('poll');
     $replies = array();
     $options = array_merge(array('urls' => array(), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => PollPlugin::POLL_OBJECT), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $p->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:47,代码来源:Poll.php


注:本文中的UUID::gen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。