-
-
Notifications
You must be signed in to change notification settings - Fork 405
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 MakeSerializerEncoder command. #30
Added MakeSerializerEncoder command. #30
Conversation
protected function writeNextStepsMessage(array $params, ConsoleStyle $io) | ||
{ | ||
$io->text([ | ||
'Next: Open your new encoder class and start customizing it.', |
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.
This is not a question about your Pull Request but a general question: are these "next steps" instructions really useful?
- This doesn't provide much: "Next: Open your new encoder class and start customizing it."
- And this is more suited for a "demo app" or "newcomer learning resource": "Find the documentation at ..."
I propose to remove all these obvious "next steps" and only keep the ones really needed.
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.
I think you may be right. But I still want a clear “success” message at the bottom. Maybe there’s a default, generic success message and we only override it when there really are additional steps
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.
The exact next information is not really helpful in this case (just followed the convention from other commands).
Just to point that when you generate new command over SensioGeneratorBundle after confirmation you'll receive
You are going to generate a foo-bar command inside AppBundle bundle.
Do you confirm generation [yes]?
created ./src/AppBundle/Command/
created ./src/AppBundle/Command/FooBarCommand.php
Generated the foo-bar command in AppBundle
Everything is OK! Now get to work :).
Not sure if and how close to this maker should be.
If agreed I can refactor existing commands for that.
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.
OK ... let's discuss about this in a separate PR and, if needed, let's make the change at once for all commands.
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.
I’m happy to have this command! @dunglas does the generated class look good to you or would you suggest any changes? Is it the best practice to create just one class that’s both an encoder and a decoder?
composer.json
Outdated
@@ -17,7 +17,8 @@ | |||
"symfony/dependency-injection": "^3.4|^4.0", | |||
"symfony/filesystem": "^3.4|^4.0", | |||
"symfony/framework-bundle": "^3.4|^4.0", | |||
"symfony/http-kernel": "^3.4|^4.0" | |||
"symfony/http-kernel": "^3.4|^4.0", | |||
"symfony/serializer": "^3.4|^4.0" |
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.
This should be in require-dev - it’s only needed to test the app.
|
||
public function supportsEncoding($format) | ||
{ | ||
return '{{ format }}' === $format; |
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.
The format could be in a FORMAT
class const, as done in built-in encoders:
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.
@ogizanagi - makes sense. Fixed.
@weaverryan - moved |
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Creates a new custom encoder class') |
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.
What about:
Creates a new serializer encoder class
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.
Yup, fixed in command description, success message (as is :) ) and command help.
return ''; | ||
} | ||
|
||
public function supportsEncoding($format) |
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.
Just asking: we can't do it right and add type hints (e.g. supportsEncoding(string $format): bool
) because of the interfaces, right?
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.
@javiereguiluz indeed. Since there is no type-hinting in the interface, trying to add some in implemented method will end up with
Fatal error: Declaration of YamlEncoder::supportsEncoding(string $format) must be compatible with EncoderInterface::supportsEncoding($format)
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.
In fact you could at least add the return type: https://3v4l.org/GiabR.
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.
@ogizanagi right! Done!
composer.json
Outdated
@@ -21,7 +21,8 @@ | |||
}, | |||
"require-dev": { | |||
"symfony/phpunit-bridge": "^3.4|^4.0", | |||
"symfony/process": "^3.4|^4.0" | |||
"symfony/process": "^3.4|^4.0", | |||
"symfony/serializer": "^3.4|^4.0" |
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.
It is really necessary? I mean, we don't do this for the current ones.
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.
@yceruto - it was from the beginning of the repo. Correct me if I'm wrong but I think removing this should go to a separate issue.
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.
symfony/serializer
deps has been introduced in this PR, no? I think is not necessary for tests either, as tests don't check dependencies currently:
https://github.com/yceruto/maker-bundle/blob/c402dac16d4744bf0c1d159ec67bdaf0d3fbd619/tests/Command/FunctionalTest.php#L49
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.
You are right. Removed from composer.json
.
return ''; | ||
} | ||
|
||
public function supportsEncoding($format): bool |
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.
?string $format
should work (not tested it), same for decode
.
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.
@dunglas - unfortunately the problem remains, tested on PHP 7.1.6
Fatal error: Declaration of YamlEncoder::supportsEncoding(?string $format) must be compatible with EncoderInterface::supportsEncoding($format)
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.
adding it relies on PHP 7.2 new features.
{ | ||
const FORMAT = '{{ format }}'; | ||
|
||
public function encode($data, $format, array $context = array()) |
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.
array $context = []
as we're on 7.1+?
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.
Fixed. Thank you!
|
||
class {{ encoder_class_name }} implements EncoderInterface, DecoderInterface | ||
{ | ||
const FORMAT = '{{ format }}'; |
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.
public const
?
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.
Fixed. Thank you!
{ | ||
$dependencies->addClassDependency( | ||
Serializer::class, | ||
'serializer' |
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.
use 4 space for each level of indentation.
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.
Fixed. Thank you!
@weaverryan - are you happy with the recent changes? |
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.
I'm super happy :). Thanks!
Guys, I know that in the light of @javiereguiluz recent post about this bundle the approach is to discuss the potential new command over a ticket but I am wondering whether this PR can be merged? It's been discussed in #17 and I hope make:serializer:encode code is good enough to be merged. Thank you for your attention! |
Thanks Piotr for working on this feature, this is much appreciated. |
This PR was squashed before being merged into the 1.0-dev branch (closes #30). Discussion ---------- Added MakeSerializerEncoder command. @javiereguiluz - I know that this is an early stage of this repository and you've mentioned in #27 that the focus should be more on fixing current issues and problems. I would love to help on those :) Nevertheless I hope you'll find this PR useful as a implementation of one of proposed commands from #17. Commits ------- 6079823 MakeSerializerEncoder - indentation fix. 6dc2d2f MakeEncoderSerializer - template fixes. 74e098b MakeEncoderSerializer - removing serializer dependency. 7051ecb MakeEncoderSerializer - adding typehint for return value on supports methods. 5cfc4f8 MakeEncoderSerializer - changed command description. f02ce64 MakeEncoderSerializer move format to constant. df17425 Moving symfony/serializer lib to require-dev e3c3d09 Added MakeSerializerEncoder command.
And thanks also for making the quick changes! Woo! |
I think making custom normalizer is much more likely to happen than custom encoders though. |
@stof - this is a good idea I think. If you are OK with that I could start new issue to discuss this further. If there be a will for that I would love to prepare such command. |
@javiereguiluz - I know that this is an early stage of this repository and you've mentioned in #27 that the focus should be more on fixing current issues and problems. I would love to help on those :)
Nevertheless I hope you'll find this PR useful as a implementation of one of proposed commands from #17.