14

I see there is already a question but it did not answer the question

How can I install a bundle in the /src directory?

Reason I would like to do this is for development and deployment, so

  • I don't have to check in Symfony's base code into my subversion repo
  • I could use Composer to deploy

Looking over the Composer docs some more I did come across this:

vendor-dir: Defaults to vendor. You can install dependencies into a different directory if you want to.

Could I set this at a Bundle level? or is this for the overall install?

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
  • Do you use Symfony2.1? And why would you do that, I can't see any benefit. If you change the `vendor-dir` every vendor will be installed in `/src` which means that the complete `vendor` directory will be copied in the `/src` directory, you don't want that. – Wouter J Nov 13 '12 at 07:00
  • Why don't you just ignore the vendor folder and then use composer on your production server to install the dependencies? Maybe you can describe your problem a bit more, I guess there is a better way then installing dependencies into the src folder. – Sgoettschkes Nov 13 '12 at 08:31
  • @WouterJ for all the normal installation except my bundle I would follow the current setup and install them in /vendor directory. Just for my bundle I would like to install in the /src directory. – Phill Pafford Nov 13 '12 at 13:03
  • @Sgoettschkes see above comment as SO can't yet notify multiple users at once – Phill Pafford Nov 13 '12 at 13:04
  • @PhillPafford I think you can't do that. And if you do it only because you think it feels better if you place bundles in `src`, don't do it. It don't make sense for the project or autoloader and the dir structure is already very bad because of composer and some packages using namespaces. – Wouter J Nov 13 '12 at 14:30
  • 4
    Dependencies do not belong in your project's src/ - it's not possible (unless you put it all in), and it's like that because it makes no sense really. I don't quite get your reasons in the question, just add `vendor` to `svn:ignore` of the project root, and then all is well. You commit your lock file, and run composer install on the production machine to get the dependencies installed. – Seldaek Nov 13 '12 at 16:19
  • @Seldaek The code I want in the /src directory is a in-house bundle and not considered a vendor. Each team can pull in different Bundles from the other teams and I would like to use Composer to put those Bundles in the /src directory. – Phill Pafford Nov 19 '12 at 18:25
  • @WouterJ The code I want in the /src directory is a in-house bundle and not considered a vendor. Each team can pull in different Bundles from the other teams and I would like to use Composer to put those Bundles in the /src directory. – Phill Pafford Nov 19 '12 at 18:25
  • @Sgoettschkes The code I want in the /src directory is a in-house bundle and not considered a vendor. Each team can pull in different Bundles from the other teams and I would like to use Composer to put those Bundles in the /src directory. – Phill Pafford Nov 19 '12 at 18:26
  • @PhillPafford in hour dependencies should go in vendor too IMO. It doesn't prevent you from going in vendor/foo/bar and committing stuff if you need, but there should be a clear distinction between *application code* in src/ and *reusable code* in vendor/. It's good to make this distinction I believe because reusable code should be held to higher standards and provide more decoupling/options than application code (ideally both would, but in practice one often needs to compromise). – Seldaek Nov 19 '12 at 19:09
  • @Seldaek but what if they both qualify for Application Code? So I'm just adding that functionality to the src as well. I do understand about keeping things separate but I'm asking is there a way to put this in the /src directory? Thanks again – Phill Pafford Nov 20 '12 at 00:19
  • @PhillPafford They don't qualify as *application specific* code if they are in an external repo IMO. If they are application specific, why would you move them out of the main application's repo? – Seldaek Nov 20 '12 at 08:32
  • @Seldaek Some of it is Legacy code which needs to be refactored, some are older libraries that are still used, there an other conditions as well. I understand the normal or correct way in structuring the code but I'm not asking the correct way. Is there some way to place the bundle in the /src directory? – Phill Pafford Nov 20 '12 at 13:18
  • As long as it's OOP code that can be autoloaded, it's path should not matter. The fact that it's legacy or not shouldn't change that. Anyway no there is no easy way to do that, except with a custom installer. – Seldaek Nov 20 '12 at 15:37
  • @Seldaek is there documentation on the Custom Installer? – Phill Pafford Nov 20 '12 at 15:58
  • @room13 Could I get your opinion on this as well? – Phill Pafford Nov 20 '12 at 18:19
  • @naderman Could I get your feedback as well? – Phill Pafford Nov 20 '12 at 18:21
  • 1
    @PhillPafford here is a link to the [composer docs](http://getcomposer.org/doc/) - I'll let you figure out which page contains info about Custom Installers. – Seldaek Nov 20 '12 at 19:20
  • @Seldaek I will except this as the answer http://getcomposer.org/doc/articles/custom-installers.md Thank you – Phill Pafford Nov 21 '12 at 00:27

4 Answers4

22

I know this is late, but in case anyone is searching for an answer that I painstakingly (hours and hours) found: vendor-dir

The documentation says:

By setting this var you can make composer install the dependencies into a directory other than vendor

Example:

{
    "config": {
        "vendor-dir": "website/password/vendor/"
    }
}

From this doc and this doc

Again, hope to save anyone else a couple hours.

9
{
    "extra": {
        "installer-paths": {
            "sites/example.com/modules/{$name}": ["vendor/package"]
        }
    }
}

Read more.

user3021267
  • 91
  • 1
  • 2
  • 3
    Be aware use of this won't work unless the dependency is setup to use `composer/installers`. This thread discusses the issue (albeit without a satisfying conclusion): https://github.com/composer/composer/issues/1948 – Quinn Comendant Apr 14 '15 at 05:15
2

I have implemented this composer plugin to install packages into user (custom) defined folders you can just include it in your composer.json, follow the example and tell me if you have more questions :)

