php - Composer custom private package not being found
Get the solution ↓↓↓I have a private-ish package repo that I'm trying to release inside the company I work for as a composer package.
I've created the package with the followingcomposer.json
file:
{
"name": "my_team/package_name",
"description": "Package Description",
"homepage": "https://git.company.com/MyTeam/package_name",
"type": "library",
"license": "Proprietary",
"minimum-stability": "stable",
"version": "1.4",
"require": {
"php": ">=7.1.0",
"ext-curl": "*",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"PackageNamespace\\": "src/"
}
}
}
All the paths in the package are correct, and I've created a Tag and Release on the Enterprise Github Repo that contains a zip file of the package at v1.4.
I wanted to test that the package worked, so I created a test script to run it, and it has the followingcomposer.json
file:
{
"name": "benjam/test",
"repositories": [
{
"type": "package",
"package": {
"name": "my_team/package_name",
"version": "1.4",
"dist": {
"type": "zip",
"url": "https://git.company.com/MyTeam/package_name/archive/v1.4.zip"
}
}
}
],
"require": {
"my_team/package_name": "1.4"
}
}
and amain.php
file with the following contents:
<?php
require __DIR__ . '/vendor/autoload.php';
$obj = new PackageNamespace\ClassName();
When I try to run that file, I get the following error:
PHP Fatal error: Uncaught Error: Class 'PackageNamespace\ClassName' not found in C:\Development\test\main.php:5
Stack trace:
#0 {main}
thrown in C:\Development\test\main.php on line 5
Fatal error: Uncaught Error: Class 'PackageNamespace\ClassName' not found in C:\Development\test\main.php on line 5
Error: Class 'PackageNamespace\ClassName' not found in C:\Development\test\main.php on line 5
Call Stack:
0.2130 353200 1. {main}() C:\Development\test\main.php:0
So it seems that the composer autoloader doesn't see the installed package.
What have I done wrong?
Other test scriptcomposer.json
settings I've tried are:
"repositories": [
{
"type": "package",
"package": {
"name": "my_team/package_name",
"version": "1.4",
"source": {
"type": "git",
"url": "https://git.company.com/MyTeam/package_name",
"reference": "origin/master"
}
}
}
],
Answer
Solution:
The issue I was having was that the zip file that was auto-generated by Github when tagging a release did not have thecomposer.json
file in the top-level of the archive.
Because composer uses the information in that file to create the autoload settings, it was successfully importing and installing the package, but was not setting the autoload settings.
I've changed my test scriptcomposer.json
file to the following, and it works:
(Note that there is a tag in the repo calledv1.4
)
{
"name": "benjam/test",
"repositories": [
{
"type": "vcs",
"url": "[email protected]/package_name.git"
}
],
"require": {
"my_team/package_name": "v1.4"
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: string literal contains an unescaped line break
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.