Skip to content

Added Symfony 4 compatibility and refactored code #345

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

Closed
wants to merge 13 commits into from
Closed

Added Symfony 4 compatibility and refactored code #345

wants to merge 13 commits into from

Conversation

junaidbinfarooq
Copy link

Replaced Symfony\Bundle\FrameworkBundle\Controller\Controller with Symfony\Bundle\FrameworkBundle\Controller\AbstractController
Added proper return type and type hints
Updated php doc-blocks

Replaced Symfony\Bundle\FrameworkBundle\Controller\Controller with Symfony\Bundle\FrameworkBundle\Controller\AbstractController
Added proper return type and type hints
Updated php doc-blocks
Copy link
Member

@odolbeau odolbeau left a comment

Choose a reason for hiding this comment

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

Thanks for your first contribution. :) It looks great. 👍
Could you please update CS?

@XWB XWB added this to the Version 1.0 milestone Nov 13, 2019
@XWB
Copy link
Contributor

XWB commented Nov 13, 2019

You will need to replace the $this->get() calls as well, because AbstractController uses a smaller container that does not contain all services.

@XWB XWB self-requested a review November 13, 2019 11:53
Copy link
Member

@welcoMattic welcoMattic left a comment

Choose a reason for hiding this comment

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

Please run cs-fixer to clean PHPDoc blocs ;)
Thanks for your contribution

{
/**
* @param Request $request
* @param string $configName
* @param string $locale
Copy link
Member

Choose a reason for hiding this comment

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

cs-fixer should remove those PHPDoc lines since they are redundant with type hinting.

Copy link
Member

@rvanlaak rvanlaak Nov 13, 2019

Choose a reason for hiding this comment

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

#342 also has the commits that fix cs, but these did not make it to master yet

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's merge #342 and this one. 👍

+ Removed $this-get calls in the controller and injected appropriate dependencies via constructor
+ cs-fixes
+ Added proper type-hints and return types
+ Added ext-json in the composer.json file
@junaidbinfarooq
Copy link
Author

junaidbinfarooq commented Nov 19, 2019

Thanks for your first contribution. :) It looks great.
Could you please update CS?

@odolbeau Updated the PR with CS-fixes and more changes. Could you please have a look.

@XWB
Copy link
Contributor

XWB commented Nov 19, 2019

@junaidbinfarooq Much better indeed. Still, those changes will only work if you have autowire enabled. So you'll have to create Resources/config/controller.yml and add each controller as a service.

@junaidbinfarooq
Copy link
Author

@junaidbinfarooq Much better indeed. Still, those changes will only work if you have autowire enabled. So you'll have to create Resources/config/controller.yml and add each controller as a service.

Oh! yeah. Done now. Please have a look.

@@ -1,3 +1,6 @@
imports:
- { resource: controller.yml }
Copy link
Contributor

Choose a reason for hiding this comment

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

Being a bundle, it would be better to move the import to TranslationExtension. See https://github.com/php-translation/symfony-bundle/blob/master/DependencyInjection/TranslationExtension.php#L42

Copy link
Author

Choose a reason for hiding this comment

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

Did see this before but still thought of importing the services as we do in the applications. Anyways, this is done now.

@@ -0,0 +1,9 @@
services:
_defaults:
Copy link
Contributor

Choose a reason for hiding this comment

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

The _defaults section needs to be removed. Autowire must be enabled in your own application and not in a bundle.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -22,7 +22,8 @@
"php-translation/symfony-storage": "^1.0",
"php-translation/extractor": "^1.6",
"nyholm/nsa": "^1.1",
"twig/twig": "^1.42 || ^2.11"
"twig/twig": "^1.42 || ^2.11",
"ext-json": "*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change required?

Copy link
Author

Choose a reason for hiding this comment

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

Added this after encountering few usages of json_encode/decode functions. PhpStorm does show a warning for this.

@XWB
Copy link
Contributor

XWB commented Nov 20, 2019

@junaidbinfarooq Almost done :)

autoconfigure: true
public: true

Translation\Bundle\Controller\:
Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to inject all the services into the constructor, so the controllers can work without autowire.

Copy link
Author

Choose a reason for hiding this comment

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

Have indeed used constructor injection.

…Extension

+ Renamed controller.yml to controllers.yml
+ Removed a few non-existent class usages
@junaidbinfarooq junaidbinfarooq requested a review from XWB November 20, 2019 19:27
@welcoMattic
Copy link
Member

@junaidbinfarooq Hi, as #342 is now merged in master, could you fix conflicts due to the merge (#342 (comment)).
Thank you 👍

@junaidbinfarooq
Copy link
Author

@junaidbinfarooq Hi, as #342 is now merged in master, could you fix conflicts due to the merge (#342 (comment)).
Thank you

Done. Could you please have a look.

@XWB
Copy link
Contributor

XWB commented Nov 28, 2019

Looks good in general. Just some tests need to be fixed.

@welcoMattic welcoMattic mentioned this pull request Nov 29, 2019
@odolbeau odolbeau mentioned this pull request Dec 7, 2019
3 tasks
@odolbeau odolbeau closed this Dec 26, 2019
@junaidbinfarooq junaidbinfarooq deleted the patch-1 branch December 28, 2019 18:24
@junaidbinfarooq
Copy link
Author

junaidbinfarooq commented Dec 31, 2019

@odolbeau Couldn't you have created a fork of my branch and update the tests instead of creating another PR and closing this one?

@odolbeau
Copy link
Member

I tried but I finally choose to create a new branch for several reasons.
Your branch mix 2 things: the Symfony 5 migration & the Strict type hinting. This branch was quite outdated compared to master when I started to work. Last but not least, you weren't active since a few weeks.
I hope you'll understand why I did that.
Thanks for your work anyway! :)

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.

5 participants