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


PHP Dispatcher::dispatch方法代码示例

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


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

示例1: data

 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $actor = $request->getAttribute('actor');
     $discussionId = array_get($request->getQueryParams(), 'id');
     $data = array_get($request->getParsedBody(), 'data', []);
     $discussion = $this->bus->dispatch(new EditDiscussion($discussionId, $actor, $data));
     // TODO: Refactor the ReadDiscussion (state) command into EditDiscussion?
     // That's what extensions will do anyway.
     if ($readNumber = array_get($data, 'attributes.readNumber')) {
         $state = $this->bus->dispatch(new ReadDiscussion($discussionId, $actor, $readNumber));
         $discussion = $state->discussion;
     }
     if ($posts = $discussion->getModifiedPosts()) {
         $discussionPosts = $discussion->postsVisibleTo($actor)->orderBy('time')->lists('id')->all();
         foreach ($discussionPosts as &$id) {
             foreach ($posts as $post) {
                 if ($id == $post->id) {
                     $id = $post;
                     $post->discussion = $post->discussion_id;
                     $post->user = $post->user_id;
                 }
             }
         }
         $discussion->setRelation('posts', $discussionPosts);
         $this->include = array_merge($this->include, ['posts', 'posts.discussion', 'posts.user']);
     }
     return $discussion;
 }
开发者ID:RudolfFussek,项目名称:core,代码行数:31,代码来源:UpdateDiscussionController.php

示例2: delete

 /**
  * {@inheritdoc}
  */
 protected function delete(Request $request)
 {
     $id = $request->get('id');
     $actor = $request->actor;
     $input = $request->all();
     $this->bus->dispatch(new DeleteDiscussion($id, $actor, $input));
 }
开发者ID:redstarxz,项目名称:flarumone,代码行数:10,代码来源:DeleteAction.php

示例3: data

 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $id = array_get($request->getQueryParams(), 'id');
     $actor = $request->getAttribute('actor');
     $data = array_get($request->getParsedBody(), 'data');
     return $this->bus->dispatch(new EditLink($id, $actor, $data));
 }
开发者ID:sijad,项目名称:flarum-ext-links,代码行数:10,代码来源:UpdateLinkController.php

示例4: data

 /**
  * Get the data to be serialized and assigned to the response document.
  *
  * @param ServerRequestInterface $request
  * @param Document               $document
  * @return mixed
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $postId = array_get($request->getQueryParams(), 'post');
     $actor = $request->getAttribute('actor');
     $file = array_get($request->getParsedBody(), 'image');
     return $this->bus->dispatch(new UploadImage($postId, base64_decode($file), $actor));
 }
开发者ID:Flarum-Chinese,项目名称:flarum-ext-image-upload,代码行数:14,代码来源:UploadImageController.php

示例5: data

 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $id = array_get($request->getQueryParams(), 'id');
     $actor = $request->getAttribute('actor');
     $file = array_get($request->getUploadedFiles(), 'avatar');
     return $this->bus->dispatch(new UploadAvatar($id, $file, $actor));
 }
开发者ID:clops,项目名称:core,代码行数:10,代码来源:UploadAvatarController.php

示例6: handle

 /**
  * @param StartDiscussion $command
  * @return mixed
  * @throws Exception
  */
 public function handle(StartDiscussion $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->assertCan($actor, 'startDiscussion');
     // Create a new Discussion entity, persist it, and dispatch domain
     // events. Before persistence, though, fire an event to give plugins
     // an opportunity to alter the discussion entity based on data in the
     // command they may have passed through in the controller.
     $discussion = Discussion::start(array_get($data, 'attributes.title'), $actor);
     $this->events->fire(new DiscussionWillBeSaved($discussion, $actor, $data));
     $this->validator->assertValid($discussion->getAttributes());
     $discussion->save();
     // Now that the discussion has been created, we can add the first post.
     // We will do this by running the PostReply command.
     try {
         $post = $this->bus->dispatch(new PostReply($discussion->id, $actor, $data));
     } catch (Exception $e) {
         $discussion->delete();
         throw $e;
     }
     // Before we dispatch events, refresh our discussion instance's
     // attributes as posting the reply will have changed some of them (e.g.
     // last_time.)
     $discussion->setRawAttributes($post->discussion->getAttributes(), true);
     $discussion->setStartPost($post);
     $discussion->setLastPost($post);
     $this->dispatchEventsFor($discussion, $actor);
     $discussion->save();
     return $discussion;
 }
