Example #1
0
 /**
  * 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());
 }
 /**
  * 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);
 }
Example #3
0
 public function __construct($options = [], Application $app = null, RepositoryContract $config = null, Dispatcher $dispatcher = null)
 {
     static::$options = $config !== null ? array_merge($options, $config->get('tracy')) : $options;
     TracyDebugger::$time = array_get($_SERVER, 'REQUEST_TIME_FLOAT', microtime(true));
     TracyDebugger::$maxDepth = array_get(static::$options, 'maxDepth');
     TracyDebugger::$maxLen = array_get(static::$options, 'maxLen');
     TracyDebugger::$showLocation = array_get(static::$options, 'showLocation');
     TracyDebugger::$strictMode = array_get(static::$options, 'strictMode');
     TracyDebugger::$editor = array_get(static::$options, 'editor');
     $bar = TracyDebugger::getBar();
     foreach (array_get(static::$options, 'panels') as $key => $enabled) {
         if ($enabled === true) {
             $class = '\\' . __NAMESPACE__ . '\\Panels\\' . ucfirst($key) . 'Panel';
             if (class_exists($class) === false) {
                 $class = $key;
             }
             $this->panels[$key] = new $class($app, static::$options);
             $bar->addPanel($this->panels[$key], $class);
         }
     }
     if ($dispatcher !== null) {
         $dispatcher->listen('kernel.handled', function ($request, $response) {
             return static::appendDebugbar($request, $response);
         });
     } else {
         TracyDebugger::enable();
     }
 }
 /**
  * リマインダー通知ビジネスロジック
  *
  * @param string $message
  */
 public function run($message)
 {
     // イベントにメッセージを設定
     $this->event->message = $message;
     // イベント発行
     $this->dispacher->fire($this->event);
 }
 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);
 }
 public function subscribe(Dispatcher $events)
 {
     $events->listen(RegisterPostTypes::class, [$this, 'registerPostType']);
     $events->listen(RegisterNotificationTypes::class, [$this, 'registerNotificationType']);
     $events->listen(DiscussionWasStickied::class, [$this, 'whenDiscussionWasStickied']);
     $events->listen(DiscussionWasUnstickied::class, [$this, 'whenDiscussionWasUnstickied']);
 }
 /**
  * Register the listeners for the subscriber.
  *
  * @param \Illuminate\Contracts\Events\Dispatcher $events
  */
 public function subscribe(Dispatcher $events)
 {
     $events->listen('Flarum\\Core\\Events\\PostWasPosted', __CLASS__ . '@whenPostWasPosted');
     $events->listen('Flarum\\Core\\Events\\PostWasDeleted', __CLASS__ . '@whenPostWasDeleted');
     $events->listen('Flarum\\Core\\Events\\PostWasHidden', __CLASS__ . '@whenPostWasHidden');
     $events->listen('Flarum\\Core\\Events\\PostWasRestored', __CLASS__ . '@whenPostWasRestored');
 }
 public static function registerMenu(Dispatcher $events, Repository $config)
 {
     $events->listen(BuildingMenu::class, function (BuildingMenu $event) use($config) {
         $menu = $config->get('adminlte.menu');
         call_user_func_array([$event->menu, 'add'], $menu);
     });
 }
 /**
  * @param Dispatcher $events
  */
 public function subscribe(Dispatcher $events)
 {
     $events->listen(ConfigurePostTypes::class, [$this, 'addPostType']);
     $events->listen(ConfigureNotificationTypes::class, [$this, 'addNotificationType']);
     $events->listen(DiscussionWasLocked::class, [$this, 'whenDiscussionWasLocked']);
     $events->listen(DiscussionWasUnlocked::class, [$this, 'whenDiscussionWasUnlocked']);
 }
 /**
  * Execute the command.
  *
  * @param Filesystem $fileSystem
  * @param Application $app
  * @param TranslationRepositoryInterface $repository
  * @param Dispatcher $event
  * @return Collection of Group
  */
 public function handle(Filesystem $fileSystem, Application $app, TranslationRepositoryInterface $repository, Dispatcher $event)
 {
     $files = $fileSystem->allFiles($app->langPath());
     /**
      * Retrieves all local languages
      */
     $languages = collect($files)->transform(function ($file) {
         return $file->getRelativePath();
     })->unique();
     /**
      * Save Database instance with all languages
      */
     $database = $repository->languages();
     /**
      * List Only names
      */
     $names = $database->pluck('name');
     /**
      * Create New Language for those which has been set locally
      * but was not present yet on the database
      */
     $newLanguages = $languages->merge($names)->diff($names)->map(function ($name) {
         return $this->dispatch(new CreateLanguageCommand($name));
     });
     /**
      * Announce LanguagesWasCreated
      */
     if (!$newLanguages->isEmpty()) {
         $event->fire(new LanguagesWasCreated($newLanguages));
     }
     /**
      * Returns All languages
      */
     return $database->merge($newLanguages);
 }
 /**
  * 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;
 }
 /**
  * @param Dispatcher $events
  */
 public function subscribe(Dispatcher $events)
 {
     $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']);
     $events->listen(GetApiRelationship::class, [$this, 'getApiRelationship']);
     $events->listen(ConfigureApiController::class, [$this, 'includeRelationships']);
     $events->listen(PrepareApiData::class, [$this, 'filterVisiblePosts']);
 }
 /**
  * @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);
 }
Example #14
0
 function it_can_raise_events(Dispatcher $dispatcher)
 {
     $this->beAnInstanceOf('spec\\FluxBB\\Core\\EventAction');
     $dispatcher->fire('stdClass', [new \stdClass()])->shouldBeCalled();
     $this->setEvents($dispatcher);
     $this->execute();
 }
Example #15
0
 /**
  * @param Dispatcher $events
  */
 public function subscribe(Dispatcher $events)
 {
     $events->listen(GetApiRelationship::class, [$this, 'getApiRelationship']);
     $events->listen(PrepareApiData::class, [$this, 'loadTagsRelationship']);
     $events->listen(ConfigureApiController::class, [$this, 'includeTagsRelationship']);
     $events->listen(PrepareApiAttributes::class, [$this, 'prepareApiAttributes']);
 }
