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

Upgrade to Laravel 6, finally! #2243

Merged
merged 5 commits into from
Jul 27, 2020
Merged

Upgrade to Laravel 6, finally! #2243

merged 5 commits into from
Jul 27, 2020

Conversation

franzliedke
Copy link
Contributor

Fixes #2055

This was easier than anticipated. 😄
Luckily, we are only using the translator using the interface from Symfony. We only need to fulfill Laravel's contract to be able to pass something into its validator factory.

Changes proposed in this pull request:

  • Update Illuminate components to current LTS release (v6)
  • Fix a few remaining global helper calls (removed in v6) and replace them by static calls
  • Unify typehints for dependency injection of translator instances
  • Satisfy updated Translator contract (from Laravel) in our implementation - only needed for the validation component

Confirmed

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

- Apparently, I forgot that `array_flatten` comes from Laravel. :)
- When I did this previously, I did not search the views directory.
The Laravel changes with v6, and our translator is primarily an
implementation of the Symfony contract.
It's contract will change in Laravel 6. We extend from Symfony's
translator, but need to be compatible with that from Laravel in
order to use its validation package.

References:
- https://laravel.com/docs/6.x/upgrade#trans-and-trans-choice
- laravel/framework@8557dc5#diff-88bc04a1548d09aa6250d902d1ac2b4c
@franzliedke
Copy link
Contributor Author

@tankerkiller125 offered to take care of replacing array_get (and possibly other old helpers?) with the class-based variant in the bundled extensions. That's a blocker for merging this PR, so we can leave that to him. 😁

@askvortsov1
Copy link
Member

On the contrary, perhaps it would be better to merge this PR, break bundled extensions on dev/master, and that way, cleaning up bundled extensions would be easier?

@franzliedke
Copy link
Contributor Author

It's a pretty easy find-and-replace operation (and safer than relying on hitting all code paths with clicking through the app or relying on non-existent tests).

@tankerkiller125
Copy link
Contributor

@askvortsov1 I'll have all the core extensions updated this weekend anyway and I'll be committing directly to master, (no point in PRing a simple helper function to class function PR) so honestly a couple days at most wait to merge isn't that bad.

Copy link
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.

Mostly pristine (as usual)!

@@ -17,6 +17,16 @@ class Translator extends BaseTranslator implements TranslatorContract
{
const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i';

public function get($key, array $replace = [], $locale = null)
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this the other way around, and have the logic in Laravel's new methods, and have the old methods reference the new ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "old" ones come from the Symfony base implementation.

Copy link
Member

Choose a reason for hiding this comment

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

The reason I bring this up is that if we eventually want to comply with the laravel contract, we might as well move the logic to laravel's methods. If we want to eventually drop the laravel translation contract, this is fine though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't get what you mean, sorry. trans() and transChoice() are implemented in Symfony's translator, and we don't overwrite these. And since we're mostly/only using Symfony's interface throughout the app, I'd rather keep their implementation as well. These two methods are only needed as a bridge to be able to use this Symfony-based translator in Laravel's validation component.

Copy link
Contributor

@tankerkiller125 tankerkiller125 left a comment

Choose a reason for hiding this comment

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

Just solid work here, I'll triple check everything works as intended tomorrow once I get core extensions updated. But what I see here is awesome.

@tankerkiller125
Copy link
Contributor

Core extensions updated

Copy link
Member

@luceos luceos left a comment

Choose a reason for hiding this comment

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

Went over the full changes. Nothing to add. The changes seemed straightforward, simple even, but I know this is the consequence of something greater. Thank you for this simple, effective and great PR, awesome job.

@franzliedke franzliedke merged commit 4dc4dc6 into master Jul 27, 2020
@franzliedke franzliedke deleted the fl/2055-l6-translator branch July 27, 2020 19:42
askvortsov1 added a commit that referenced this pull request Oct 5, 2020
This seems to be a leftover change missed in #2243
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.

Upgrade Illuminate components to 6.x
4 participants