1

I am using the Composer package Omnipay in my project and I want to add a new class to the package (in my case it is support for a new payment gateway). The naming does not conflict with anything and it follows the same naming and structure conventions as sibling folders. However, when I run composer update it deletes my whole folder of changes even though it didn't need to. Is there a way I can tell composer not to delete that directory?

nathanjosiah
  • 4,441
  • 4
  • 35
  • 47

2 Answers2

0

As far as I'm aware, you cannot add to a Composer package as it is external and therefore out of your control. You should treat the packages as libraries only, and add all classes into your own project, ensuring that the packages you need are still set up in your .json file

Thomas Marchant
  • 208
  • 4
  • 14
0

Leave everything under /vendor alone, don't change any files there. You should treat libraries as external dependencies - don't check them into source control or change them in any way. Just reference them in your own code.

If you need to customize a composer library, you can either work around it in your own code (most PHP libraries support dependency injection, which will let you override any of the libraries' classes), or alternatively you can fork the library on github, then reference your own fork in composer.json, or submit the pull request so everyone can benefit from it.

Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
  • I will probably end up forking it. Seems a bit stupid that this type of extension isn't possible. – nathanjosiah Jul 14 '13 at 22:54
  • 1
    It's not stupid - you shouldn't modify external libraries, otherwise you won't be able to update them in future. Just extend individual classes in your own code, that's the OO way. – Adrian Macneil Jul 15 '13 at 09:55
  • The thing is, they aren't external and the type of extension I am doing is safe even for the future – nathanjosiah Jul 15 '13 at 14:30