-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rid of event subscribers that resolve services too early, part 1
Refs flarum/core#1578.
- Loading branch information
1 parent
e2b0087
commit 73c0626
Showing
4 changed files
with
49 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <toby.zerner@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Tags\Listener; | ||
|
||
use Flarum\Api\Event\Serializing; | ||
use Flarum\Api\Serializer\ForumSerializer; | ||
use Flarum\Settings\SettingsRepositoryInterface; | ||
|
||
class PrepareForumTagsApiAttributes | ||
{ | ||
/** | ||
* @var SettingsRepositoryInterface | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @param SettingsRepositoryInterface $settings | ||
*/ | ||
public function __construct(SettingsRepositoryInterface $settings) | ||
{ | ||
$this->settings = $settings; | ||
} | ||
|
||
public function handle(Serializing $event) | ||
{ | ||
if ($event->isSerializer(ForumSerializer::class)) { | ||
$event->attributes['minPrimaryTags'] = $this->settings->get('flarum-tags.min_primary_tags'); | ||
$event->attributes['maxPrimaryTags'] = $this->settings->get('flarum-tags.max_primary_tags'); | ||
$event->attributes['minSecondaryTags'] = $this->settings->get('flarum-tags.min_secondary_tags'); | ||
$event->attributes['maxSecondaryTags'] = $this->settings->get('flarum-tags.max_secondary_tags'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73c0626
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this might be an inspiration for a more definite extender for
listen
@franzliedke :73c0626
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned elsewhere, I'd like to avoid such an extender. We'll have dedicated extenders for some specific domain events (such as "post was posted" or "post was hidden"), but apart from those, events are internal, private API. Exposing this extender would just encourage using the private API.
Implementing custom extenders is still possible, but they won't be guaranteed to work across minor / patch releases, if they're using "private" API.
73c0626
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha 👍