8000 [HttpFoundation] Move IP check methods to a HttpUtils class for reuse by vicb · Pull Request #6005 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Move IP check methods to a HttpUtils class for reuse #6005

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

Conversation

vicb
Copy link
Contributor
@vicb vicb commented Nov 13, 2012

No description provided.

{
if (false !== strpos($requestIp, ':')) {
return self::checkIp6($requestIp, $ip);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

no need for else here as the if returns

@vicb
Copy link
Contributor Author
vicb commented Nov 13, 2012

Thanks @stof ! (didn't get my copy paste error as PHP allow calling non static method w/o a warning).

*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HttpUtils
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the class final, for restricting it to be inherited.

class MyHttpUtils extends HttpUtils
8000

{
     public function __construct() {}
}
// In Java you cant inherit from class with private default constructor, 
// but in PHP you can
$utils = new MyHttpUtils(); 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see #5879

Copy link
Contributor

Choose a reason for hiding this comment

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

@vicb, I saw it, but I don't get any point!, you change the access modifier to private to make the class not instantiated, but some one could inherit from the class and make an instance object of inherited class without calling the parent constructor, and it is bug.

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 change is for consistency with other ...Utils classes. Having a private constructor is a safeguard to prevent from instatiating a class with static methods only. Users can still extend the class as it is not final (in such a case the safeguard will not be useful any more, is that really important ?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for your point. No, when the programming language is PHP, no, it is not really important (In OOP when some class has private constructor is not extendable and instatiable)

Thanks for answering my comment, I get the note.

@GromNaN
Copy link
Member
GromNaN commented Nov 17, 2012

Having an Utils class with mixed functions doesn't seem to be a good practice. I think the class should be called something like Symfony\Component\HttpFoundation\IpAddress.

@vicb
Copy link
Contributor Author
vicb commented Nov 27, 2012

@fabpot could this be merged if HttpUtils is renamed to IpUtils ?

* @param string $requestIp
* @param string $ip
*
* @return boolean True valid, false if not.
Copy link
Contributor

Choose a reason for hiding this comment

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

True if valid, false if not ?

@fabpot
Copy link
Member
fabpot commented Dec 6, 2012

Renaming the class to IpUtils is indeed a good idea.

@vicb
Copy link
Contributor Author
vicb commented Dec 6, 2012

ready !

@fabpot
Copy link
Member
fabpot commented Dec 6, 2012

Can you add an entry in the CHANGELOG?

@vicb
Copy link
Contributor Author
vicb commented Dec 6, 2012

done, thanks for the reminder !

@fabpot fabpot closed this in 0c6e145 Dec 6, 2012
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.

6 participants
0