I have the following problem: I have an old project which uses Laravel 4.2, PHP 5.5.9 and Composer. I’m trying to set it up on a different computer (With Laravel 4.2.2 and PHP 5.6) but one of the required packages has a dependency which is missing because whoever was managing that GitHub account decided to remove it. Thus, the required package can’t be installed via Composer.
Now, the old project has these packages downloaded and I can copy both of them manually. What I don’t know, is how to correctly add them to the project this way and stop composer from trying to download them anew.
No code examples give as none are needed.
Advertisement
Answer
If you have the files, and you won’t be able to continue using composer to manage that package (e.g. for updates, removal, etc), then you just need to treat the files as if they belonged to your project.
It’s hard to give you specifics without knowing more about the package you want to use, but a general approach would be:
Let’s say that the package you want to use is funtastic/foobar
. If you have the files from your old vendor
, we just need the directory inside the vendor/funtastic
, which might be called foobar
.
First, copy your files within your project. Since they belong to a different namespace than the rest of your application, I personally wouldn’t put them in src
. You could put them in a new directory called lib
, for example.
So now your file structure would be something like:
project-root-dir ├── public │ └── index.php ├── vendor/ ├── lib/ │ └── foobar/ │ └── some files ... │ └── src/ ├── composer.json ├── composer.lock
Now you need to check the package’s composer.json
, specifically the autoload
section. It might say something like:
"autoload": { "psr-4": { "Funtastic\FooBar\": "src" } }
You now need to go to your application’s composer.json
, find the autoload
section and edit it so it includes the FuntasticFooBar
namespace. Assuming you already had an App
namespace:
"autoload": { "psr-4": { "App\": "src/", "Funtastic\FooBar\": "lib/foobar/src" }
Additionally, you also need to check the require
section of the original package and see if it depends on any package and add those packages to your application’s “require” section in its composer.json
.
With all this in place and the composer.json
correctly edited, you could simply regenerate the autoloader (composer dump-autload
) and you would be ready to go.
Obviously, since I don’t know the specifics of your package and project, you’ll have to adjust these instructions to your specific case, but it should not take long to have the package working within your application.
Alternatively, if you want to continue treating this package as if it were an “external” dependency:
- Zip all the package files into
package.zip
and put it intobase_dir/lib
- Add the following to your composer.json:
(Solution originally proposed by the question author themselves).
"repositories": [ { "type": "package", "package": { "name": "vendor/name", "version": "1.0", "dist": { "url": "lib/package.zip", "type": "zip" } } } ],
With this the files will exist twice in your project: as a “repository”, and installed on vendor
, which I find less than ideal. You can also keep the files outside of your project, but that would require additional tracking.
I would personally bite the bullet an accept this package is no longer an external dependency, but files that should be maintained be application developer.