Skip to content

Commit 8b3f102

Browse files
committed
Merge pull request #1993 from Sgoettschkes/issue1951
Changing description of symfony installation to composer
2 parents 44a963f + 16333e1 commit 8b3f102

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

book/from_flat_php_to_symfony2.rst

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -420,34 +420,36 @@ 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 its 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
432+
.. code-block:: json
434433
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';
434+
{
435+
"require": {
436+
"symfony/symfony": "2.1.*"
437+
},
438+
"autoload": {
439+
"files": ["model.php","controller.php"]
440+
}
441+
}
442+
443+
Next, `download Composer`_ and then run the following command, which will download Symfony
444+
into a vendor/ directory:
440445

441-
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
442-
$loader->registerNamespaces(array(
443-
'Symfony' => __DIR__.'/../vendor/symfony/symfony/src',
444-
));
446+
.. code-block:: bash
445447
446-
$loader->register();
448+
$ php composer.phar install
447449
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.
450+
Beside downloading your dependencies, Composer generates a ``vendor/autoload.php`` file,
451+
which takes care of autoloading for all the files in the Symfony Framework as well as
452+
the files mentioned in the autoload section of your `composer.json`.
451453

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

461463
<?php
462464
// index.php
463-
require_once 'app/bootstrap.php';
465+
require_once 'vendor/bootstrap.php';
464466

465467
use Symfony\Component\HttpFoundation\Request;
466468
use Symfony\Component\HttpFoundation\Response;
@@ -752,7 +754,7 @@ Learn more from the Cookbook
752754
* :doc:`/cookbook/controller/service`
753755

754756
.. _`Doctrine`: http://www.doctrine-project.org
755-
.. _`download Symfony`: http://symfony.com/download
757+
.. _`download Composer`: http://getcomposer.org/download/
756758
.. _`Routing`: https://github.com/symfony/Routing
757759
.. _`Templating`: https://github.com/symfony/Templating
758760
.. _`KnpBundles.com`: http://knpbundles.com/

0 commit comments

Comments
 (0)