Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Model extender, integration tests #2100

Merged
merged 13 commits into from
Apr 24, 2020

Conversation

askvortsov1
Copy link
Sponsor Member

@askvortsov1 askvortsov1 commented Mar 29, 2020

Fixes part of #1891

Changes proposed in this pull request:

  • Add Model extender with relationship method (decided not to go with one method-per-relationship as this is simpler, more flexible, and easier to operate). Also added configureDates and configureDefaultAttributes methods, which also take callables.
  • Deprecated GetModelRelationship, ConfigureModelDefaultAttributes, ConfigureModelDates events
  • Added integration tests for model relationship extender

Reviewers should focus on:
Anything I'm missing?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

@franzliedke franzliedke mentioned this pull request Apr 13, 2020
78 tasks
tests/integration/extenders/ModelTest.php Show resolved Hide resolved
tests/integration/extenders/ModelTest.php Outdated Show resolved Hide resolved
tests/integration/extenders/ModelTest.php Outdated Show resolved Hide resolved
Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, finally had time to give this some thought. I noted down my personal preferences, but would like to hear thoughts from other team members first...

src/Extend/Model.php Outdated Show resolved Hide resolved
src/Extend/Model.php Outdated Show resolved Hide resolved
src/Extend/Model.php Outdated Show resolved Hide resolved
src/Database/DatabaseServiceProvider.php Outdated Show resolved Hide resolved
src/Database/DatabaseServiceProvider.php Outdated Show resolved Hide resolved
src/Extend/Model.php Show resolved Hide resolved
@clarkwinkelmann clarkwinkelmann self-requested a review April 21, 2020 20:40
@askvortsov1
Copy link
Sponsor Member Author

For the Default Attributes one, do we want to allow extension developers to use stuff like settings there? We could pass a predetermined number of things (translator, settings, URL Generator), and have them use those for the default attributes.

@franzliedke
Copy link
Contributor

Not for now, I'd say. We can consider that when the use-case pops up. Until then it feels just like wild guessing. 😉


return $dates[$class];
return array_merge($this->dates, Arr::get(static::$dateAttributes, static::class, []));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the cache semantics of the previous implementation - so that the event dispatch and the array merge only happens once per class per request?

(Not sure how often this is called internally... it might not be relevant any longer when the event dispatching is gone.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take care of this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Played around with it. Static caching would cause problems in tests (uh oh), and I'm not too worried about it once the event dispatching is gone, so I'm leaving this as is.

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job. thanks a lot!!!

@franzliedke franzliedke merged commit 15bed97 into flarum:master Apr 24, 2020
franzliedke added a commit that referenced this pull request Apr 24, 2020
- Remove unused private attributes
- Complete docblocks
- Add scalar type hints
- Format code
- Reorder methods

Refs #2100.
franzliedke added a commit that referenced this pull request Apr 24, 2020
- Format code
- Reorder methods
- Test a different scenario to avoid the use of sleep()

Refs #2100.
franzliedke added a commit that referenced this pull request Apr 24, 2020
franzliedke added a commit that referenced this pull request Apr 24, 2020
We determined that child classes are not properly affected when
extending the parent classes.

Refs #2100.
@clarkwinkelmann
Copy link
Member

I'm only catching up now with those features.

I understand you added a way to specify new date attributes on the model, but not casts ? I'm pretty sure casts would be useful. Should we make an issue for that ?

@askvortsov1
Copy link
Sponsor Member Author

The goal here is to move to the extenders as public API (no functionality was changed), but I agree that would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants