.. index:: single: Components; Installation single: Components; Usage How to Install and Use the Symfony2 Components ============================================== If you're starting a new project (or already have a project) that will use one or more components, the easiest way to integrate everything is with `Composer`_. Composer is smart enough to download the component(s) that you need and take care of autoloading so that you can begin using the libraries immediately. This article will take you through using the :doc:`/components/finder`, though this applies to using any component. Using the Finder Component -------------------------- **1.** If you're creating a new project, create a new empty directory for it. **2.** Create a new file called ``composer.json`` and paste the following into it: .. code-block:: json { "require": { "symfony/finder": "2.1.*" } } If you already have a ``composer.json`` file, just add this line to it. You may also need to adjust the version (e.g. ``2.1.1`` or ``2.2.*``). You can research the component names and versions at `packagist.org`_. **3.** `Install composer`_ if you don't already have it present on your system: **4.** Download the vendor libraries and generate the ``vendor/autoload.php`` file: .. code-block:: bash $ php composer.phar install **5.** Write your code: Once Composer has downloaded the component(s), all you need to do is include the ``vendor/autoload.php`` file that was generated by Composer. This file takes care of autoloading all of the libraries so that you can use them immediately:: // File: src/script.php // update this to the path to the "vendor/" directory, relative to this file require_once '../vendor/autoload.php'; use Symfony\Component\Finder\Finder; $finder = new Finder(); $finder->in('../data/'); // ... .. tip:: If you want to use all of the Symfony2 Components, then instead of adding them one by one: .. code-block:: json { "require": { "symfony/finder": "2.1.*", "symfony/dom-crawler": "2.1.*", "symfony/css-selector": "2.1.*" } } you can use: .. code-block:: json { "require": { "symfony/symfony": "2.1.*" } } This will include the Bundle and Bridge libraries, which you may not actually need. Now What? --------- Now that the component is installed and autoloaded, read the specific component's documentation to find out more about how to use it. And have fun! .. _Composer: http://getcomposer.org .. _Install composer: http://getcomposer.org/download/ .. _packagist.org: https://packagist.org/