https://github.com/mnsami/composer-custom-directory-installer

composer-custom-directory-installer

A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.

This is not another composer-installer library for supporting non-composer package types i.e. application .. etc. This is only to add the flexability of installing composer packages outside the vendor folder. This package only supports composer package types,

https://getcomposer.org/doc/04-schema.md#type

The type of the package. It defaults to library.

Package types are used for custom installation logic. If you have a package that needs some special logic, you can define a custom type. This could be a symfony-bundle, a wordpress-plugin or a typo3-module. These types will all be specific to certain projects, and they will need to provide an installer capable of installing packages of that type.

How to use

  • Include the composer plugin into your composer.json require section::
"require":{
    "php": ">=5.3",
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "monolog/monolog": "*"
  }
  • In the extra section define the custom directory you want to the package to be installed in::
  "extra":{
    "installer-paths":{
      "./monolog/": ["monolog/monolog"]
    }

by adding the installer-paths part, you are telling composer to install the monolog package inside the monolog folder in your root directory.

  • As an added new feature, we have added more flexibility in defining your download directory same like the composer/installers, in other words you can use variables like {$vendor} and {$name} in your installer-path section:
"extra": {
    "installer-paths": {
        "./customlibs/{$vendor}/db/{$name}": ["doctrine/orm"]
    }
}

the above will manage to install the doctrine/orm package in the root folder of your project, under customlibs.

Note

Composer type: project is not supported in this installer, as packages with type project only make sense to be used with application shells like symfony/framework-standard-edition, to be required by another package.

mina.nsami
  • 411
  • 3
  • 7
2

If you find composer's custom installers too complex or rigid, and you can plan what types of systems you will be deploying to, you might consider using post-install scripts.

Here's an example that creates a symlink from a package installed under vendors to the location where it might be expected:

"scripts": {
    "post-install-cmd": [
        "test -d vendor/foo/bar && ln -s ../vendor/foo/bar lib/bar"
    ]
}

This will create a symlink at lib/bar/ pointing to vendor/foo/bar/.

Quinn Comendant
  • 9,686
  • 2
  • 32
  • 35