Skip to content

[Cookbook] How to use components #1899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cookbook/workflow/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Workflow

new_project_git
new_project_svn
new_project_components
68 changes: 68 additions & 0 deletions cookbook/workflow/new_project_components.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. index::
single: Workflow; Components

How to start a new project using Symfony2 Components
====================================================

Using Finder Component
----------------------

1. Create a new empty folder.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dot should be a semi colon.


2. Create a new file called ``composer.json`` and paste the following into it:

.. code-block:: json

{
"require": {
"symfony/finder": "2.1.*"
}
}

3. Download vendor libraries and generate ``vendor/autoload.php`` file:

.. code-block:: bash

$ php composer.phar install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine these two steps (2 and 3) by using:

$ php composer.phar require symfony/finder:2.1.*


4. Write your code:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove line 29 and 30 and replace the single colon by 2 colons.


.. code-block:: php

<?php

// File: src/script.php

require_once '../vendor/autoload.php';

use Symfony\Component\Finder\Finder;

$finder = new Finder();
$finder->in('../data/');

...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be // ...


.. tip::

If you want to use all the Symfony2 Component, then instead of adding them one by one:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recommend this because it requries not only the components, but the complete Symfony2 core Framework including Twig, the Doctrine-, Monolog-, Propel-, Swiftmailer- and Twig Bridges and the Framework-, Security-, Twig- and WebProfiler Bundles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but all the components are in the same folder. Otherwise they are in separate folders.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but who cares when using composer ? you don't need to bother about the way stuff are stored in the vendor/ folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof Ok. You're right.

Nevertheless, I still think, that the best method to write a script that can access any component is to use:

{
    "require": {
        "symfony/symfony": "2.1.*"
    }
}


.. code-block:: json

{
"require": {
"symfony/finder": "2.1.*",
"symfony/dom-crawler": "2.1.*",
"symfony/css-selector": "2.1.*"
...
}
}

use:

.. code-block:: json

{
"require": {
"symfony/symfony": "2.1.*"
}
}