Publishing to Packagist
Keep on Learning!
If you liked what you've learned so far, dive in!
Subscribe to get
access to this tutorial plus video, code and script downloads.
20 Comments
Hey Benoit,
Good question! Well, you just need to make the package name unique, i.e. rename that "knpuniversity/lorem-ipsum-bundle" into something like "%your github username here%/lorem-ipsum-bundle". It should be unique enough this way.
Cheers!
Hi, again me,
when i install my bundle with, composer req my/package i get an error :
!! DependencyInjection/config/packages/synology.yaml
!! In SynologyExtension.php line 23:
!!
!! Notice: Undefined index: dsm_app_id
cause he don't found the file /config/packages/synology.yaml in the symfony root project
######
Edit :
Ok found ! must add default value in the dependency configuration file


Hello, I have a question about the recipe.
I've decided to write my own recipe for this nice bundle ( https://github.com/BooleanType/symfony-recipes/tree/master/boolean-type ). My version of bundle is here: https://packagist.org/packages/boolean-type/lorem-ipsum-bundle .
Why have I decided to write it? First of all is, for sure, getting experience in it :) Secondly, when I remove bundle via composer remove
, I see an error in console: There is no extension able to load the configuration for "knpu_lorem_ipsum"
, which is quite understandable, since the configuration file is not removed along with the bundle. The same is true when creating a bundle: I would like the configuration file to be created automatically, as happens when installing the official Symfony bundles.
So, my recipe is very easy:
1) registers bundle in <i>bundles.php</i>;
2) copies <i>knpu_lorem_ipsum.yaml</i> in app's <i>/config/packages</i> dir;
3) creates 2 vars in <i>.env</i>: KNPU_LOREM_IPSUM_FOO
and KNPU_LOREM_IPSUM_BAR
;
4) shows some custom text after bundle installation.
All I want is to see, if it works correctly. But unfortunately I can't test it :(
As I know, that private recipes (as mine is) are not allowed for pushing to contrib. I've tried to use "Server for Symfony Flex" ( https://server-for-symfony-flex.readthedocs.io/en/latest/ ), but no success. I run php bin/console system:status
and see my recipe:
Configuration
----------------------------------- ----------
Proxy for official endpoint enabled
Caching for official endpoint enabled
Local mirror for official recipes enabled
Local mirror for contrib recipes disabled
----------------------------------- ----------
Repo status
---------- ------------------------------------------------ ----------------- ------------ ---------------------
Repo Url Remote readable Downloaded Last Update
---------- ------------------------------------------------ ----------------- ------------ ---------------------
private https://github.com/BooleanType/symfony-recipes Yes Yes 2021-02-17 21:38:48
official https://github.com/symfony/recipes Yes Yes 2021-02-17 21:38:52
contrib https://github.com/symfony/recipes-contrib Yes No
---------- ------------------------------------------------ ----------------- ------------ ---------------------
But when I run composer recipes boolean-type/lorem-ipsum-bundle
, I see only auto-generated recipe, which just adds my bundle in <i>bundles.php</i>:
name : boolean-type/lorem-ipsum-bundle
version : v1.0.0
status : auto-generated recipe
Of course, I expect to see my <i>private</i> recipe, but something is wrong. And I even can't say, or am <i>I</i> wrong, when using this server, either this server just doesn't work for some reason.
So, is there a possibility to test my recipe? Can you advice me some lib / tech for this? Maybe, it is still possible to test via pushing to contrib?
Thanks in advance.
Hey @Boolean_Type!
Nice job on the recipe!
And yes, it is possible to test your recipe. As you mentioned, there is no support for private recipes. The process to test looks like this:
A) Create a pull request to for your recipe. You will want to make it against the https://github.com/symfony/... repository
B) Once the pull request is open, at the bottom, you should see the message "This branch was successfully deployed" with a "Show environments" link. You can see an example on this open PR: https://github.com/symfony/...
C) If you click on that link, it will give you instructions on how to test your recipe. Basically, when you create a pull request, it deploys your recipe to the Symfony Flex server. Then, you can set an environment variable to tell your local Flex to use that deployment. This allows you to (after setting the env var) go into a project and "composer require" your bundle and see how the new recipe behaves :).
Let me know if this helps!
Cheers!


Thank you, weaverryan , for the answer very much. The recipe works like a charm! :)


