本文整理汇总了PHP中Illuminate\Contracts\Bus\Dispatcher类的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher类的具体用法?PHP Dispatcher怎么用?PHP Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* @param Requests\SignUpRequest $request
* @param CommandDispatcher $commandDispatcher
*
* @return
*/
public function store(Requests\SignUpRequest $request, CommandDispatcher $commandDispatcher)
{
$commandDispatcher->dispatchFrom(RegisterUser::class, $request);
\Auth::login(User::where('username', $request['username'])->first());
Flash::overlay('Welcome!!');
return Redirect::home();
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(Dispatcher $dispatcher)
{
$id = \App\Domain\ValueObject\UUID::make();
$title = new \App\Domain\ValueObject\String\NonBlank($this->argument("title"));
$author = new \App\Domain\ValueObject\String\NonBlank($this->argument("github_username"));
$post = \App\Domain\ValueObject\Post::make($id, $title, $author);
$dispatcher->dispatch(new \App\Commands\CreatePost($post));
$this->info("Post {$id} created.");
}
示例3: boot
public function boot(Dispatcher $dispatcher)
{
$dispatcher->mapUsing(function ($command) {
$command = str_replace('Commands\\', 'Commands\\Handlers\\', get_class($command));
return trim($command, '\\') . 'Handler@handle';
});
$this->registerMiddleware($this->app['router']);
$this->registerModuleResourceNamespaces();
$this->setLocalesConfigurations();
}
示例4: 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;
}
示例5: 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;
}
示例6: failed
/**
* Call the failed method on the job instance.
*
* @param array $data
* @return void
*/
public function failed(array $data)
{
$handler = $this->dispatcher->resolveHandler($command = unserialize($data['command']));
if (method_exists($handler, 'failed')) {
call_user_func([$handler, 'failed'], $command);
}
}
示例7: 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));
}
示例8: 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));
}
示例9: 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));
}
示例10: 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));
}
示例11: destroy
/**
* Unfallow a User
*
* @param $userIdToUnfallow
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($userIdToUnfallow, Request $request)
{
$request->replace(array_add($request->all(), 'userId', Auth::id()));
$this->dispatcher->dispatchFrom(UnfallowUser::class, $request);
Flash::success('You have now unfallowed this user');
return Redirect::back();
}
示例12: 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;
}
示例13: 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));
}
示例14: 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));
}
示例15: call
/**
* Handle the queued job.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @param array $data
* @return void
*/
public function call(Job $job, array $data)
{
$command = $this->setJobInstanceIfNecessary($job, unserialize($data['command']));
$this->dispatcher->dispatchNow($command);
if (!$job->isDeletedOrReleased()) {
$job->delete();
}
}