18

I've just started using composer with PHPStorm 'cause I'm bored of downloading dependencies from github manually. But there are some things I can't understand.

Composer always downloads files into /vendor folder. Like if I add Twitter Bootstrap - it will be downloaded to /vendor/twitter/bootstrap folder. But I need it to be into my /webroot/bootstrap/ directory. How do you move this files? Because if I move it manually - they won't be updated later using composer update command.

Or if I use micro php framevork slim. I've added slim/slim dependency. But it will be placed into /vendor/slim/slim/...

So what should I do? Use Phing or some other deployment tool to move files from /vendor to desired destination? What do you use?

That's not exactly whar I need, but it works for css/js/etc. http://www.phpclasses.org/blog/package/8429/post/1-Using-Composer-to-Install-JavaScript-CSS-and-Images-Under-the-Web-Document-Directory.html

Alexey
  • 353
  • 2
  • 3
  • 11
  • You can simply `require vendor/autoload.php;` and then it doesn't really matter *where* the directory is. – Ja͢ck Feb 17 '14 at 10:29
  • What's wrong with Slim being in the vendors folder? For webroot resources, I'm using [`bower`](http://bower.io) instead of `composer` for that, or you could symlink the files into the webroot directory. – deceze Feb 17 '14 at 10:30
  • @Jack, autoloading works only for php classes. That's ok. But with static like images/css/js. – Alexey Feb 17 '14 at 10:41
  • @deceze, symlink looks good, but I develop under windows. Not a goot choice, I know. Here I'm looking for a best practice. What is the common way of using composer. You've suggest symlink - thank you, I think that's a good choice. – Alexey Feb 17 '14 at 10:43
  • 1
    possible duplicate of [How to specify Composer install path?](http://stackoverflow.com/questions/11883374/how-to-specify-composer-install-path) – Ja͢ck Feb 17 '14 at 10:54
  • 1
    @Jack, not exactly. I'm looking for a best practice, 'cause I'm not used to composer. If moving files is bad - ok, I want to know a right way to develop. – Alexey Feb 17 '14 at 10:58
  • @Alexey, you'll want to keep your code separated from 3rd party code (such as the Slim framework). The easiest way is to use the `vendor` map for that and a `src` map for your own code. Of course javascript and css need to be web-accessible. – Arjan Feb 17 '14 at 12:01
  • @Arjan, I'm sorry, but I don't understand. Maybe 'cause lack of english. What do you mean by vendor and src map? Mapping where and how it should help me separate my code from 3rd party one? – Alexey Feb 17 '14 at 14:52
  • 1
    @Alexey: My bad. I should have used folder instead of map. Composer uses `/vendor/` for 3rd party code and you could use `/src` for your source code. That way you keep them separated. – Arjan Feb 18 '14 at 09:42

3 Answers3

31
"config": {
    "vendor-dir": "path/to/wherever"
},

in your composer.json file

George Wilson
  • 5,595
  • 5
  • 29
  • 42
  • 1
    This saved me! Using Netbeans composer is in root as vendor is. But if you, like me, created folder eg. `code` just for code part of project that will be eventually rsync-ed to production server, with this config I have moved vendor inside code subdir `code/vendor/` keeping composer in root of nb project. – Vladimir Vukanac Oct 22 '14 at 22:23
  • Unfortunately Class mapping is unable to change per ENV (dev, production). In local have code, but don't have on production. – Vladimir Vukanac Oct 22 '14 at 23:51
2

The documentation states that you can do this:

{
    "extra": {
        "installer-paths": {
            "sites/example.com/modules/{$name}": ["vendor/package"]
        }
    }
}
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
0

This question is answered here.

Vendor directory is a Composer convention. Good programming practice is to prefer convention over configuration. You can reference you files and classes in a number of ways with Composer.

Community
  • 1
  • 1
Miroslav Trninic
  • 3,327
  • 4
  • 28
  • 51
  • I don't believe that the OP's question is answered here or in the question you refer to. I think the OP has some vendor files that should pref be outside of the web root and others (like bootstrap, angular etc) that obviously needs to be under the web root - so two vendor destinations for one project – Jannie Theunissen Sep 25 '14 at 12:02
  • As JannieT said. This is not the answer to the original question. Also the hint is correct. – Marcel Lange Dec 22 '16 at 08:53