Skip to content
Prev Previous commit
Next Next commit
Other minor fixes
  • Loading branch information
wouterj committed Nov 20, 2014
commit c8ce5074e05f5954458f6258871debf2157abc71
40 changes: 18 additions & 22 deletions book/http_fundamentals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ applications, while staying out of your way. Symfony is built on the best
ideas from many technologies: the tools and concepts you're about to learn
represent the efforts of thousands of people, over many years. In other words,
you're not just learning "Symfony", you're learning the fundamentals of the
web, development best practices, and how to use many amazing new PHP libraries,
web, development best practices and how to use many amazing new PHP libraries,
inside or independently of Symfony. So, get ready.

True to the Symfony philosophy, this chapter begins by explaining the fundamental
Expand All @@ -33,9 +33,9 @@ takes place:
:align: center

And while the actual language used is a bit more formal, it's still dead-simple.
HTTP is the term used to describe this simple text-based language. And no
matter how you develop on the web, the goal of your server is *always* to
understand simple text requests, and return simple text responses.
HTTP is the term used to describe this simple text-based language. No matter
how you develop on the web, the goal of your server is *always* to understand
simple text requests, and return simple text responses.

Symfony is built from the ground up around that reality. Whether you realize
it or not, HTTP is something you use everyday. With Symfony, you'll learn
Expand All @@ -48,7 +48,7 @@ Step1: The Client Sends a Request
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Every conversation on the web starts with a *request*. The request is a text
message created by a client (e.g. a browser, an iPhone app, etc) in a
message created by a client (e.g. a browser, a smartphone app, etc) in a
Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with the 📱? :P

special format known as HTTP. The client sends that request to a server,
and then waits for the response.

Expand Down Expand Up @@ -98,7 +98,7 @@ delete a specific blog entry, for example:

There are actually nine HTTP methods defined by the HTTP specification,
but many of them are not widely used or supported. In reality, many modern
browsers don't support the ``PUT`` and ``DELETE`` methods.
browsers don't even support the ``PUT`` and ``DELETE`` methods.

In addition to the first line, an HTTP request invariably contains other
lines of information called request headers. The headers can supply a wide
Expand Down Expand Up @@ -161,7 +161,7 @@ communication on the web. And as important and powerful as this process is,
it's inescapably simple.

The most important fact is this: regardless of the language you use, the
type of application you build (web, mobile, JSON API), or the development
type of application you build (web, mobile, JSON API) or the development
philosophy you follow, the end goal of an application is **always** to understand
each request and create and return the appropriate response.

Expand Down Expand Up @@ -277,6 +277,7 @@ an HTTP response message. This allows your application to use an object-oriented
interface to construct the response that needs to be returned to the client::

use Symfony\Component\HttpFoundation\Response;

$response = new Response();

$response->setContent('<html><body><h1>Hello world!</h1></body></html>');
Expand Down Expand Up @@ -366,12 +367,13 @@ on that value. This can get ugly quickly::
// index.php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$request = Request::createFromGlobals();
$path = $request->getPathInfo(); // the URI path being requested

if (in_array($path, array('', '/'))) {
$response = new Response('Welcome to the homepage.');
} elseif ($path == '/contact') {
} elseif ('/contact' === $path) {
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 philosophical, but I personally only use the === when I have a specific reason to match type. I know people that disagree, however.

Copy link
Member Author

Choose a reason for hiding this comment

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

the Symfony standard is to always use ===

Copy link
Member

Choose a reason for hiding this comment

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

@weaverryan the implicit type casting can create very weird bugs in your code (for instance 0 == 'abc' is true in PHP). this is one of the reason we use strict comparison everywhere, unless we need the non-strict one

$response = new Response('Contact us');
} else {
$response = new Response('Page not found.', 404);
Expand Down Expand Up @@ -485,8 +487,8 @@ email messages.

.. _symfony2-build-your-app-not-your-tools:

Symfony: Build your App, not your Tools.
----------------------------------------
Symfony: Build your App, not your Tools
---------------------------------------

You now know that the goal of any app is to interpret each incoming request
and create an appropriate response. As an application grows, it becomes more
Expand Down Expand Up @@ -522,24 +524,21 @@ regardless of how your project is developed. To name a few:
about how that request should be handled (e.g. execute the ``contactAction()``
method);

* `Form`_ - A full-featured and flexible framework for creating forms and
handling form submissions;
* `Form </components/form/introduction>` - A full-featured and flexible
Copy link
Member

Choose a reason for hiding this comment

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

missing :doc: role

framework for creating forms and handling form submissions;

* `Validator`_ - A system for creating rules about data and then validating
whether or not user-submitted data follows those rules;

* :doc:`ClassLoader </components/class_loader/introduction>` - An autoloading library that allows
PHP classes to be used without needing to manually ``require`` the files
containing those classes;

* :doc:`Templating </components/templating/introduction>` - A toolkit for rendering
templates, handling template inheritance (i.e. a template is decorated with
a layout) and performing other common template tasks;

* `Security`_ - A powerful library for handling all types of security inside
an application;
* `Security </components/security/introduction>` - A powerful library for
Copy link
Member

Choose a reason for hiding this comment

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

missing :doc: role

handling all types of security inside an application;

* `Translation`_ - A framework for translating strings in your application.
* `Translation </components/translation/introduction>` - A framework for
Copy link
Member

Choose a reason for hiding this comment

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

missing :doc: role

translating strings in your application.

Each and every one of these components is decoupled and can be used in *any*
PHP project, regardless of whether or not you use the Symfony framework.
Expand Down Expand Up @@ -576,8 +575,5 @@ sensible defaults. For more advanced users, the sky is the limit.
.. _`List of HTTP status codes`: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
.. _`List of HTTP header fields`: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
.. _`List of common media types`: http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types
.. _`Form`: https://github.com/symfony/Form
.. _`Validator`: https://github.com/symfony/Validator
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this one link to the component doc as well ? Or is it not merged yet ?

Copy link
Member

Choose a reason for hiding this comment

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

not merged yet - it's been on the lower priority because we packed so much into 2.6 and the docs needing to be re-read for updates like this :).

.. _`Security`: https://github.com/symfony/Security
.. _`Translation`: https://github.com/symfony/Translation
.. _`Swift Mailer`: http://swiftmailer.org/