/** * Execute the console command. * * @return mixed */ public function handle() { foreach ($this->permissionsToRegister() as $name => $description) { $this->permissionRepository->firstOrRegister(['name' => $name], ['description' => $description]); } $this->events->fire(new PermissionsModified()); }
/** * Dispatch all events for an entity. * * @param object $entity * @param User $actor */ public function dispatchEventsFor($entity, User $actor = null) { foreach ($entity->releaseEvents() as $event) { $event->actor = $actor; $this->events->fire($event); } }
/** * handle group creation logic * * @param Validator $validator * @param Dispatcher $dispatcher * @param Group $group * @return CommandResult */ public function handle(Validator $validator, Dispatcher $dispatcher, Group $group) { // check user permission if (!$this->disablePermissionChecking) { if (!$this->user->hasAnyPermission(['user.manage'])) { return new CommandResult(false, CommandResult::$responseForbiddenMessage, null, 403); } } // validate data $validationResult = $validator->make(array('name' => $this->name, 'permissions' => $this->permissions), Group::$rules); if ($validationResult->fails()) { return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400); } // prepare data to be store $groupToBeCreated = array('name' => $this->name, 'permissions' => $this->transform($this->permissions)); // fire creating $dispatcher->fire('group.creating', array($groupToBeCreated)); // create $createdGroup = $group->create($groupToBeCreated); if (!$createdGroup) { return new CommandResult(false, "Failed to create user.", null, 400); } // fire created user $dispatcher->fire('group.created', array($createdGroup)); // return response return new CommandResult(true, "Group successfully created.", $createdGroup, 201); }
/** * Make a new validator instance for this model. * * @param array $attributes * @return \Illuminate\Validation\Validator */ protected function makeValidator(array $attributes) { $rules = array_only($this->getRules(), array_keys($attributes)); $validator = $this->validator->make($attributes, $rules, $this->getMessages()); $this->events->fire(new ConfigureValidator($this, $validator)); return $validator; }
/** * handle user deletion logic * * @param User $user * @param Group $group * @param Dispatcher $dispatcher * @param Repository $config * @return CommandResult */ public function handle(User $user, Group $group, Dispatcher $dispatcher, Repository $config) { // check user permission if (!$this->disablePermissionChecking) { if (!$this->user->hasAnyPermission(['user.delete'])) { return new CommandResult(false, CommandResult::$responseForbiddenMessage, null, 403); } if ($this->user->id == $this->id) { return new CommandResult(false, "Cannot delete self.", null, 400); } } // prepare the user model $user = $this->createUserModel($user, $config); // find the user if (!($userToBeDelete = $user->find($this->id))) { return new CommandResult(false, "User not found.", null, 404); } // fire deleting $dispatcher->fire('user.deleting', array($this->args)); // begin deletion $userToBeDelete->groups()->detach(); $userToBeDelete->delete(); // fire deleted $dispatcher->fire('user.deleted', array($userToBeDelete)); // all good return new CommandResult(true, "User successfully deleted.", null, 200); }
/** * Execute the console command. * * @return void */ public function handle() { $this->events->fire('command.publishvendors', $this); $this->events->fire('command.runmigrations', $this); $this->events->fire('command.updatecache', $this); $this->events->fire('command.extrastuff', $this); }
/** * Handle the command. * * @param CreateIncomeServiceCommand $command * @return void */ public function handle(CreateIncomeServiceCommand $command) { $input = ['service_id' => $command->serviceId, 'service_date' => $command->serviceDate, 'created_by' => $command->userId, 'role_access' => $command->roleAccess, 'status' => $command->status]; $incomeService = $this->incomeService->save($input); $this->dispatcher->fire(new IncomeServiceWasCreated($incomeService->id)); return $incomeService; }
/** * Execute the command. * * @param ContentType $contentType * @param Validator $validator * @param Dispatcher $dispatcher * @return CommandResult */ public function handle(ContentType $contentType, Validator $validator, Dispatcher $dispatcher) { // validate authorization if (!$this->disablePermissionChecking) { if (!$this->user->hasAnyPermission(['contentBuilder.manage'])) { return new CommandResult(false, CommandResult::$responseForbiddenMessage, null, 403); } } // validate data $validationResult = $validator->make(array('taxonomy' => $this->taxonomy, 'content_type_id' => $this->contentTypeId), ContentTypeTaxonomy::$rules); if ($validationResult->fails()) { return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400); } // prepare the data to be stored $taxonomyToBeCreated = array('taxonomy' => $this->taxonomy, 'description' => $this->description); // fire creating event $dispatcher->fire('contentTypeTaxonomy.creating', array($taxonomyToBeCreated)); // store try { $contentType = $contentType->findOrFail($this->contentTypeId); $createdContentTypeTaxonomy = $contentType->taxonomies()->create($taxonomyToBeCreated); } catch (\Exception $e) { return new CommandResult(false, "Invalid Content Type.", null, 400); } // fire creating event $dispatcher->fire('contentTypeTaxonomy.created', array($createdContentTypeTaxonomy)); // return return new CommandResult(true, "Content type taxonomy successfully created.", $createdContentTypeTaxonomy, 201); }
public function handle(Navigation $navigation, Factory $validator, Dispatcher $dispatcher) { // check if user has permission if (!$this->disablePermissionChecking) { if (!$this->user->hasAnyPermission(['navigationBuilder.manage'])) { return new CommandResult(false, "Not enough permission.", null, 403); } } // validate data $validationResult = $validator->make(array('name' => $this->name, 'data' => $this->data), Navigation::$rules); if ($validationResult->fails()) { return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400); } if (!($nav = $navigation->find($this->id))) { return new CommandResult(false, 'Navigation does not exist.', null, 400); } // fire before create event $dispatcher->fire('navigationBuilder.updating', array($nav, $this->args)); $nav->name = $this->name; $nav->data = $this->data; $nav->save(); // fire after create $dispatcher->fire('navigationBuilder.updated', array($nav, $this->args)); // all good return new CommandResult(true, "Navigation successfully updated.", $nav, 200); }
/** * {@inheritdoc} */ public function render(Request $request) { $view = $this->getView($request); $this->events->fire(new ConfigureClientView($this, $view, $request)); $this->events->fire(new ConfigureWebApp($this, $view, $request)); return $view->render($request); }
/** * リマインダー通知ビジネスロジック * * @param string $message */ public function run($message) { // イベントにメッセージを設定 $this->event->message = $message; // イベント発行 $this->dispacher->fire($this->event); }
/** * @param Navigation $navigation * @param Dispatcher $dispatcher * @return CommandResult */ public function handle(Navigation $navigation, Dispatcher $dispatcher) { // check if user has permission if (!$this->disablePermissionChecking) { if (!$this->user->hasAnyPermission(['navigationBuilder.manage'])) { return new CommandResult(false, "Not enough permission.", null, 403); } } // fire before create event $dispatcher->fire('navigationBuilder.beforeQuery', array($this->args)); if ($this->id && $this->id != '') { if (!($res = $navigation->with(array())->find($this->id))) { return new CommandResult(false, "Navigation does not exist.", null, 404); } } else { if ($this->paginated) { $res = $navigation->with(array())->paginate($this->perPage); } else { $res = $navigation->all(); } } // fire after create $dispatcher->fire('navigationBuilder.afterQuery', array($this->args)); // all good return new CommandResult(true, "List custom navigation command successful.", $res, 200); }
/** * Handle the command. * * @param DeleteIncomeServiceMemberFundTotal $command * @return void */ public function handle(DeleteIncomeServiceMemberFundTotal $command) { $memberFund = $this->memberFund->getByIdAndMemberId($command->incomeServiceId, $command->memberId); $this->memberFund->deleteTotal($memberFund->id); $incomeService = $this->dispatcher->fire(new IncomeServiceMemberFundTotalWasDeleted($command->incomeServiceId, $command->memberId, $memberFund->tithes, $memberFund->offering, $memberFund->others, $memberFund->total)); return ['memberFundTotal' => $memberFund, 'fundTotal' => $incomeService[1]]; }
/** * Fire off an event. * * @param string $name * @param mixed $payload * @return mixed */ protected function fireEvent($name, $payload = null) { if (!isset(static::$dispatcher)) { $this->initEventDispatcher(); } static::$dispatcher->fire($name, $payload); }
/** * @param CouchbaseViewQuery $viewQuery * @param bool $jsonAsArray * * @return mixed */ public function execute(CouchbaseViewQuery $viewQuery, $jsonAsArray = false) { if (isset($this->dispatcher)) { $this->dispatcher->fire(new ViewQuerying($viewQuery)); } return $this->bucket->query($viewQuery, $jsonAsArray); }
/** * Fire an event for this cache instance. * * @param string $event * @param array $payload * @return void */ protected function fireCacheEvent($event, $payload) { if (!isset($this->events)) { return; } switch ($event) { case 'hit': if (count($payload) == 2) { $payload[] = []; } return $this->events->fire(new Events\CacheHit($payload[0], $payload[1], $payload[2])); case 'missed': if (count($payload) == 1) { $payload[] = []; } return $this->events->fire(new Events\CacheMissed($payload[0], $payload[1])); case 'delete': if (count($payload) == 1) { $payload[] = []; } return $this->events->fire(new Events\KeyForgotten($payload[0], $payload[1])); case 'write': if (count($payload) == 3) { $payload[] = []; } return $this->events->fire(new Events\KeyWritten($payload[0], $payload[1], $payload[2], $payload[3])); } }
/** * @param ContentType $contentType * @param Dispatcher $dispatcher * @return CommandResult */ public function handle(ContentType $contentType, Dispatcher $dispatcher) { // begin before query $dispatcher->fire('contentType.beforeQuery', array($this->args)); // check if has permission if (!$this->disablePermissionChecking) { // if $type->type is not provided, the request referrer should be from // the admin UI Content Type Builder component. // so we will check if the user has permission (contentBuilder.manage) // on the other hand, // if $type->type is provided, we will check if user has permission to manage that type if (!is_null($this->type) && $this->type != '') { if (!$this->user->hasAnyPermission([$this->type . '.manage'])) { return new CommandResult(false, "Not enough permission.", null, 403); } } else { if (!$this->user->hasAnyPermission(['contentBuilder.manage'])) { return new CommandResult(false, "Not enough permission.", null, 403); } } } // begin query $results = $contentType->with(array('terms.taxonomy', 'taxonomies', 'taxonomies.terms', 'formGroups'))->ofType($this->type)->get(); // begin after query $dispatcher->fire('contentType.afterQuery', array($this->args)); // all good return new CommandResult(true, "Query content types successful.", $results, 200); }
/** * Log a query in the connection's query log. * * @param string $query * @param float|null $time * * @return void */ public function logQuery($query, $time = null) { if (isset($this->events)) { $this->events->fire('osm.query', [$query, $time]); } parent::logQuery($query, $time); }
/** * @param $method * @param $args * @return mixed */ public function __call($method, $args) { //Execute the command from client $result = call_user_func_array([$this->client, $method], $args); //Fire event $this->event->fire(new RedisCommandWasExecuted($method, $args)); return $result; }
/** * Handle the command. * * @param CreateMemberCommand $command * @return void */ public function handle(CreateMemberCommand $command) { $member = $this->member->create($command->member); if ($member) { $this->dispatcher->fire(new MemberWasCreated($member->id, $member->firstname, $member->lastname)); } return $member; }
/** * @param User $actor * @param Builder $query */ public function find(User $actor, Builder $query) { if (!$actor->hasPermission('discussion.hide')) { $query->where(function ($query) use($actor) { $query->whereNull('discussions.hide_time')->where('comments_count', '>', 0)->orWhere('start_user_id', $actor->id); $this->events->fire(new ScopeHiddenDiscussionVisibility($query, $actor, 'discussion.hide')); }); } }
/** * @param DeleteModeratorNotes $command * * @return ModeratorNotes */ public function handle(DeleteModeratorNotes $command) { $actor = $command->actor; $post = $this->posts->findOrFail($command->postId, $actor); $this->assertCan($actor, 'viewModeratorNotes', $post->discussion); $this->events->fire(new ModeratorNotesWillBeDeleted($post, $actor, $command->data)); $post->moderatorNotes()->delete(); return $post; }
/** * Execute the job. */ public function handle() { $job = new \App\Job(); $job->title = $this->title; $job->description = $this->description; $job->save(); $this->event->fire(new JobWasPostedEvent()); return $this; }
/** * Fire an event here as we enter the middleware * layer of the application so we can hook into it. * * @param Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) { $response = $this->events->fire(new ApplicationHasLoaded(), [], true); define('IS_ADMIN', $request->segment(1) == 'admin'); if ($response instanceof Response) { return $response; } return $next($request); }
/** * {@inheritdoc} */ public function getAttributes($model, array $fields = null) { if (!is_object($model) && !is_array($model)) { return []; } $attributes = $this->getDefaultAttributes($model); static::$dispatcher->fire(new PrepareApiAttributes($this, $model, $attributes)); return $attributes; }
/** * @param Basket $basket * @param Settlement $settlement * * @throws \Exception * * @return \ChingShop\Modules\Sales\Domain\Order\Order */ public function settle(Basket $basket, Settlement $settlement) : Order { $order = $this->basketToOrder($basket); $payment = $this->paymentForSettlement($settlement); $order->payment()->save($payment); $basket->offers()->collection()->each(function (PotentialOffer $offer) use($order) { $order->orderOffers()->save(OrderOffer::makeFrom($order, $offer)); }); $this->dispatcher->fire(new NewOrderEvent($order)); return $order; }
/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $this->assertAdmin($request->getAttribute('actor')); $settings = $request->getParsedBody(); foreach ($settings as $k => $v) { $this->dispatcher->fire(new PrepareSerializedSetting($k, $v)); $this->settings->set($k, $v); $this->dispatcher->fire(new SettingWasSet($k, $v)); } return new EmptyResponse(204); }
public function run() { // 前回のデータを取得 $oldCards = $this->converter->convert($this->reader->read(storage_path() . $this->lastDataFile, '[]')); if (is_null($oldCards)) { return false; } // URL生成 $url = 'https://trello.com/1/lists/' . env('TRELLO_LIST_ID') . '/cards' . '?key=' . env('TRELLO_KEY') . '&token=' . env('TRELLO_TOKEN'); // Trelloよりカード情報取得 if (false === ($json = $this->getter->get($url))) { return false; } // 取得したカード情報(JSON形式)を配列へ変換 if (is_null($cards = $this->converter->convert($json))) { return false; } $created = new CardCreated(); $updated = new CardUpdated(); $currentCards = []; foreach ($cards as $card) { // 保存用データ作成 $id = $card['id']; // 日本時間で保存したほうが分かりやすい $carbonTime = (new Carbon($card['dateLastActivity']))->timezone('Asia/Tokyo'); $timeString = $carbonTime->toDateTimeString(); $currentCards[$id] = $timeString; // 直前のデーターに存在していなければ新規カード if (!array_key_exists($id, $oldCards)) { $created->id = $id; $created->name = $card['name']; $created->time = $carbonTime; $this->dispatcher->fire($created); continue; } // IDが一致するのに最終更新時間が異なっていれば更新 if ($timeString !== $oldCards[$id]) { $updated->id = $id; $updated->name = $card['name']; $updated->time = $carbonTime; $this->dispatcher->fire($updated); } } $deleted = new CardDeleted(); // 削除されたカードを選択 $deletedCards = array_diff_key($oldCards, $currentCards); foreach ($deletedCards as $deletedId => $time) { $deleted->id = $deletedId; $this->dispatcher->fire($deleted); } // 今回の取得データをファイルへ保存 $this->file->put(storage_path() . $this->lastDataFile, json_encode($currentCards)); return true; }
/** * Override give config values from persistent setting storage. * * @param array $override * @param \Illuminate\Contracts\Config\Repository $config * @param \Krucas\Settings\Settings $settings * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher */ protected function overrideConfig(array $override, Repository $config, Settings $settings, Dispatcher $dispatcher) { foreach ($override as $key => $settingKey) { $configKey = is_string($key) ? $key : $settingKey; $dispatcher->fire("settings.overriding: {$configKey}", [$configKey, $settingKey]); $settingValue = $settings->get($settingKey); $configValue = $config->get($configKey); $config->set($configKey, $settingValue); $dispatcher->fire("settings.override: {$configKey}", [$configKey, $configValue, $settingKey, $settingValue]); } }
/** * @param Request $request * @param array $routeParams * @return \Psr\Http\Message\ResponseInterface */ public function handle(Request $request, array $routeParams = []) { $user = $request->getAttribute('actor'); if ($user->exists) { $token = array_get($request->getQueryParams(), 'token'); AccessToken::where('user_id', $user->id)->findOrFail($token); $user->accessTokens()->delete(); $this->events->fire(new UserLoggedOut($user)); } return $this->withForgetCookie(new RedirectResponse($this->app->url())); }