This tutorial is built using Symfony 4, but most of the concepts apply fine to Symfony 5!
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"doctrine/annotations": "^1.8", // v1.8.0
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knpuniversity/lorem-ipsum-bundle": "*@dev", // dev-master
"nexylan/slack-bundle": "^2.0,<2.2", // v2.0.1
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.6
"symfony/asset": "^4.0", // v4.0.6
"symfony/console": "^4.0", // v4.0.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.6
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.6
"symfony/web-server-bundle": "^4.0", // v4.0.6
"symfony/yaml": "^4.0", // v4.0.6
"weaverryan_test/lorem-ipsum-bundle": "^1.0" // v1.0.0
},
"require-dev": {
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"sensiolabs/security-checker": "^4.1", // v4.1.8
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.6
"symfony/dotenv": "^4.0", // v4.0.6
"symfony/maker-bundle": "^1.0", // v1.1.1
"symfony/monolog-bundle": "^3.0", // v3.2.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.3.3
"symfony/stopwatch": "^3.3|^4.0", // v4.0.6
"symfony/var-dumper": "^3.3|^4.0", // v4.0.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.6
}
}
8 Comments
I'm working with sf 3.4.9, trying to register an extension like mentioned in the doc https://symfony.com/doc/3.4...
But unfortunately my Extension class is not registered because I dont have the Bundle structure in my project, so any idea !!
Hey Ahmed,
Hm, probably the question is why do you need to register an extension? Probably you don't actually need it. If you want to import some services - import it manually in config/services.yaml, etc. But if you really need it and you 100% sure you can't avoid without it (I mean you can't implement what you want in a different way without registering an extension), you probably need to create an bundle class (e.g. AppBundle) which extends the base Bundle class, add it to config/bundles.php and manually register an extension class like showed in docs: https://symfony.com/doc/mas...
Cheers!
I just noticed that 11 users liked my comment, so that's why I'm going to propose a solution for the problem : Manually Registering an Extension Class, between us I had already file two solutions for a long time in tmy blog, (a French article), here a link for people who understands the language https://ahmedbhs.me/creation-dune-extension-di-dependency-injection-extensions ...
Ok so under
AppKernel.phpclass, it was necessary to add manually the extension with the functionaddExtension():Great solution! Thanks for sharing! It’s indeed interesting to see what comments / questions get upvoted :)
Thank you for all the tutorials and availability, I really appreciate it. Anyway I think my way is a little hard coded and it should extend the getContainerExtension function as it is mentioned in the official doc and as Victor answered us. Besides it's because of his answer that I had the motivation to write the solution. Cheers!
Your solution is actually great - the BEST solution! In Symfony 4, because we don't have bundles (and you don't need them), what you showed IS the best solution.
By the way, what is your motivation for creating & registering an extension class? I'd like to hear the use-case that you (and apparently many other people) are having.
Cheers!
I understand you try to spicy things up when explaining.. but after 200 videos the "ahhh" and "ohh error" and "I l love errors" becomes annoying to listen to. It's like it breaks up the flow of words.
Hey Stefan D.!
Haha, fair enough :). I *do* like to show errors... so that you know what they mean when you hit them... and also, sometimes... it's on accident ;). But, it's funny - I have to listen to myself over and over again too for recording purposes - a person can only take so much Ryan :D
I hope you'll watch 200 more despite... and that's an impressive number - congrats!
"Houston: no signs of life"
Start the conversation!