1
votes

I have a local dependency which is hosted on a private Gitlab repo. I am however, having difficulty pulling this into my project via Composer.

My composer.json:

"require": {
    "crmpicco/GolfBundle": "dev-master"
},
"repositories": [
    {
        "type": "package",
        "package": {
        "name": "crmpicco/GolfBundle",
        "version": "dev-master",
        "source": {
            "url": "https://git.crmpicco.com/rfc1872/golfbundle.git",
            "type": "git",
            "reference": "master"
        },
        "autoload": {
            "psr-4": {
                "crmpicco\\GolfBundle\\": ""
            }
        }
        }
    }
],

When I look in the vendor directory the directories are doubled-up when I would not expect that, e.g. /vendor/crmpicco/GolfBundle/crmpicco/GolfBundle

When I run a composer update crmpicco\GolfBundle I get the following error when Symfony tries to do a cache:clear:

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted   
  to load class "crmpiccoGolfBundle from namespace "crmpicco\GolfBundle".         
  Did you forget a "use" statement for "crmpicco\GolfBundle\crmpiccoGolfBundle"?   
  in /var/www/crmpicco/symfony/app/AppKernel.php:31   

What am I missing/doing wrong in my composer.json setup?

Bundle dir structure:

/crmpicco
   /GolfBundle
      /Component      
      /DependencyInjection
      crmpiccoGolfBundle.php

Bundle composer.json:

{
  "name": "crmpicco/GolfBundle",
  "type": "library",
  "description": "A Symfony 2 bundle which provides an easy way to handle billing and subscriptions.",
  "license": "MIT", 
  "require": {
    "php": ">=7.0",
    "symfony/config": "~2.8.34",
    "symfony/dependency-injection": "~2.8.34",
    "symfony/http-kernel": "~2.8.34",
  },
  "autoload": {
    "psr-4": {
      "crmpicco\\GolfBundle\\": ""
    }
  },
  "extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "relative"
  }
}
2
Can you please paste here the directory structure of your GolfBundle and it's composer.json?Nikita Leshchev
@NikitaLeshchev Hi, sure. I've updated the question. I have no composer.json in my bundle dir.crmpicco
@NikitaLeshchev Apologies for the confusion, I have added the composer.json which belongs to my bundle to the question above.crmpicco

2 Answers

1
votes

You should not use package type for repositories which contains valid composer.json. This type was designed for packages without composer.json, so this file will be completely ignored, same as updates in your package.

In your case it is better to define it as git:

"repositories": [
    {
        "type": "git",
        "url": "https://git.crmpicco.com/rfc1872/golfbundle.git"
    }
],
1
votes

Ok. As I see you have wrong psr-4 autoload config in your bundle's composer.json You have to change it to the following:

"autoload": {
    "psr-4": {
        "crmpicco\\GolfBundle\\": "crmpicco/GolfBundle"
    }
}

Also If you don't want duplicating of dirs, move your bundle's contents to the root dir and then don't change composer.json contents. Dirs duplicate because Composer creates dir structure based on name property which is also crmpicco/GolfBundle in your case.