4

How do I have do modify my composer.json to install directly into the src-dir (Symfony/src)?

{
"name": "acme/example-bundle",
"type": "symfony-bundle",
"license": "MIT",
"require": {
    "php": ">=5.3.2",
    "symfony/framework-bundle": "2.1.*"
},
"suggest": {
    "doctrine/doctrine-bundle": "*"
},
"autoload": {
    "psr-0": { "Acme": "src/" }
},
"target-dir": "../../src/Acme/ExampleBundle"

}

Florent
  • 12,310
  • 10
  • 49
  • 58
bodokaiser
  • 15,122
  • 22
  • 97
  • 140
  • 1
    I totaly agree with the accepted answer. However, there are situations where you have no choice. What options do I have to get an dependendy installed in `src` instead of `vendor`? – BetaRide Sep 26 '12 at 11:22
  • 1
    Did you ever get this working? I have the same issue and wanted to know if you found a solution for putting a Bundle in the src/ directory – Phill Pafford Nov 09 '12 at 21:05

2 Answers2

8

actually it's not a good idea to install vendor packages to the src dir because vendor packages should not be edited and the src directory is meant for code that is edited in the development process.

one reason that comes to my mind is that you want do modify these packages. if this is the point, you'd better be off using git submodules because composer only has a one way flow, meaning changes can only come from the source of the vendor package and there is no upstream to the source.

i use git submodules for the bundles in my projects that are not project specific and thus reside in their own git repository but are actively developed during in the project.

room13
  • 1,922
  • 1
  • 15
  • 28
  • Ok, youre right with this actually. Thank you for the advice!# – bodokaiser Jun 19 '12 at 18:13
  • 6
    This is actually incorrect. If you specify --prefer-source composer will try to clone git repositories and checkout svn repositories for your vendors so you can develop and commit in these repositories. – naderman Jun 19 '12 at 19:20
  • oh... didn't know that. i had the issue with the old vendors script in sf 2.0, that the repositories would be checked out as readonly and a commit/push was not possible. could you post an example on how i can include a github repository so i can push back? thanx – room13 Jun 20 '12 at 11:37
  • Simply run php composer.phar install --prefer-source and it will do that for you. – naderman Jun 26 '12 at 17:43
  • I would like to run the command composer require comapny/bundle:1.* and install the bundle this way for deployments, suggestions? – Phill Pafford Nov 09 '12 at 21:07
  • I realize that you're advising best practices on how to do this kind of thing. However, you should try to also provide an actual answer to the question because it could be applicable to other users in a similar, yet slightly different scenario and isn't any kind of security risk in doing so. – Charles Sprayberry May 14 '13 at 01:11
5

The src directory of a PHP/Symfony project is typically used only for the code of that project. Code you install as a dependency goes into the vendor directory.

This makes it easy to keep track of which code is part of the project itself and which code is maintained in a separate repository.

As such you should not install a bundle from a separate repository into your src directory. Bundles in Symfony work just fine if they are located in the vendor directory just like many of the core framework bundles.

naderman
  • 1,060
  • 11
  • 12