-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from all commits
0ef3f8e
99c5c08
8ed4076
b239305
269c6ce
b93c118
13ba87c
2c79d42
fcaf268
a4f52d9
94db3cb
ee67eee
4c2e4f9
7e5cd41
95edc8d
6fe23c0
00e524e
4b39fc0
26be81c
18d376e
a18f827
3d46b1d
255577f
358b4c8
1473eec
7e8da09
bd3ca8e
db0ad14
0ce2a83
fdb195c
97743fb
9ffd186
a0b1d42
479a85e
5674395
f00401d
54e1b08
bde64c8
a635d89
111cac0
8399581
02aab54
fda9900
76e45f9
09969d9
7a8e449
ae1171a
a3f0b31
831adec
16b5b09
0b7581d
9bc692f
26bef8d
a8a2da0
11886e6
db59374
d907d46
0941f47
1f43dbf
006b1e2
de69a87
400c087
d0ff8bc
9533f9a
aae0705
60617d7
0d6beb1
c087780
8e7106d
e8c19f7
6e01599
43e2e35
91e46f6
799e963
2ddd8b9
c88c20a
10e2732
f6656e4
249b704
ca9d5d8
f3c151c
d802d42
a1336e0
842e4d1
55f5c12
f303b20
409dba5
73cd243
d44e4a2
bf9c871
13a7170
126bcef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "we will" -> "it'll" |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "we won't talk" -> "This guide won't talk" There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "we are" -> "you are" |
||
HTTP frameworks or Request/Response frameworks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "as a HTTP framework or Request/Response framework" |
||
|
||
Before we start | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we -> you |
||
about some conventions: where we will store our code, how we will name our | ||
classes, how we will reference external dependencies, etc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
// framework/index.php | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this lines should be removed |
||
$input = $_GET['name']; | ||
|
||
printf('Hello %s', $input); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would vote to do |
||
|
||
Use the PHP built-in server to test this great application in a browser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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"