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 MakeSerializerEncoder command. #30

Merged
merged 8 commits into from
Nov 28, 2017
Merged

Added MakeSerializerEncoder command. #30

merged 8 commits into from
Nov 28, 2017

Conversation

piotrgradzinski
Copy link
Contributor

@piotrgradzinski piotrgradzinski commented Nov 19, 2017

@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.

protected function writeNextStepsMessage(array $params, ConsoleStyle $io)
{
$io->text([
'Next: Open your new encoder class and start customizing it.',
Copy link
Member

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.

Copy link
Member

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

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

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 discuss about this in a separate PR and, if needed, let's make the change at once for all commands.

Copy link
Member

@weaverryan weaverryan left a 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"
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ogizanagi - makes sense. Fixed.

@piotrgradzinski
Copy link
Contributor Author

piotrgradzinski commented Nov 19, 2017

@weaverryan - moved symfony/serializer to required-dev in composer.json
@ogizanagi - changed format to const.

protected function configure()
{
$this
->setDescription('Creates a new custom encoder class')
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

@piotrgradzinski piotrgradzinski Nov 19, 2017

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)

Copy link
Member

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.

Copy link
Contributor Author

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"
Copy link
Member

@yceruto yceruto Nov 19, 2017

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

@piotrgradzinski piotrgradzinski Nov 20, 2017

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

@dunglas dunglas Nov 19, 2017

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.

Copy link
Contributor Author

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)

Copy link
Member

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())
Copy link
Member

@dunglas dunglas Nov 19, 2017

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+?

Copy link
Contributor Author

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 }}';
Copy link
Member

Choose a reason for hiding this comment

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

public const?

Copy link
Contributor Author

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'
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thank you!

@piotrgradzinski
Copy link
Contributor Author

@weaverryan - are you happy with the recent changes?

Copy link
Member

@weaverryan weaverryan left a 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!

@piotrgradzinski
Copy link
Contributor Author

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!

@weaverryan
Copy link
Member

Thanks Piotr for working on this feature, this is much appreciated.

@weaverryan weaverryan merged commit 6079823 into symfony:master Nov 28, 2017
weaverryan added a commit that referenced this pull request Nov 28, 2017
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.
@weaverryan
Copy link
Member

And thanks also for making the quick changes! Woo!

@stof
Copy link
Member

stof commented Nov 28, 2017

I think making custom normalizer is much more likely to happen than custom encoders though.

@piotrgradzinski
Copy link
Contributor Author

@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.

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.

7 participants