开发者ID:sijad,项目名称:core,代码行数:36,代码来源:StartDiscussionHandler.php

示例7: delete

 /**
  * {@inheritdoc}
  */
 protected function delete(ServerRequestInterface $request)
 {
     $id = array_get($request->getQueryParams(), 'id');
     $actor = $request->getAttribute('actor');
     $input = $request->getParsedBody();
     $this->bus->dispatch(new DeleteDiscussion($id, $actor, $input));
 }
开发者ID:flarum,项目名称:core,代码行数:10,代码来源:DeleteDiscussionController.php

示例8: authenticated

    /**
     * Respond with JavaScript to inform the Flarum app about the user's
     * authentication status.
     *
     * An array of identification attributes must be passed as the first
     * argument. These are checked against existing user accounts; if a match is
     * found, then the user is authenticated and logged into that account via
     * cookie. The Flarum app will then simply refresh the page.
     *
     * If no matching account is found, then an AuthToken will be generated to
     * store the identification attributes. This token, along with an optional
     * array of suggestions, will be passed into the Flarum app's sign up modal.
     * This results in the user not having to choose a password. When they
     * complete their registration, the identification attributes will be
     * set on their new user account.
     *
     * @param array $identification
     * @param array $suggestions
     * @return HtmlResponse
     */
    protected function authenticated(array $identification, array $suggestions = [])
    {
        $user = User::where($identification)->first();
        // If a user with these attributes already exists, then we will log them
        // in by generating an access token. Otherwise, we will generate a
        // unique token for these attributes and add it to the response, along
        // with the suggested account information.
        if ($user) {
            $accessToken = $this->bus->dispatch(new GenerateAccessToken($user->id));
            $payload = ['authenticated' => true];
        } else {
            $token = AuthToken::generate($identification);
            $token->save();
            $payload = array_merge($identification, $suggestions, ['token' => $token->id]);
        }
        $content = sprintf('<script>
window.opener.app.authenticationComplete(%s);
window.close();
</script>', json_encode($payload));
        $response = new HtmlResponse($content);
        if (isset($accessToken)) {
            // Extend the token's expiry to 2 weeks so that we can set a
            // remember cookie
            $accessToken::unguard();
            $accessToken->update(['expires_at' => new DateTime('+2 weeks')]);
            $response = $this->withRememberCookie($response, $accessToken->id);
        }
        return $response;
    }
开发者ID:redstarxz,项目名称:flarumone,代码行数:49,代码来源:AuthenticatorTrait.php

示例9: data

 /**
  * Get the data to be serialized and assigned to the response document.
  *
  * @param ServerRequestInterface $request
  * @param Document               $document
  * @return mixed
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $title = Arr::get($request->getParsedBody(), 'title');
     $start_post_id = Arr::get($request->getParsedBody(), 'start_post_id');
     $end_post_id = Arr::get($request->getParsedBody(), 'end_post_id');
     $actor = $request->getAttribute('actor');
     return $this->bus->dispatch(new SplitDiscussion($title, $start_post_id, $end_post_id, $actor));
 }
开发者ID:flagrow,项目名称:flarum-ext-split,代码行数:15,代码来源:SplitController.php

示例10: handle

 /**
  * @param Request $request
  * @param array $routeParams
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function handle(Request $request, array $routeParams = [])
 {
     try {
         $token = array_get($routeParams, 'token');
         $user = $this->bus->dispatch(new ConfirmEmail($token));
     } catch (InvalidConfirmationTokenException $e) {
         return new HtmlResponse('Invalid confirmation token');
     }
     $token = $this->bus->dispatch(new GenerateAccessToken($user->id));
     return $this->withRememberCookie($this->redirectTo('/'), $token->id);
 }
开发者ID:redstarxz,项目名称:flarumone,代码行数:16,代码来源:ConfirmEmailAction.php

示例11: handle

 /**
  * @param Request $request
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function handle(Request $request)
 {
     try {
         $token = array_get($request->getQueryParams(), 'token');
         $user = $this->bus->dispatch(new ConfirmEmail($token));
     } catch (InvalidConfirmationTokenException $e) {
         return new HtmlResponse('Invalid confirmation token');
     }
     $token = $this->bus->dispatch(new GenerateAccessToken($user->id));
     return $this->withRememberCookie(new RedirectResponse($this->app->url()), $token->id);
 }
开发者ID:ygbhf,项目名称:flarum-full,代码行数:15,代码来源:ConfirmEmailController.php

示例12: create

 /**
  * Create a discussion according to input from the API request.
  *
  * @param JsonApiRequest $request
  * @return \Flarum\Core\Discussions\Discussion
  */
 protected function create(JsonApiRequest $request)
 {
     $actor = $request->actor;
     $discussion = $this->bus->dispatch(new StartDiscussion($actor, $request->get('data')));
     // After creating the discussion, we assume that the user has seen all
     // of the posts in the discussion; thus, we will mark the discussion
     // as read if they are logged in.
     if ($actor->exists) {
         $this->bus->dispatch(new ReadDiscussion($discussion->id, $actor, 1));
     }
     return $discussion;
 }
开发者ID:redstarxz,项目名称:flarumone,代码行数:18,代码来源:CreateAction.php

示例13: handle

 /**
  * @param Request $request
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function handle(Request $request)
 {
     try {
         $token = array_get($request->getQueryParams(), 'token');
         $user = $this->bus->dispatch(new ConfirmEmail($token));
     } catch (InvalidConfirmationTokenException $e) {
         return new HtmlResponse('Invalid confirmation token');
     }
     $session = $request->getAttribute('session');
     $this->authenticator->logIn($session, $user->id);
     return new RedirectResponse($this->app->url());
 }
开发者ID:flarum,项目名称:core,代码行数:16,代码来源:ConfirmEmailController.php

示例14: data

 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $actor = $request->getAttribute('actor');
     $discussion = $this->bus->dispatch(new StartDiscussion($actor, array_get($request->getParsedBody(), 'data')));
     // After creating the discussion, we assume that the user has seen all
     // of the posts in the discussion; thus, we will mark the discussion
     // as read if they are logged in.
     if ($actor->exists) {
         $this->bus->dispatch(new ReadDiscussion($discussion->id, $actor, 1));
     }
     return $discussion;
 }
开发者ID:ygbhf,项目名称:flarum-full,代码行数:15,代码来源:CreateDiscussionController.php

示例15: data

 /**
  * Update a discussion according to input from the API request, and return
  * it ready to be serialized and assigned to the JsonApi response.
  *
  * @param \Flarum\Api\JsonApiRequest $request
  * @param \Flarum\Api\JsonApiResponse $response
  * @return \Flarum\Core\Models\Discussion
  */
 protected function data(JsonApiRequest $request, JsonApiResponse $response)
 {
     $user = $request->actor->getUser();
     $discussionId = $request->get('id');
     if ($data = array_except($request->get('data'), ['readNumber'])) {
         $discussion = $this->bus->dispatch(new EditDiscussionCommand($discussionId, $user, $data));
     }
     if ($readNumber = $request->get('data.readNumber')) {
         $state = $this->bus->dispatch(new ReadDiscussionCommand($discussionId, $user, $readNumber));
         $discussion = $state->discussion;
     }
     return $discussion;
 }
开发者ID:Qiang1234,项目名称:core,代码行数:21,代码来源:UpdateAction.php


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