本文整理匯總了PHP中Model\User::dispense方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::dispense方法的具體用法?PHP User::dispense怎麽用?PHP User::dispense使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Model\User
的用法示例。
在下文中一共展示了User::dispense方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: perform
public static function perform(Comment $comment)
{
if ($comment->comment_id) {
return;
}
$article = $comment->article()->find_one();
if ($article->user_id != $comment->user_id) {
Notify::dispense()->create(array('user_id' => $article->user_id, 'from_user_id' => $comment->user_id, 'type' => Notify::REPLY, 'object_type' => $article->type(), 'object_id' => $article->id, 'message' => $comment->text))->save();
}
if (!preg_match_all('/@(\\w+)/', $comment->text, $match)) {
return;
}
$users = array();
foreach ($match[1] as $username) {
if (isset($users[$username])) {
continue;
}
if (!($user = User::dispense()->where('name', $username)->find_one())) {
continue;
}
// If mention in reply, ignore mention notify
if ($user->id == $article->user_id) {
continue;
}
$users[$username] = $user->id;
}
foreach ($users as $user_id) {
Notify::dispense()->create(array('user_id' => $user_id, 'from_user_id' => $comment->user_id, 'type' => Notify::MENTION, 'object_type' => $article->type(), 'object_id' => $article->id, 'message' => $comment->text))->save();
}
}
示例2: get
/**
* GET /
*/
public function get()
{
$id = $this->params['id'];
$post = \Model\User::dispense()->find_one($id);
if (!$post) {
$this->error('Unknown User');
}
$this->data = $post->as_array();
}
示例3: parserUser
public function parserUser($text)
{
return preg_replace_callback('{
(?<!(?:\\[|`))\\s?
@([\\w]{1,20})
\\s(?!(?:\\]|`))
}xs', function ($match) {
if ($user = User::dispense()->where('name', $match[1])->find_one()) {
return '[' . trim($match[0]) . '](' . Url::to('/u/' . $user->id) . ')';
} else {
return $match[0];
}
}, $text);
}