Request->getPort() should prefer HTTP_HOST over SERVER_PORT
merged branch dhotson/request-http-host-port (PR #8882)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #8882).

Discussion
----------

[HttpFoundation] Request->getPort() should prefer HTTP_HOST over SERVER_PORT

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/3420
| License       | MIT
| Doc PR        | none

What is this?
----

_Note to reviewer: This follows on from a previous pull request: https://github.com/symfony/symfony/pull/8184
Since the introduction of `Request->setTrustedHosts()` — the implementation of this fix has been simplified._

This fixes the semantics of the `Request#getPort()` method to prefer the HTTP_HOST header over SERVER_PORT.

This is relevant in situations where the web server is running on a different port to the public facing website. e.g. load balancers, proxies, port forwarding.

Consistency
----

This change makes Symfony more consistent with other popular web frameworks.

Preferring HTTP_HOST over SERVER_NAME and SERVER_PORT is the strategy used by Ruby's Rack and Python's Django.

Python has a PEP that describes how to reconstruct URLs:
http://www.python.org/dev/peps/pep-0333/#url-reconstruction

https://github.com/rack/rack/blob/b6290a184cead2ffd731647d0836c5ebd3c21e7a/lib/rack/request.rb#L92

Commits
-------

fa97d80 Request->getPort() should prefer HTTP_HOST over SERVER_PORT
[HttpFoundation] improve perf of previous merge (refs #8882)