Skip to content

Rebuilding Format class #3149

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 16 commits into from

Conversation

mostafakhudair
Copy link
Contributor

keeping configuration methods away of hands

creating new class Format to handle getFormatter method
new exception methods forInvalidFormatter & forInvalidMime using in getFormatter
adding invalidFormatter & invalidMime translation using in FormatException
adding some changes to current format codes to be compatible with \CodeIgniter\Format
adding some changes to current format codes to be compatible with \CodeIgniter\Format
adding format as instance of factory for Formatters
Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

  • We need some tests for the new Format class.
  • ResponseTrait needs an update to use a new Format class.

*
* @return \CodeIgniter\Format\FormatterInterface
*/
public function getFormatter(string $mime)
Copy link
Member

Choose a reason for hiding this comment

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

We can't remove this. It would be a BC change.

This should use Services::format() under the hood and have a phpdoc comment that points out this method is deprecated since we have a new Format class now.

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 didn't remove it completely i just relocated it in system/Format/Format.php under CodeIgniter\Format namespace and now all Format instances runs throw \Config\Services::format()

about tests I actually don't know how to do it on the right way, may i get help or something

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I'm aware that you moved it to the Format class, but it doesn't change the fact that some people might use this method already in their code (just like we do in some of our tests). If we remove this method from here it will break their code - it has to stay.

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 got your point, but i think we can solve this problem by hinting new changes in next version changelog or something like that, any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

No, sorry. It has to stay - it was a public method. Removing it will be a breaking compatibility change.

adding some changes to current format codes to be compatible with \CodeIgniter\Format

removing negotiate() methord 3rd argument its false by default
removing useless  property $this->formatter
@mostafakhudair
Copy link
Contributor Author

Travis faild i will do changes at night

@michalsn
Copy link
Member

If you look at Travis build, you will see some errors. Please change the code in these tests so they use new Format class instead of Config\Format::getFormatter()

Speaking about tests for Format class - I think taking a look at LoggerTest would be a good idea, because we have there quite simple, generic examples. You should test all simple things you can do with this new class, like loading formatters, throwing exceptions when it should be thrown etc.

Of course, test it locally first: ./vendor/bin/phpunit tests/system/Format/Format.php - this will be probably a call to your test for Format class. Take your time and browse other tests we already have - they will certainly explain a lot.

but shall I use (! empty($this->config) or just ! instanceof as I did
revert some changes and improve code style
One line code
replace with new format() service
@paulbalandan paulbalandan mentioned this pull request Aug 29, 2020
5 tasks
@MGatner MGatner closed this in #3563 Sep 1, 2020
@mostafakhudair mostafakhudair deleted the patch-12 branch September 4, 2020 14:08
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.

2 participants