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

Integrate the "Create your own framework" tutorial into the Symfony official documentation #4455

Closed
wants to merge 92 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
0ef3f8e
added part 1
fabpot Jan 3, 2012
99c5c08
added a LICENSE file
fabpot Jan 3, 2012
8ed4076
Fixed typo
lyrixx Jan 3, 2012
b239305
Fixed typo
jdreesen Jan 4, 2012
269c6ce
merged branch lyrixx/patch-1 (PR #1)
fabpot Jan 4, 2012
b93c118
merged branch jdreesen/patch-1 (PR #2)
fabpot Jan 4, 2012
13ba87c
added a tip about the Composer autoloader
fabpot Jan 4, 2012
2c79d42
added part 2
fabpot Jan 4, 2012
fcaf268
Fixes grammatical error
catchamonkey Jan 5, 2012
a4f52d9
added links to projects
fabpot Jan 5, 2012
94db3cb
merged branch catchamonkey/patch-1 (PR #3)
fabpot Jan 5, 2012
ee67eee
fixed markup
fabpot Jan 5, 2012
4c2e4f9
[part2] Fixinng typo: removing one of the double where
Jan 5, 2012
7e5cd41
merged branch gnugat/part2-typo-where-where (PR #4)
fabpot Jan 5, 2012
95edc8d
Add missing colon to code-block
andreia Jan 6, 2012
6fe23c0
merged branch andreia/master (PR #5)
fabpot Jan 6, 2012
00e524e
fixed ambiguity (closes #6)
fabpot Jan 6, 2012
4b39fc0
removed the path to composer.json as JSON doe snot support comments b…
fabpot Jan 7, 2012
26be81c
added part 3
fabpot Jan 7, 2012
18d376e
updated composer.json
fabpot Jan 7, 2012
a18f827
fixed typos
jdreesen Jan 8, 2012
3d46b1d
merged branch jdreesen/patch-2 (PR #7)
fabpot Jan 8, 2012
255577f
went back to 2.1.* in composer.json files
fabpot Jan 8, 2012
358b4c8
added part 4
fabpot Jan 9, 2012
1473eec
fixed typo
fabpot Jan 9, 2012
7e8da09
fixed typo (closes #8)
fabpot Jan 9, 2012
bd3ca8e
fixed extract() calls
fabpot Jan 9, 2012
db0ad14
added part 5
fabpot Jan 11, 2012
0ce2a83
fixed some typos
jdreesen Jan 11, 2012
fdb195c
added part 6
fabpot Jan 13, 2012
97743fb
added part 7
fabpot Jan 15, 2012
9ffd186
[part7] Fixing typo: adding 'x' to Simple/Framework class
Jan 15, 2012
a0b1d42
merged branch gnugat/part7-typo-simple (PR #12)
fabpot Jan 15, 2012
479a85e
fixed typos
fabpot Jan 15, 2012
5674395
renamed part as we now know that we are going to have more than 10 parts
fabpot Jan 15, 2012
f00401d
added part 8
fabpot Jan 17, 2012
54e1b08
added a note in part 8
fabpot Jan 17, 2012
bde64c8
made small tweaks
fabpot Jan 19, 2012
a635d89
added part 10
fabpot Jan 21, 2012
111cac0
removed some use statement to be more consistent with previous parts
fabpot Jan 21, 2012
8399581
moved the Context::fromRequest() code to the Framework class
fabpot Jan 21, 2012
02aab54
Corrected some english errors
Jan 21, 2012
fda9900
fixed pygments code name for json
fabpot Jan 22, 2012
76e45f9
fixed markup
fabpot Jan 22, 2012
09969d9
added part 11
fabpot Jan 23, 2012
7a8e449
merged branch Nanocom/master (PR #14)
fabpot Jan 23, 2012
ae1171a
merged branch jdreesen/patch-3 (PR #10)
fabpot Jan 23, 2012
a3f0b31
Corrected few typos
Jan 23, 2012
831adec
merged branch Nanocom/master (PR #15)
fabpot Jan 23, 2012
16b5b09
Fixed typo
willdurand Jan 24, 2012
0b7581d
merged branch willdurand/patch-1 (PR #16)
fabpot Jan 24, 2012
9bc692f
added part 12
fabpot Jan 25, 2012
26bef8d
Fixed typos
amitayh Jan 25, 2012
a8a2da0
Fixed part 12 typos
amitayh Jan 25, 2012
11886e6
Merge branch 'master' of https://github.com/amitayh/Create-Your-Frame…
amitayh Jan 25, 2012
db59374
fixed typo
fabpot Jan 25, 2012
d907d46
Fixed typos
nanocom Jan 25, 2012
0941f47
merged branch Nanocom/master (PR #18)
fabpot Jan 25, 2012
1f43dbf
removed conflict merge
fabpot Jan 25, 2012
006b1e2
fixed markup
fabpot Jan 27, 2012
de69a87
HttpKernel name can't be imported twice, if importing only Symfony\Co…
hrbonz Feb 7, 2012
400c087
add framework code as people would probably modify it following first…
hrbonz Feb 7, 2012
d0ff8bc
updated titles
fabpot Feb 7, 2012
9533f9a
merged branch hrbonz/part12_fixes (PR #19)
fabpot Feb 7, 2012
aae0705
fixed CS
fabpot Feb 7, 2012
60617d7
Fixed one typo.
Feb 25, 2012
0d6beb1
merged branch pedrotgimenez/part11 (PR #21)
fabpot Mar 2, 2012
c087780
merged branch amitayh/master (PR #17)
fabpot Mar 22, 2012
8e7106d
Fixed a typo in part02.rst (<php changed to <?php)
Apr 30, 2012
e8c19f7
Merge pull request #22 from ubick/master
fabpot Apr 30, 2012
6e01599
Fix little typo
dirkaholic Sep 14, 2012
43e2e35
Merge pull request #23 from dirkaholic/master
fabpot Sep 14, 2012
91e46f6
removed the paragraph about CS as we now have standards
fabpot Sep 28, 2012
799e963
updated composer autoload path
bamarni Oct 3, 2012
2ddd8b9
merged branch bamarni/master (PR #24)
fabpot Oct 3, 2012
c88c20a
removed usage of the ClassLoader component in favor of Composer
fabpot Oct 15, 2012
10e2732
added an index file
fabpot May 15, 2013
f6656e4
removed a note that is not relevant anymore
fabpot May 15, 2013
249b704
added missing links
fabpot May 15, 2013
ca9d5d8
removed unused references
fabpot May 15, 2013
f3c151c
reworded slightly some sentence to convert the text from a series of …
fabpot May 15, 2013
d802d42
updated code for Symfony 2.3 and made minor tweaks to the text
fabpot May 15, 2013
a1336e0
Update part06.rst
revollat Jun 6, 2013
842e4d1
bug #25 Update part06.rst (revollat)
fabpot Mar 14, 2014
55f5c12
updated the whole book (changes mainly related to Composer)
fabpot Jun 23, 2014
f303b20
removed versions when adding Symfony component with Composer
fabpot Oct 24, 2014
409dba5
move things around
fabpot Nov 12, 2014
73cd243
added the "Create your own framework" tutorial
fabpot Nov 12, 2014
d44e4a2
added the new tutorial in the main index
fabpot Nov 12, 2014
bf9c871
fixed markup
fabpot Nov 12, 2014
13a7170
made some changes to better integrate the tutorial into the current d…
fabpot Nov 20, 2014
126bcef
removed external references alignement
fabpot Feb 5, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions create_framework/01-introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Introduction
============

`Symfony2`_ is a reusable set of standalone, decoupled, and cohesive PHP
Copy link
Member

Choose a reason for hiding this comment

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

remove serial comma before "and"

components that solve common web development problems.

Instead of using these low-level components, you can use the ready-to-be-used
Symfony2 full-stack web framework, which is based on these components... or
Copy link
Member

Choose a reason for hiding this comment

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

"Symfony2" -> "Symfony" (same should be done in the rest of the PR)

you can create your very own framework. This book is about the latter.
Copy link
Member

Choose a reason for hiding this comment

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

"this book" -> "this tutorial"


Why would you like to create your own framework?
Copy link
Member

Choose a reason for hiding this comment

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

"Why would you Like to Create your Own Framework?"

------------------------------------------------

Why would you like to create your own framework in the first place? If you
look around, everybody will tell you that it's a bad thing to reinvent the
wheel and that you'd better choose an existing framework and forget about
creating your own altogether. Most of the time, they are right but there are
a few good reasons to start creating your own framework:

* To learn more about the low level architecture of modern web frameworks in
general and about the Symfony2 full-stack framework internals in particular;

* To create a framework tailored to your very specific needs (just be sure
first that your needs are really specific);

* To experiment creating a framework for fun (in a learn-and-throw-away
approach);

* To refactor an old/existing application that needs a good dose of recent web
development best practices;

* To prove the world that you can actually create a framework on your own (...
but with little effort).

This tutorial will gently guide you through the creation of a web framework,
one step at a time. At each step, you will have a fully-working framework that
you can use as is or as a start for your very own. We will start with simple
Copy link
Member

Choose a reason for hiding this comment

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

"we will" -> "it'll"
"simple frameworks" -> "a simple framework"

frameworks and more features will be added with time. Eventually, you will have
a fully-featured full-stack web framework.

And of course, each step will be the occasion to learn more about some of the
Symfony2 Components.

.. tip::

If you don't have time to read the whole book, or if you want to get
started fast, you can also have a look at `Silex`_, a micro-framework
based on the Symfony2 Components. The code is rather slim and it leverages
many aspects of the Symfony2 Components.

Many modern web frameworks advertize themselves as being MVC frameworks. We
won't talk about the MVC pattern as the Symfony2 Components are able to create
Copy link
Member

Choose a reason for hiding this comment

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

"we won't talk" -> "This guide won't talk"

Copy link
Member

Choose a reason for hiding this comment

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

I believe there should be a comma between "MVC pattern" and "as the", as it currently looks like "we talk about X as if it was Y", but instead it should be "we talk about X because of Y"

any type of frameworks, not just the ones that follow the MVC architecture.
Anyway, if you have a look at the MVC semantics, this book is about how to
create the Controller part of a framework. For the Model and the View, it
really depends on your personal taste and you can use any existing
third-party libraries (Doctrine, Propel, or plain-old PDO for the Model; PHP
Copy link
Member

Choose a reason for hiding this comment

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

remove serial comma before or

or Twig for the View).

When creating a framework, following the MVC pattern is not the right goal. The
main goal should be the **Separation of Concerns**; this is probably the only
design pattern that you should really care about. The fundamental principles of
the Symfony2 Components are focused on the HTTP specification. As such, the
frameworks that we are going to create should be more accurately labelled as
Copy link
Member

Choose a reason for hiding this comment

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

"we are" -> "you are"

HTTP frameworks or Request/Response frameworks.
Copy link
Member

Choose a reason for hiding this comment

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

"as a HTTP framework or Request/Response framework"


Before we start
Copy link
Member

Choose a reason for hiding this comment

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

"Before you Start"

---------------

Reading about how to create a framework is not enough. You will have to follow
along and actually type all the examples we will work on. For that, you need a
Copy link
Member

Choose a reason for hiding this comment

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

"[...] we will work on" -> "[...] you will see." or something else as long as it avoids the first person usage.

recent version of PHP (5.3.8 or later is good enough), a web server (like
Copy link
Member

Choose a reason for hiding this comment

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

should be 5.3.9 now?

Apache or NGinx), a good knowledge of PHP and an understanding of Object
Copy link
Member

Choose a reason for hiding this comment

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

or build-in web server

Oriented programming.

Ready to go? Let's start.
Copy link
Member

Choose a reason for hiding this comment

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

"Let's start" -> "Read on!" or the like, again to remove first person usage


Bootstrapping
-------------

Before we can even think of creating our first framework, we need to talk
Copy link
Member

Choose a reason for hiding this comment

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

we -> you
"we need to talk about some conventions" -> "you need to think about some conventions"

about some conventions: where we will store our code, how we will name our
classes, how we will reference external dependencies, etc.
Copy link
Member

Choose a reason for hiding this comment

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

3x we -> you


To store our framework, create a directory somewhere on your machine:
Copy link
Member

Choose a reason for hiding this comment

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

"our framework" -> "your new framework"


.. code-block:: bash

$ mkdir framework
$ cd framework

Dependency Management
~~~~~~~~~~~~~~~~~~~~~

To install the Symfony2 Components that we need for our framework, we are going
Copy link
Member

Choose a reason for hiding this comment

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

2x we -> you (from now on, I'll no longer comment on this subject, but it still applies)

to use `Composer`_, a project dependency manager for PHP. If you don't have it
yet, `download and install`_ Composer now:

.. code-block:: bash

$ curl -sS https://getcomposer.org/installer | php
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 replaced with a link to http://symfony.com/doc/current/cookbook/composer.html


Then, generate an empty ``composer.json`` file, where Composer will store the
framework dependencies:

.. code-block:: bash

$ composer init -n

Our Project
-----------

Instead of creating our framework from scratch, we are going to write the same
"application" over and over again, adding one abstraction at a time. Let's
start with the simplest web application we can think of in PHP::

<?php
Copy link
Member

Choose a reason for hiding this comment

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

we never show PHP open tag. If you insist on having them, you should use html+php instead of the default php syntax highlighting


// framework/index.php

Copy link
Member

Choose a reason for hiding this comment

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

this lines should be removed

$input = $_GET['name'];

printf('Hello %s', $input);
Copy link
Member

Choose a reason for hiding this comment

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

I would vote to do echo 'Hello '.$input. We almost never use any *rintf function in the examples (they are hard to read and not PHP basics).


Use the PHP built-in server to test this great application in a browser
Copy link
Member

Choose a reason for hiding this comment

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

"If you have PHP 5.4, you can use the PHP built-in [...]. Otherwise, use your own server (Apache, Nginx, etc.)"

(``http://localhost:4321/index.php?name=Fabien``):

.. code-block:: bash

$ php -S 127.0.0.1:4321

In the next chapter, we are going to introduce the HttpFoundation Component
and see what it brings us.

.. _`Symfony2`: http://symfony.com/
.. _`documentation`: http://symfony.com/doc
.. _`Silex`: http://silex.sensiolabs.org/
.. _`Composer`: http://packagist.org/about-composer
.. _`download and install`: https://getcomposer.org/doc/01-basic-usage.md
Loading