Hello again! :)
I've done all your instructions, my recipe is now in pull request ( https://github.com/symfony/recipes-contrib/pull/1099 ).
Also I've got instructions, when clicked "View deployment" button generated by symfony-flex-server bot ( https://flex.symfony.com/r/github.com/symfony/recipes-contrib/1099 ):
Step 0. Allow installing "contrib" recipes in your application:
composer config extra.symfony.allow-contrib true
Step 1. Define the SYMFONY_ENDPOINT environment variable:
# On *nix and Mac
export SYMFONY_ENDPOINT=https://flex.symfony.com/r/github.com/symfony/recipes-contrib/1099
# On Windows
SET SYMFONY_ENDPOINT=https://flex.symfony.com/r/github.com/symfony/recipes-contrib/1099
# ... and so on ...
So, I've set env var, removed and installed back my bundle. Next I run:composer recipes boolean-type/lorem-ipsum-bundle
Result is:
Using "https://flex.symfony.com/r/github.com/symfony/recipes-contrib/1099" as the Symfony endpoint
name : boolean-type/lorem-ipsum-bundle
version : v1.0.0
status : auto-generated recipe
I've noticed this <i>"Using ... as the Symfony endpoint"</i>. But when I run composer recipes:install boolean-type/lorem-ipsum-bundle --force -v
, still auto-generated recipe is applied. What am I missing? Thanks.

Hey there,
That's odd, in theory it should work. Is it related to this comment? https://github.com/symfony/...


But you see, I just tried to install the bundle on another project - it worked! :) Maybe, I have wrong setting on my home test project or I had to wait a bit until it worked (I guess waiting, because the installation instructions ( https://flex.symfony.com/r/... ) did not appear immediately, but only a few hours after the recipe was successfully validated by bot).
I'll try at at home project tonight too and I will know for sure.

Interesting... perhaps it was Composer's cache who caused that odd behavior. If you face to this problem again try clearing out composer's cache and see if that works :)
Cheers!


I've cleared my cache and repeated the whole bundle and recipe installations process - everything works as expected! Thanks!


Hej, I'm not sure, that this comment is actual, 'cause I've re-pushed my files after that ( https://github.com/symfony/... ) and all checks passed for this commit...


Helloy.
Can you help?
In my case symfony flex doesn't enable bundle in bundles.php.
I can't understand why? Maybe you can suggest me a reason.
I use symfony 4.4

Hey Вячеслав Л.
Can you tell me what bundle is not being registered? Also, could you double check that Symfony Flex is installed in your project?
When you install a bundle that comes with a recipe, you should see a message coming from Composer that a recipe was found
Cheers!


I try install my bundle, from private bitbucket repository, In my project Flex installed, because other bundles registred, after composer required

Ohh, it's your own bundle. It may be missing the "type" key on your composer.json. Check at this piece of documentation: https://symfony.com/doc/4.4...
Cheers!


`{
"name": "company/name",
"description": "some test",
"type": "symfony-bundle",
"license": "proprietary",
"require": {
"php": "^7.1.2",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/config": "4.4.*",
"symfony/dependency-injection": "4.4.*",
"symfony/http-kernel": "4.4.*",
"symfony/yaml": "4.4.*",
"symfony/serializer": "4.4.*",
"symfony/form": "4.4.*"
},
"autoload": {
"psr-4": {
"Mokryinos\\ServiceResponseBundle\\": "src/"
}
},
"conflict": {
"symfony/symfony": "*"
}
}
`
my composer.json in bundle
Hey Вячеслав Л.!
Well, the type
key looks perfect :). Here is the logic in Symfony Flex that automatically updates bundles.php when it's installing a "symfony-bundle" type: https://github.com/symfony/flex/blob/c497c0c77cb9018cccd9c092832ebf9826612f92/src/Flex.php#L760-L775
For this to work, you need a few things:
A) The symfony-bundle type
B) Flex needs to be able to locate your bundle class
My guess is that (B) is not working. Flex looks in some "common" places for your "bundle" file and follows some conventions to find it. The logic is here: https://github.com/symfony/flex/blob/e4f5a2653ca503782a31486198bd1dd1c9a47f83/src/SymfonyBundle.php#L33-L63
This looks at your psr-4 path (so, src/
in your case) then uses your namespace to try to find the correct bundle class there. I'm not actually sure all the things it "tries" - the logic is in the extractClassNames()
method that it calls. I would add some var_dump
inside that method and install your bundle to see what class names it's looking for. It's possible that your bundle class (or file path) is not what Flex is expecting, so it can't "guess" it and install it.
Let me know what you find out!
Cheers!


How do you keep updating the bundle once it's in Packagist? I mean the code now is in /vendor how do I manage to have the GIT?
Hey Sela,
As an author of the bundle, you have access to its Git repository, right? So, just push your changes to that repo. If you would like to do some changes in the bundle in a real project - you can install the bundle from the local Git repository with Composer. Then it will be symlinked, so when you will change code in your bundle's local repository - you will see the changes in your project. See Composer docs for more information on it: https://getcomposer.org/doc... .
As an alternative solution, Composer allow you to install packages from source, use "composer install --prefer-source" and Composer, instead downloading just files, will pull down the entire Git repositories, but the previous solutions might be better I think :) And actually exactly this solution we show in this course, see https://symfonycasts.com/sc... . Have you seen that chapter? :)
I hope this helps!
Cheers!
It is my first time to post on Packagist. If I take the code from the tutorial and try to post it and I get "A package with the name knpuniversity/lorem-ipsum-bundle already exists." which I guess was to be expected. If I want to finish section 19 and 20, what should I do?