@@ -64,9 +64,9 @@ Propel, or plain-old PDO for the Model; PHP or Twig for the View).
64
64
When creating a framework, following the MVC pattern is not the right goal.
65
65
The main goal should be the Separation of Concerns; I actually think that this
66
66
is the only design pattern that you should really care about. The fundamental
67
- principles of the Symfony2 Components are centered around the HTTP
68
- specification. As such, the frameworks that we are going to create should be
69
- more accurately labelled as HTTP frameworks or Request/Response frameworks.
67
+ principles of the Symfony2 Components are focused on the HTTP specification.
68
+ As such, the frameworks that we are going to create should be more accurately
69
+ labelled as HTTP frameworks or Request/Response frameworks.
70
70
71
71
Before we start
72
72
---------------
@@ -97,20 +97,18 @@ Components Installation
97
97
~~~~~~~~~~~~~~~~~~~~~~~
98
98
99
99
To install the Symfony2 Components that we need for our framework, we are
100
- going to use `Composer `_, a project dependency manager for PHP. First, list
101
- your dependencies in a ``composer.json `` file:
100
+ going to use `Composer `_, a project dependency manager for PHP. Create a
101
+ ``composer.json `` file, where we will list our dependencies :
102
102
103
103
.. code-block :: javascript
104
104
105
105
{
106
106
" require" : {
107
- " symfony/class-loader" : " 2.1.*"
108
107
}
109
108
}
110
109
111
- Here, we tell Composer that our project depends on the Symfony2 ClassLoader
112
- component, version 2.1.0 or later. To actually install the project
113
- dependencies, download the composer binary and run it:
110
+ The file is empty for now as we do not depend on anything yet. To install the
111
+ project dependencies, download the composer binary and run it:
114
112
115
113
.. code-block :: sh
116
114
@@ -121,13 +119,7 @@ dependencies, download the composer binary and run it:
121
119
$ php composer.phar install
122
120
123
121
After running the ``install `` command, you must see a new ``vendor/ ``
124
- directory that must contain the Symfony2 ClassLoader code.
125
-
126
- .. note ::
127
-
128
- Even if we highly recommend you the use of Composer, you can also download
129
- the archives of the components directly or use Git submodules. That's
130
- really up to you.
122
+ directory.
131
123
132
124
Naming Conventions and Autoloading
133
125
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -137,42 +129,8 @@ require the file where a class is defined before being able to use it. But
137
129
with some conventions, we can just let PHP do the hard work for us.
138
130
139
131
Symfony2 follows the de-facto PHP standard, `PSR-0 `_, for class names and
140
- autoloading. The Symfony2 ClassLoader Component provides an autoloader that
141
- implements this PSR-0 standard and most of the time, the Symfony2 ClassLoader
142
- is all you need to autoload all your project classes.
143
-
144
- Create an empty autoloader in a new ``autoload.php `` file:
145
-
146
- .. code-block :: php
147
-
148
- <?php
149
-
150
- // framework/autoload.php
151
-
152
- require_once __DIR__.'/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
153
-
154
- use Symfony\Component\ClassLoader\UniversalClassLoader;
155
-
156
- $loader = new UniversalClassLoader();
157
- $loader->register();
158
-
159
- You can now run the ``autoload.php `` on the CLI, it should not do anything and
160
- should not throw any error:
161
-
162
- .. code-block :: sh
163
-
164
- $ php autoload.php
165
-
166
- .. tip ::
167
-
168
- The Symfony website has more information about the `ClassLoader `_
169
- component.
170
-
171
- .. note ::
172
-
173
- Composer automatically creates an autoloader for all your installed
174
- dependencies; instead of using the ClassLoader component, you can also
175
- just require ``vendor/.composer/autoload.php ``.
132
+ autoloading and Composer generates such an autoloader for all the dependencies
133
+ it manages; it can be enabled by requiring the ``vendor/autoload.php `` file.
176
134
177
135
Our Project
178
136
-----------
@@ -183,6 +141,8 @@ start with the simplest web application we can think of in PHP::
183
141
184
142
<?php
185
143
144
+ // framework/index.php
145
+
186
146
$input = $_GET['name'];
187
147
188
148
printf('Hello %s', $input);
0 commit comments