本文整理汇总了PHP中Illuminate\Contracts\Events\Dispatcher类的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher类的具体用法?PHP Dispatcher怎么用?PHP Dispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* 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);
}
示例2: __construct
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();
}
}
示例3: handle
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);
}
示例4: subscribe
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']);
}
示例5: subscribe
/**
* 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');
}
示例6: registerMenu
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);
});
}
示例7: subscribe
/**
* @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']);
}
示例8: handle
/**
* 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);
}
示例9: subscribe
/**
* @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']);
}
示例10: handle
/**
* @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);
}
示例11:
function it_can_raise_events(Dispatcher $dispatcher)
{
$this->beAnInstanceOf('spec\\FluxBB\\Core\\EventAction');
$dispatcher->fire('stdClass', [new \stdClass()])->shouldBeCalled();
$this->setEvents($dispatcher);
$this->execute();
}
示例12: subscribe
/**
* @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']);
}
示例13: handle
/**
* 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));
}
示例14: setupListener
/**
* 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
}
});
}
示例15: handle
/**
* @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);
}