Skip to content

Commit 229dd4f

Browse files
committed
Changing description of symfony installation to composer
1 parent 56d7ff0 commit 229dd4f

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

book/from_flat_php_to_symfony2.rst

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -420,34 +420,29 @@ Why should you have to reinvent solutions to all these routine problems?
420420
Add a Touch of Symfony2
421421
~~~~~~~~~~~~~~~~~~~~~~~
422422

423-
Symfony2 to the rescue. Before actually using Symfony2, you need to make
424-
sure PHP knows how to find the Symfony2 classes. This is accomplished via
425-
an autoloader that Symfony provides. An autoloader is a tool that makes it
426-
possible to start using PHP classes without explicitly including the file
427-
containing the class.
423+
Symfony2 to the rescue. Before actually using Symfony2, you need to download
424+
it. This can be done by using composer, which takes care of downloading the
425+
correct version and all it's dependencies and provides an autoloader. An
426+
autoloader is a tool that makes it possible to start using PHP classes
427+
without explicitly including the file containing the class.
428428

429-
First, `download Symfony`_ and place it into a ``vendor/symfony/symfony/`` directory.
430-
Next, create an ``app/bootstrap.php`` file. Use it to ``require`` the two
431-
files in the application and to configure the autoloader:
429+
In your root directory, create a ``composer.json`` file with the following
430+
content:
432431

433-
.. code-block:: html+php
434-
435-
<?php
436-
// bootstrap.php
437-
require_once 'model.php';
438-
require_once 'controllers.php';
439-
require_once 'vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
432+
.. code-block:: json
440433
441-
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
442-
$loader->registerNamespaces(array(
443-
'Symfony' => __DIR__.'/../vendor/symfony/symfony/src',
444-
));
445-
446-
$loader->register();
447-
448-
This tells the autoloader where the ``Symfony`` classes are. With this, you
449-
can start using Symfony classes without using the ``require`` statement for
450-
the files that contain them.
434+
{
435+
"require": {
436+
"symfony/symfony": "2.1.*"
437+
},
438+
"autoload": {
439+
"files": ["model.php","controller.php"]
440+
}
441+
}
442+
443+
After installing your dependencies, composer has generated ``vendor/autoload.php``,
444+
which takes care to include all files from the symfony framework as well as
445+
the files mentioned in the autoload section of your composer.json.
451446

452447
Core to Symfony's philosophy is the idea that an application's main job is
453448
to interpret each request and return a response. To this end, Symfony2 provides
@@ -460,7 +455,7 @@ the HTTP response being returned. Use them to improve the blog:
460455

461456
<?php
462457
// index.php
463-
require_once 'app/bootstrap.php';
458+
require_once 'vendor/bootstrap.php';
464459

465460
use Symfony\Component\HttpFoundation\Request;
466461
use Symfony\Component\HttpFoundation\Response;

0 commit comments

Comments
 (0)