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?

- 4,441
- 4
- 35
- 47
-
Are you sure that your package json is correct? Specifies working github url etc? – Arkadiusz 'flies' Rzadkowolski Jul 11 '13 at 17:21
-
I am including it via `"require": {"omnipay/omnipay": "0.9.*"}` – nathanjosiah Jul 11 '13 at 17:23
-
What does composer.phar update output says? – Arkadiusz 'flies' Rzadkowolski Jul 11 '13 at 17:27
-
Nothing unless there is an update to something. The package works and my additions work, but when the package has an update composer deletes my additions – nathanjosiah Jul 11 '13 at 17:34
-
But that's how updates work - whole package (from vendor dir) is deleted. You should use your namespaced Classes in seperate folder - this way class will not get deleted once package is updated. – Arkadiusz 'flies' Rzadkowolski Jul 11 '13 at 17:36
2 Answers
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

- 208
- 4
- 14
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.

- 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
-
1It'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