Example #16
0
 /**
  * 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);
 }
Example #17
0
 /**
  * @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);
 }
Example #18
0
 /**
  * Handle the command.
  *
  * @param Dispatcher $events
  */
 public function handle(Dispatcher $events)
 {
     $this->builder->fire('posting', ['builder' => $this->builder]);
     $this->builder->fireFieldEvents('form_posting');
     $this->dispatch(new LoadFormValues($this->builder));
     /**
      * Multiple form builders do not get
      * validated here.. in fact:
      *
      * @todo: Decouple validation into it's own method like multiple form builders
      */
     if (!$this->builder instanceof MultipleFormBuilder) {
         $this->dispatch(new ValidateForm($this->builder));
     }
     $this->dispatch(new RemoveSkippedFields($this->builder));
     $this->dispatch(new HandleForm($this->builder));
     $this->dispatch(new SetSuccessMessage($this->builder));
     $this->dispatch(new SetActionResponse($this->builder));
     if ($this->builder->isAjax()) {
         $this->dispatch(new SetJsonResponse($this->builder));
     }
     $this->builder->fire('posted', ['builder' => $this->builder]);
     $this->builder->fireFieldEvents('form_posted');
     $events->fire(new FormWasPosted($this->builder));
 }
 /**
  * setting up listener
  *
  * @param Dispatcher $events
  * @param Writer $log
  */
 private function setupListener(Dispatcher $events, Writer $log)
 {
     $environments = config('slow-query-logger.environments', []);
     if (!$this->app->environment($environments)) {
         return;
     }
     $events->listen(QueryExecuted::class, function (QueryExecuted $queryExecuted) use($log) {
         $sql = $queryExecuted->sql;
         $bindings = $queryExecuted->bindings;
         $time = $queryExecuted->time;
         $logSqlQueriesSlowerThan = config('slow-query-logger.time-to-log');
         if ($logSqlQueriesSlowerThan < 0 || $time < $logSqlQueriesSlowerThan) {
             return;
         }
         $level = config('slow-query-logger.log-level', 'debug');
         try {
             foreach ($bindings as $val) {
                 $sql = preg_replace('/\\?/', "'{$val}'", $sql, 1);
             }
             $log->log($level, $time . '  ' . $sql);
         } catch (\Exception $e) {
             //  be quiet on error
         }
     });
 }
 /**
  * @param Factory $validator
  * @param Dispatcher $dispatcher
  * @param ContentType $contentType
  * @param ContentTypeFormGroup $contentTypeFormGroup
  * @return CommandResult
  */
 public function handle(Factory $validator, Dispatcher $dispatcher, ContentType $contentType, ContentTypeFormGroup $contentTypeFormGroup)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['contentBuilder.manage'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     // validate data
     $validationResult = $validator->make(array('name' => $this->name, 'form_name' => $this->formName, 'fields' => $this->fields, 'content_type_id' => $this->contentTypeId), ContentTypeFormGroup::$rules);
     if ($validationResult->fails()) {
         return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400);
     }
     // fire event creating
     $dispatcher->fire('formGroup.creating', array($this->args));
     // begin create
     if (!($cType = $contentType->find($this->contentTypeId))) {
         return new CommandResult(false, "Content Type Not Found.", null, 400);
     }
     $createdFormGroup = $cType->formGroups()->create(array('name' => $this->name, 'form_name' => $this->formName, 'conditions' => $this->conditions, 'fields' => $this->fields, 'content_type_id' => $this->contentTypeId));
     // fire event creating
     $dispatcher->fire('formGroup.created', array($createdFormGroup));
     // all good
     return new CommandResult(true, "Form group successfully created.", $createdFormGroup, 201);
 }
Example #21
0
 /**
  * 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);
 }
Example #22
0
 /**
  * {@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);
 }
Example #23
0
 /**
  * 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]));
     }
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * @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);
 }
 /**
  * @param Dispatcher $events
  */
 public function subscribe(Dispatcher $events)
 {
     $events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted']);
     $events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
     $events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']);
     $events->listen(PostWasRestored::class, [$this, 'whenPostWasRestored']);
 }
 /**
  * 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]];
 }
Example #29
0
 /**
  * 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;
 }
Example #30
0
 /**
  * Register the listeners for the subscriber.
  *
  * @param  Dispatcher $events
  *
  * @return array
  */
 public function subscribe($events)
 {
     $events->listen(ServicePreProcess::class, static::class . '@onServicePreProcess');
     $events->listen(ServicePostProcess::class, static::class . '@onServicePostProcess');
     $events->listen(ResourcePreProcess::class, static::class . '@onResourcePreProcess');
     $events->listen(ResourcePostProcess::class, static::class . '@onResourcePostProcess');
 }