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
4

2 回答 2

0

在我终于开始在 github 存储库上使用版本标签之前,我遇到了同样的问题。

在 index.json 中,我的包的版本是 1.0。

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

我在我的包上创建了一个v1.0git 标签,以便打包师可以看到它。在我的 nextcomposer require中,flex 最终执行了我的配方,而不是使用自动生成的配方。

Flex 似乎需要将配方与您的捆绑包版本相关联。您似乎不能依赖简单的dev-main版本名称。

它会在你的情况下工作吗?从那以后你找到解决方案了吗?

于 2021-12-05T23:27:23.557 回答
-1

要验证是否使用配方,您可以在配方 manifest.json 文件中添加别名。

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

现在尝试使用别名安装软件包:

composer require short-name

如果它安装包,那么它正在使用配方。这样您就可以缩小搜索范围。

于 2020-10-08T09:13:50.363 回答