本文整理汇总了PHP中event函数的典型用法代码示例。如果您正苦于以下问题:PHP event函数的具体用法?PHP event怎么用?PHP event使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了event函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Save the site to the database, create a config and add that config to nginx.
*
* @param $request
* @param $groupId
*
* @return bool
*/
public function handle($request, $groupId)
{
$uuid = $this->site->generateUuid($request['port'] . $request['name']);
$site = $this->createSite($request, $groupId, $uuid);
event(new SiteWasCreated($site, $request));
return [true, null];
}
示例2: newComment
public function newComment(Bin $bin, Requests\Bins\NewComment $request)
{
$comment = $bin->comments()->create(['user_id' => auth()->user()->getAuthIdentifier(), 'message' => $request->input('message')]);
event(new UserCommentedOnBin($comment));
session()->flash('success', 'Success! Comment added!');
return redirect()->to($comment->getCommentUrl());
}
示例3: getMiddleware
/**
* {@inheritdoc}
*/
protected function getMiddleware(Application $app)
{
$pipe = new MiddlewarePipe();
$path = parse_url($app->url(), PHP_URL_PATH);
$errorDir = __DIR__ . '/../../error';
if (!$app->isInstalled()) {
$app->register('Flarum\\Install\\InstallServiceProvider');
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.install.routes')]));
$pipe->pipe($path, new HandleErrors($errorDir, true));
} elseif ($app->isUpToDate() && !$app->isDownForMaintenance()) {
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale'));
event(new ConfigureMiddleware($pipe, $path, $this));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')]));
$pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode()));
} else {
$pipe->pipe($path, function () use($errorDir) {
return new HtmlResponse(file_get_contents($errorDir . '/503.html', 503));
});
}
return $pipe;
}
示例4: play
/**
* Increase a song's play count as the currently authenticated user.
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function play(Request $request)
{
if ($interaction = Interaction::increasePlayCount($request->input('song'), $request->user())) {
event(new SongStartedPlaying($interaction->song, $interaction->user));
}
return response()->json($interaction);
}
示例5: handle
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// Delete the post from database
$this->post->delete();
// Fire Event and Listeners
event(new DeletedPost($this->post));
}
示例6: boot
public static function boot()
{
parent::boot();
static::created(function (EventLog $eventLog) {
event(new NewEventLog($eventLog));
});
}
示例7: register
/**
* @param $user_firstname
* @param $user_lastname
* @param $email
* @param $password
* @param $user_phone
* @return static
*/
public static function register($user_firstname, $user_lastname, $email, $password, $user_phone)
{
$user = new static(compact('user_firstname', 'user_lastname', 'email', 'password', 'user_phone'));
// $user = Event::fire(new UserRegistred($user));
event(new UserHasRegistred($user, $password));
return $user;
}
示例8: boot
/**
* Override the boot method to bind model event listeners.
*
* @return void
*/
public static function boot()
{
parent::boot();
static::saved(function (Deployment $model) {
event(new ModelChanged($model, 'deployment'));
});
}
示例9: handle
/**
* Execute the job.
*
* @param \Illuminate\Http\Request $request
* @return \Apolune\Contracts\Account\Account|null
*/
public function handle(Request $request)
{
$this->account->password = bcrypt($request->get('password'));
$this->account->save();
event(new ChangedPassword($this->account));
return $this->account;
}
示例10: register
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user) ?: redirect($this->redirectPath());
}
示例11: handle
/**
* Perform authentication before a request is executed.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $grant
*
* @return mixed
* @throws AccessDeniedException
*/
public function handle($request, Closure $next, $grant = null)
{
$route = $this->router->getCurrentRoute();
/**
* FOR (Internal API requests)
* @note GRANT(user) will always be able to access routes that are protected by: GRANT(client)
*
* For OAuth grants from password (i.e. Resource Owner: user)
* @Auth will only check once, because user exists in auth afterwards
*
* For OAuth grants from client_credentials (i.e. Resource Owner: client)
* @Auth will always check, because user is never exists in auth
*/
if (!$this->auth->check(false)) {
$this->auth->authenticate($route->getAuthenticationProviders());
$provider = $this->auth->getProviderUsed();
/** @var OAuth2 $provider */
if ($provider instanceof OAuth2) {
// check oauth grant type
if (!is_null($grant) && $provider->getResourceOwnerType() !== $grant) {
throw new AccessDeniedException();
}
}
// login user through Auth
$user = $this->auth->getUser();
if ($user instanceof User) {
\Auth::login($user);
event(new UserLoggedInEvent($user));
}
}
return $next($request);
}
示例12: save
public static function save($data)
{
$code = (new Parcels())->getNextCode();
$description = $data[0];
event(new ActivityLog(auth()->user()->username . ' created a parcel ' . $description . ' with the code ' . $code . ' successfully via CSV Upload.'));
return auth()->user()->parcels()->create(['weight' => 1, 'town_id' => 1, 'status_id' => 1, 'description' => $description, 'code' => $code, 'destination' => $data[1]]);
}
示例13: handle
/**
* Handle the subscribe customer command.
*
* @param \CachetHQ\Cachet\Commands\Subscriber\VerifySubscriberCommand $command
*
* @return void
*/
public function handle(VerifySubscriberCommand $command)
{
$subscriber = $command->subscriber;
$subscriber->verified_at = Carbon::now();
$subscriber->save();
event(new SubscriberHasVerifiedEvent($subscriber));
}
示例14: handle
/**
* @param UploadAvatar $command
* @return \Flarum\Core\Users\User
* @throws \Flarum\Core\Exceptions\PermissionDeniedException
*/
public function handle(UploadAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
// Make sure the current user is allowed to edit the user profile.
// This will let admins and the user themselves pass through, and
// throw an exception otherwise.
if ($actor->id !== $user->id) {
$user->assertCan($actor, 'edit');
}
$tmpFile = tempnam(sys_get_temp_dir(), 'avatar');
$command->file->moveTo($tmpFile);
$manager = new ImageManager();
$manager->make($tmpFile)->fit(100, 100)->save();
event(new AvatarWillBeSaved($user, $actor, $tmpFile));
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
$mount->delete($file);
}
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$user->changeAvatarPath($uploadName);
$mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$user->save();
$this->dispatchEventsFor($user);
return $user;
}
示例15: getMiddleware
/**
* {@inheritdoc}
*/
protected function getMiddleware(Application $app)
{
$pipe = new MiddlewarePipe();
$path = config('hyn.laravel-flarum.paths.api');
// if ($app->isInstalled() && $app->isUpToDate()) {
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
$pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\FakeHttpMethods'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithHeader'));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale'));
event(new ConfigureMiddleware($pipe, $path, $this));
$pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
$pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\HandleErrors'));
// } else {
// $pipe->pipe($path, function () {
// $document = new Document;
// $document->setErrors([
// [
// 'code' => 503,
// 'title' => 'Service Unavailable'
// ]
// ]);
//
// return new JsonApiResponse($document, 503);
// });
// }
return $pipe;
}