From 8a50c9c00830f60b0074974910d2575c28b07c6c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 5 Nov 2014 12:05:40 -0500 Subject: [PATCH 1/2] Updating component usage to use composer require --- components/using_components.rst | 65 +++++++++++---------------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/components/using_components.rst b/components/using_components.rst index 6c9c13c003c..530451f4327 100644 --- a/components/using_components.rst +++ b/components/using_components.rst @@ -20,40 +20,33 @@ 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: +**2.** Open a terminal and use Composer to grab the library. -.. code-block:: json - - { - "require": { - "symfony/finder": "2.3.*" - } - } - -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.2.2`` or ``2.3.*``). - -You can research the component names and versions at `packagist.org`_. +.. code-block:: bash -**3.** `Install composer`_ if you don't already have it present on your system: + $ composer require symfony/finder -**4.** Download the vendor libraries and generate the ``vendor/autoload.php`` file: +The name ``symfony/finder`` is written at the top of the documentation for +whatever component you want. -.. code-block:: bash +.. tip:: - $ php composer.phar install + If you get a command not found for ``composer``, you'll need to + `Install composer`_. Depending on how you install, you may end up with + a ``composer.phar`` file in your directory. In that case, no worries! + Just run ``php composer.phar require symfony/finder``. -**5.** Write your code: +**3.** 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 + // File example: src/script.php // update this to the path to the "vendor/" directory, relative to this file - require_once '../vendor/autoload.php'; + require_once __DIR__.'../vendor/autoload.php'; use Symfony\Component\Finder\Finder; @@ -62,33 +55,18 @@ immediately:: // ... -.. tip:: - - If you want to use all of the Symfony Components, then instead of adding - them one by one: - - .. code-block:: json +Using all of the Components +--------------------------- - { - "require": { - "symfony/finder": "2.3.*", - "symfony/dom-crawler": "2.3.*", - "symfony/css-selector": "2.3.*" - } - } +If you want to use all of the Symfony Components, then instead of adding +them one by one, you can include the ``symfony/symfony`` package: - you can use: - - .. code-block:: json +.. code-block:: bash - { - "require": { - "symfony/symfony": "2.3.*" - } - } + $ composer require symfony/symfony - This will include the Bundle and Bridge libraries, which you may not - actually need. +This will also include the Bundle and Bridge libraries, which you may or +may not actually need. Now what? --------- @@ -100,4 +78,3 @@ And have fun! .. _Composer: http://getcomposer.org .. _Install composer: http://getcomposer.org/download/ -.. _packagist.org: https://packagist.org/ From d64fae2aac7566668673b1c648b54936f6535c28 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 6 Nov 2014 21:41:56 -0500 Subject: [PATCH 2/2] Adding details about a specific version --- components/using_components.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/using_components.rst b/components/using_components.rst index 530451f4327..acd7ce449ec 100644 --- a/components/using_components.rst +++ b/components/using_components.rst @@ -27,7 +27,7 @@ Using the Finder Component $ composer require symfony/finder The name ``symfony/finder`` is written at the top of the documentation for -whatever component you want. +whatever component you want. .. tip:: @@ -36,6 +36,12 @@ whatever component you want. a ``composer.phar`` file in your directory. In that case, no worries! Just run ``php composer.phar require symfony/finder``. +If you know you need a specific version of the library, add that to the command: + +.. code-block:: bash + + $ composer require symfony/finder:~2.3 + **3.** Write your code! Once Composer has downloaded the component(s), all you need to do is include