1
1
.. index ::
2
2
single: Workflow; Components
3
3
4
- How to start a new project using Symfony2 Components
5
- ====================================================
4
+ How to start a new project using the Symfony2 Components
5
+ ========================================================
6
+
7
+ If you're starting a new project that uses one or more Symfony2 components
8
+ (or adding the components to an existing project), the easiest way to integrate
9
+ everything is with Composer. Composer is smart enough to download the component(s)
10
+ that you need and take care of autoloading so that you can begin using the
11
+ libraries immediately.
12
+
13
+ This article will take you through using the :doc: `/components/finder `, though
14
+ this applies to using any component.
6
15
7
16
Using Finder Component
8
17
----------------------
9
18
10
- 1. Create a new empty folder .
19
+ ** 1. ** Create a new empty directory for your project .
11
20
12
- 2. Create a new file called ``composer.json `` and paste the following into it:
21
+ ** 2. ** Create a new file called ``composer.json `` and paste the following into it:
13
22
14
- .. code-block :: json
23
+ .. code-block :: json
15
24
16
- {
17
- "require" : {
18
- "symfony/finder" : " 2.1.*"
19
- }
25
+ {
26
+ "require" : {
27
+ "symfony/finder" : " 2.1.*"
20
28
}
29
+ }
21
30
22
- 3. Download vendor libraries and generate ``vendor/autoload.php `` file:
31
+ If you already have a ``composer.json `` file, just add this line to it. You
32
+ may also need to adjust the version (e.g. ``2.1.1 `` or ``2.2.* ``).
23
33
24
- .. code-block :: bash
34
+ You can research the component names and versions at _packagist.org.
25
35
26
- $ php composer.phar install
36
+ ** 3. ** Download the vendor libraries and generate the `` vendor/autoload. php`` file:
27
37
28
- 4. Write your code:
38
+ .. code-block :: bash
29
39
30
- .. code-block :: php
40
+ $ php composer.phar install
31
41
32
- <?php
42
+ 4. Write your code:
43
+
44
+ Once Composer has downloaded the component(s), all you need to do is include
45
+ the ``vendor/autoload.php `` file that was generated by Composer. This file
46
+ takes care of autoloading all of the libraries so that you can use them
47
+ immediately::
33
48
34
49
// File: src/script.php
35
50
@@ -44,7 +59,8 @@ Using Finder Component
44
59
45
60
.. tip ::
46
61
47
- If you want to use all the Symfony2 Component, then instead of adding them one by one:
62
+ If you want to use all of the Symfony2 Components, then instead of adding
63
+ them one by one:
48
64
49
65
.. code-block :: json
50
66
@@ -57,7 +73,7 @@ Using Finder Component
57
73
}
58
74
}
59
75
60
- use:
76
+ you can use:
61
77
62
78
.. code-block :: json
63
79
@@ -66,3 +82,8 @@ Using Finder Component
66
82
"symfony/symfony" : " 2.1.*"
67
83
}
68
84
}
85
+
86
+ This will include the Bundle and Bridge libraries, which you may not
87
+ actually need.
88
+
89
+ .. _packagist.org : https://packagist.org/
0 commit comments