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

ApiController Extender #2451

Merged
merged 17 commits into from
Dec 6, 2020

Conversation

SychO9
Copy link
Member

@SychO9 SychO9 commented Nov 12, 2020

Part B of #1624
Part of #1891

Changes proposed in this pull request:

  • Deprecate WillGetData Event.
  • Deprecate WillSerializeData Event.
  • Add extenders to replace both events above.

Reviewers should focus on:

  • I had to move all the methods in WillGetData to the AbstractSerializeController, the signature for those methods are somewhat incomplete, some could use proper type hinting while other could explicitly support mixed parameter types of string|array do we want to do that ?
  • Do we want to add to the extender convenience methods, similar to the ones present in the WillGetData event for adding/removing includes ...etc ?

Confirmed

  • Backend changes: tests are green (run composer test).

@SychO9 SychO9 changed the title ApiController Extender WIP: ApiController Extender Nov 12, 2020
@SychO9 SychO9 force-pushed the sm/1624-api-controller-extender branch 2 times, most recently from 32e215a to 0ee522f Compare November 27, 2020 20:09
@SychO9
Copy link
Member Author

SychO9 commented Nov 27, 2020

Btw, the methods removeInclude removeOptionalInclude and removeSortField which were ported from the WillGetData event, I'm pretty sure they never actually worked, so I changed the code behind them (only the ones imported, the old ones I didn't).

Arr::forget removes items using their keys, but in this context we do not use keys, only values.

@SychO9 SychO9 force-pushed the sm/1624-api-controller-extender branch 3 times, most recently from 42aa939 to 38f7111 Compare December 1, 2020 17:40
@SychO9 SychO9 changed the title WIP: ApiController Extender ApiController Extender Dec 1, 2020
@SychO9 SychO9 marked this pull request as ready for review December 1, 2020 18:16
Copy link
Sponsor Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

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

Looking great! A few minor comments

tests/integration/extenders/ApiControllerTest.php Outdated Show resolved Hide resolved
tests/integration/extenders/ApiControllerTest.php Outdated Show resolved Hide resolved
Copy link
Member Author

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

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

Alright there's an issue I found while updating the bundled extensions to use this extender.

I passed an invokable class to prepareDataForSerialization (to replace the event listener) and the problem is that the class cannot receive the $data array by reference (which throws a php warning).

That's because when it comes to invokable classes, they're not directly called, it's the callback that returns the invokable which is called. (ContainerUtil::wrapCallback).

I think we can work around this if we receive the function arguments by reference when wrapping the invokable class object.

I'll make a separate pull request for that.

@askvortsov1
Copy link
Sponsor Member

Dumb question, but aren't all arrays received by reference on account of them being mutable objects? I thought PHPs pass by reference was only needed for primitives and strings

@SychO9
Copy link
Member Author

SychO9 commented Dec 4, 2020

Arrays are not considered objects, so just like primitives they are always passed by value and you have to explicitly specify that you would like to receive them by reference to modify them, otherwise you're just modifying a copy.

@askvortsov1
Copy link
Sponsor Member

Arrays are not considered objects, so just like primitives they are always passed by value and you have to explicitly specify that you would like to receive them by reference to modify them, otherwise you're just modifying a copy.

PHP why must you be like this 😬

I passed an invokable class to prepareDataForSerialization (to replace the event listener) and the problem is that the class cannot receive the $data array by reference (which throws a php warning).

Alright, good catch! Could we add some tests that will ensure that this will work once we fix this in ContainerUtil?

@SychO9
Copy link
Member Author

SychO9 commented Dec 4, 2020

Alright, good catch! Could we add some tests that will ensure that this will work once we fix this in ContainerUtil?

Good idea!

PHP why must you be like this 😬

¯\_(ツ)_/¯

www google com_search_q=why+can%27t+you+be+normal+meme+%22php%22 tbm=isch ved=2ahUKEwjSosH1jrXtAhWS7-AKHYRoBDsQ2-cCegQIABAA

@SychO9
Copy link
Member Author

SychO9 commented Dec 5, 2020

One of the tests naturally fails, until #2485 is merged.

@askvortsov1 askvortsov1 force-pushed the sm/1624-api-controller-extender branch from 6c14110 to c884006 Compare December 6, 2020 20:00
@askvortsov1 askvortsov1 merged commit 51a97fb into flarum:master Dec 6, 2020
@SychO9 SychO9 deleted the sm/1624-api-controller-extender branch December 6, 2020 20:13
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