0

I'm trying to create a re-usable custom bundle following the great course on SymfonyCasts. But when I try to install it with composer, the symfony recipes doesn't apply. For example, my bundle isn't registered at all in config/bundles.php. I read everywhere that the simple fact of setting "type": "symfony-bundle" in the composer.json should automatically run the recipes, but in my case it simply doesn't.

The strange fact is the recipes does apply on uninstall. Example :

composer remove chinaskijr/mybundle prints

Symfony operations: 1 recipe (769c88112592ff8a35644e9520929f21)
  - Unconfiguring chinaskijr/mybundle (>=v2.x-dev): From auto-generated recipe

But nothing on composer require chinaskijr/mybundle:*@dev

The SymfonyCasts course make us install it through "path" repositories, but I also tried with private gitea repositories and the results was identical.

I also don't think that the issue comes from my bundle cause when I registered it by hands, his code is correctly working.

Here is my composer.json

{
    "name": "chinaskijr/mybundle",
    "type": "symfony-bundle",
    "description": "A bundle for practice",
    "version": "v2.x-dev",
    "authors": [
        {"name": "chinaskijr", "role": "Owner"},

    ],
    "require": {
        "php": "^7.2"
    },
    "autoload": {
        "psr-4": {"chinaskijr\\mybundle\\": ""}
    }
}

Thank you very much for answering.

EDIT : I'm not sure the problem is from here because I tried to install it on differents projects, and it never works. Here is on symfony/skeleton for example.

{
    "type": "project",
    "license": "proprietary",
    "repositories": [
        {"type": "path",  "url": "../mybundle"}
    ],
    "require": {
        "php": "^7.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "chinaskijr/mybundle": "*@dev",
        "symfony/console": "5.0.*",
        "symfony/dotenv": "5.0.*",
        "symfony/flex": "^1.3.1",
        "symfony/framework-bundle": "5.0.*",
        "symfony/yaml": "5.0.*"
    },
    "require-dev": {
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "5.0.*"
        }
    }
}

EDIT2 : There is the structure. Once activated by hand, services are autowired, I can access them from the container and get the config All namespaces are prefixed by chinaskijr\mybundle\ following the PSR-0

.
├── composer.json
├── Controller
│   └── MyBundleController.php
├── DependencyInjection
│   ├── Configuration.php
│   └── MyBundleExtension.php
├── MyBundleBundle.php
├── README.md
└── Resources
    ├── config
    │   └── services.xml
    └── templates
        └── index.html.twig
  • Where did you host your recipe? https://flex.symfony.com/ does not list a recipe by the given name – Nico Haase May 12 '20 at 11:21
  • Thanks for your reply. From what I know, set "type": "symfony-bundle" in composer.json should auto-generated a basic recipe (as it does on bundle uninstallation) : https://symfony.com/doc/current/bundles/best_practices.html#installation – Robin Colombier May 12 '20 at 11:42
  • Can you share the `composer.json` of your project? – Nico Haase May 12 '20 at 11:44
  • Additionally, can you share the bundle's configuration? Maybe you haven't named your classes properly? – Nico Haase May 12 '20 at 11:47
  • I've add the `composer.json` of the project on the OP, bundle configuration is going to follow, but everything is working when I add the bundle myself to `config/bundles.php, it's just the recipe. – Robin Colombier May 12 '20 at 11:54
  • Which version of Flex are you using? The given constraint allows a minimum version of Flex that is nearly a year old, and maybe your problem has been fixed in the meantime? – Nico Haase May 12 '20 at 12:00
  • 1
    Thanks again for your time ! The structure had been add to the OP. The installed version is the v1.6.2 from january 30th, there is a new one that had been released 3 days ago (https://github.com/symfony/flex/releases) , I'm going to try it. EDIT : Issue is still happening on 1.6.3 – Robin Colombier May 12 '20 at 12:04
  • Sorry for bothering further: have you checked whether `symfony.lock` already contains your bundle? That's internal housekeeping for recipes. Additionally, can you simulate an install such that before requiring, the package is not present in `vendor`? Maybe Flex triggers that recipe progress only in this case – Nico Haase May 12 '20 at 12:09
  • You're not bothering me at all. I've tried your two suggestions and it did not work. I don't work also on a new project so I do think that the issue come from the bundle itself. But I can't see why... – Robin Colombier May 12 '20 at 12:19

2 Answers2

0

I had the same problem until I finally started to use tags for versions on the github repository.

In the index.json, the version for my bundle is 1.0.

    "recipes": {
        "vendor/bundle": [
            "1.0"
        ]
    },

I created a v1.0 git tag on my bundle so that packagist could see it. On my next composer require, flex finally executed my recipe instand of using an auto-generated one.

It appears Flex need the recipe to be associated with a version of your bundle. It doesn't seem you can rely on a simple dev-main version name.

Would it work in your situation ? Did you find a solution since then ?

Djyp
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 06 '21 at 01:55
-1

To verify is recipe used or not, you can add alias to recipe manifest.json file.

   "aliases": [ "short-name", "my-bundle-another-alias" ],

And now try to install the package using the alias:

composer require short-name

If it installs the package, then it is using the recipe. This way you can narrow your search.