1
1
Introduction
2
2
============
3
3
4
- `Symfony2 `_ is a reusable set of standalone, decoupled, and cohesive PHP
4
+ `Symfony `_ is a reusable set of standalone, decoupled and cohesive PHP
5
5
components that solve common web development problems.
6
6
7
7
Instead of using these low-level components, you can use the ready-to-be-used
8
- Symfony2 full-stack web framework, which is based on these components... or
9
- you can create your very own framework. This book is about the latter.
8
+ Symfony full-stack web framework, which is based on these components... or
9
+ you can create your very own framework. This tutorial is about the latter.
10
10
11
- Why would you like to create your own framework ?
11
+ Why would you Like to Create your Own Framework ?
12
12
------------------------------------------------
13
13
14
14
Why would you like to create your own framework in the first place? If you
@@ -18,7 +18,7 @@ creating your own altogether. Most of the time, they are right but there are
18
18
a few good reasons to start creating your own framework:
19
19
20
20
* To learn more about the low level architecture of modern web frameworks in
21
- general and about the Symfony2 full-stack framework internals in particular;
21
+ general and about the Symfony full-stack framework internals in particular;
22
22
23
23
* To create a framework tailored to your very specific needs (just be sure
24
24
first that your needs are really specific);
@@ -34,55 +34,55 @@ a few good reasons to start creating your own framework:
34
34
35
35
This tutorial will gently guide you through the creation of a web framework,
36
36
one step at a time. At each step, you will have a fully-working framework that
37
- you can use as is or as a start for your very own. We will start with simple
38
- frameworks and more features will be added with time. Eventually, you will have
37
+ you can use as is or as a start for your very own. It will start with a simple
38
+ framework and more features will be added with time. Eventually, you will have
39
39
a fully-featured full-stack web framework.
40
40
41
41
And of course, each step will be the occasion to learn more about some of the
42
- Symfony2 Components.
42
+ Symfony Components.
43
43
44
44
.. tip ::
45
45
46
46
If you don't have time to read the whole book, or if you want to get
47
47
started fast, you can also have a look at `Silex `_, a micro-framework
48
- based on the Symfony2 Components. The code is rather slim and it leverages
49
- many aspects of the Symfony2 Components.
50
-
51
- Many modern web frameworks advertize themselves as being MVC frameworks. We
52
- won't talk about the MVC pattern as the Symfony2 Components are able to create
53
- any type of frameworks, not just the ones that follow the MVC architecture.
54
- Anyway, if you have a look at the MVC semantics, this book is about how to
55
- create the Controller part of a framework. For the Model and the View, it
56
- really depends on your personal taste and you can use any existing
57
- third-party libraries (Doctrine, Propel, or plain-old PDO for the Model; PHP
58
- or Twig for the View).
48
+ based on the Symfony Components. The code is rather slim and it leverages
49
+ many aspects of the Symfony Components.
50
+
51
+ Many modern web frameworks advertize themselves as being MVC frameworks. This
52
+ tutorial won't talk about the MVC pattern, as the Symfony Components are able to
53
+ create any type of frameworks, not just the ones that follow the MVC
54
+ architecture. Anyway, if you have a look at the MVC semantics, this book is
55
+ about how to create the Controller part of a framework. For the Model and the
56
+ View, it really depends on your personal taste and you can use any existing
57
+ third-party libraries (Doctrine, Propel or plain-old PDO for the Model; PHP or
58
+ Twig for the View).
59
59
60
60
When creating a framework, following the MVC pattern is not the right goal. The
61
61
main goal should be the **Separation of Concerns **; this is probably the only
62
62
design pattern that you should really care about. The fundamental principles of
63
- the Symfony2 Components are focused on the HTTP specification. As such, the
64
- frameworks that we are going to create should be more accurately labelled as
65
- HTTP frameworks or Request/Response frameworks .
63
+ the Symfony Components are focused on the HTTP specification. As such, the
64
+ framework that you are going to create should be more accurately labelled as a
65
+ HTTP framework or Request/Response framework .
66
66
67
- Before we start
68
- ---------------
67
+ Before You Start
68
+ ----------------
69
69
70
70
Reading about how to create a framework is not enough. You will have to follow
71
- along and actually type all the examples we will work on . For that, you need a
72
- recent version of PHP (5.3.8 or later is good enough), a web server (like
73
- Apache or NGinx ), a good knowledge of PHP and an understanding of Object
74
- Oriented programming.
71
+ along and actually type all the examples included in this tutorial . For that,
72
+ you need a recent version of PHP (5.3.9 or later is good enough), a web server
73
+ (like Apache, NGinx or PHP's built-in web server ), a good knowledge of PHP and
74
+ an understanding of Object Oriented programming.
75
75
76
- Ready to go? Let's start.
76
+ Ready to go? Read on!
77
77
78
78
Bootstrapping
79
79
-------------
80
80
81
- Before we can even think of creating our first framework, we need to talk
82
- about some conventions: where we will store our code, how we will name our
83
- classes, how we will reference external dependencies, etc.
81
+ Before you can even think of creating the first framework, you need to think
82
+ about some conventions: where you will store the code, how you will name the
83
+ classes, how you will reference external dependencies, etc.
84
84
85
- To store our framework, create a directory somewhere on your machine:
85
+ To store your new framework, create a directory somewhere on your machine:
86
86
87
87
.. code-block :: bash
88
88
@@ -92,20 +92,9 @@ To store our framework, create a directory somewhere on your machine:
92
92
Dependency Management
93
93
~~~~~~~~~~~~~~~~~~~~~
94
94
95
- To install the Symfony2 Components that we need for our framework, we are going
95
+ To install the Symfony Components that you need for your framework, you are going
96
96
to use `Composer `_, a project dependency manager for PHP. If you don't have it
97
- yet, `download and install `_ Composer now:
98
-
99
- .. code-block :: bash
100
-
101
- $ curl -sS https://getcomposer.org/installer | php
102
-
103
- Then, generate an empty ``composer.json `` file, where Composer will store the
104
- framework dependencies:
105
-
106
- .. code-block :: bash
107
-
108
- $ composer init -n
97
+ yet, :doc: `download and install Composer </cookbook/composer >` now.
109
98
110
99
Our Project
111
100
-----------
@@ -114,16 +103,15 @@ Instead of creating our framework from scratch, we are going to write the same
114
103
"application" over and over again, adding one abstraction at a time. Let's
115
104
start with the simplest web application we can think of in PHP::
116
105
117
- <?php
118
-
119
106
// framework/index.php
120
107
121
108
$input = $_GET['name'];
122
109
123
110
printf('Hello %s', $input);
124
111
125
- Use the PHP built-in server to test this great application in a browser
126
- (``http://localhost:4321/index.php?name=Fabien ``):
112
+ If you have PHP 5.4, you can use the PHP built-in server to test this great
113
+ application in a browser (``http://localhost:4321/index.php?name=Fabien ``).
114
+ Otherwise, use your own server (Apache, Nginx, etc.):
127
115
128
116
.. code-block :: bash
129
117
@@ -132,8 +120,7 @@ Use the PHP built-in server to test this great application in a browser
132
120
In the next chapter, we are going to introduce the HttpFoundation Component
133
121
and see what it brings us.
134
122
135
- .. _`Symfony2 ` : http://symfony.com/
123
+ .. _`Symfony ` : http://symfony.com/
136
124
.. _`documentation` : http://symfony.com/doc
137
125
.. _`Silex` : http://silex.sensiolabs.org/
138
126
.. _`Composer` : http://packagist.org/about-composer
139
- .. _`download and install` : https://getcomposer.org/doc/01-basic-usage.md
0 commit comments