@@ -64,9 +64,9 @@ Propel, or plain-old PDO for the Model; PHP or Twig for the View).
6464When creating a framework, following the MVC pattern is not the right goal.
6565The main goal should be the Separation of Concerns; I actually think that this
6666is 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.
7070
7171Before we start
7272---------------
@@ -97,20 +97,18 @@ Components Installation
9797~~~~~~~~~~~~~~~~~~~~~~~
9898
9999To 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 :
102102
103103.. code-block :: javascript
104104
105105 {
106106 " require" : {
107- " symfony/class-loader" : " 2.1.*"
108107 }
109108 }
110109
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:
114112
115113.. code-block :: sh
116114
@@ -121,13 +119,7 @@ dependencies, download the composer binary and run it:
121119 $ php composer.phar install
122120
123121 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.
131123
132124Naming Conventions and Autoloading
133125~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -137,42 +129,8 @@ require the file where a class is defined before being able to use it. But
137129with some conventions, we can just let PHP do the hard work for us.
138130
139131Symfony2 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.
176134
177135Our Project
178136-----------
@@ -183,6 +141,8 @@ start with the simplest web application we can think of in PHP::
183141
184142 <?php
185143
144+ // framework/index.php
145+
186146 $input = $_GET['name'];
187147
188148 printf('Hello %s', $input);
0 commit comments