The course is built on Symfony 4, but the principles still apply perfectly to Symfony 5 - not a lot has changed in the world of relations!
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.7.2
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.14
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.14
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0", // v4.0.4
"symfony/yaml": "^4.0", // v4.0.14
"twig/extensions": "^1.5" // v1.5.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"fzaninotto/faker": "^1.7", // v1.7.1
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.4
"symfony/dotenv": "^4.0", // v4.0.14
"symfony/maker-bundle": "^1.0", // v1.4.0
"symfony/monolog-bundle": "^3.0", // v3.1.2
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.4
"symfony/stopwatch": "^3.3|^4.0", // v4.0.4
"symfony/var-dumper": "^3.3|^4.0", // v4.0.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.4
}
}
28 Comments
FYI for anyone doing this who runs into:
The intl extension is needed to use intl-based filters.
You'll have to install the php-intl package. On Ubuntu with PHP7.2 it's:
$ apt-get install php7.2-intl
Hey Matt,
Thanks for sharing this with others!
Cheers!
I'm working on a Symfony 5.0.4 app and installing twig extensions using: composer require twig/extensions fails installation. Is it common pratice that a library like Twig extension get updated to run in the new versions of Symfony?
Hey Robert V.
That's odd. I believe it should work. Can you show me what errors are you having?
Cheers!
composer require twig/extensions
below is the
Using version ^1.5 for twig/extensions
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install twig/extensions v1.5.4
- Conclusion: don't install twig/extensions v1.5.3
- Conclusion: don't install twig/extensions v1.5.2
- Conclusion: don't install twig/extensions v1.5.1
- Conclusion: remove doctrine/doctrine-bundle 2.0.7
- Conclusion: don't install doctrine/doctrine-bundle 2.0.7
- twig/twig v2.0.0 conflicts with doctrine/doctrine-bundle[2.0.7].
then more conflicts up to
- twig/twig v1.42.5 conflicts with symfony/http-kernel[v5.0.4].
and
- Conclusion: don't install twig/twig v3.0.3|install twig/twig v1.27.0|install twig/twig v1.28.0
Hey Robert V.!
Ah, it looks like you're in dependency "heck" :D. So here's the problem - I think you guessed it already. Basically: twig/extensions has *not* be updated to work with Symfony 5. Normally, it IS a common practice for twig/extensions to be updated when a new Symfony version is released. However, this package has been replaced by a few, smaller libraries (which I like much better). Check out the README here: https://github.com/twigphp/...
Basically, you should now install a new TwigExtraBundle (depending on when you installed Twig, you may already have this). Then, you can immediately try to start using any of the functions or filters from twig extensions. When you do, you'll get a really clear error telling you *exactly* what other package you should install. Here is a screencast talking about this exactly: https://symfonycasts.com/sc...
Let me know if that works!
Cheers!
Hi Ryan ,
could u make a video explaining how to understand and solve this kind of problems of conclusion
Hey Tarek H.!
Ha! That's a good idea :). In this case, I was familiar with the problem... and I think there was more Composer output than Rob was showing (it's not obvious from just what he posted here what the problem was). But my thought process probably would have been:
A) Check the twig/extension library to see what libraries it requires (since, the problem is somehow related to this library): https://github.com/twigphp/...
B) This basically only requires twig/twig... and it requires ONLY version 2. Do I maybe have version 1 installed of Twig? Or version 3? If I have version 3, why hasn't twig/extension been updated to support v3?
These things can be a bit of a "search", and it involves checking composer.json files & googling to see what happened. This was a particularly complex one.
So, I'm not sure that's the best answer, but I hope it helps :). Maybe I'll find a situation like this again and make a video to debug it - that would be cool!
Cheers!
I was able to get truncate working by running: composer require twig/string-extra
then print the first 100 words with: comment.content|u.truncate(100)
Hey Robert V.
Great! Is there any more issues?
Cheers!
Hey Ryan and Vladimir! No more issues; composer require twig/string-extra enabled the use of u.truncate in my twig template. Thanks for your help guys!
For Symfony 5, it appears the approach is to use the "u" filter which provides access to the Symfony string component. Examples and composer installation are here: https://twig.symfony.com/do...
Hello,
When i installed twig extension i got this :
Executing script cache:clear [OK]
Executing script assets:install public [OK]
Executing script security-checker security:check [KO]
[KO]
Script security-checker security:check returned with error code 1
!! Symfony Security Check Report
!! =============================
!!
!! 5 packages have known vulnerabilities.
!!
!! symfony/cache (v4.3.6)
!! ----------------------
!!
!! * [CVE-2019-18889][]: Forbid serializing AbstractAdapter and TagAwareAdapter instances
!!
!! symfony/http-foundation (v4.3.6)
!! --------------------------------
!!
!! * [CVE-2019-18888][]: Prevent argument injection in a MimeTypeGuesser
!!
!! symfony/http-kernel (v4.3.6)
!! ----------------------------
!!
!! * [CVE-2019-18887][]: Use constant time comparison in UriSigner
!!
!! symfony/mime (v4.3.6)
!! ---------------------
!!
!! * [CVE-2019-18888][]: Prevent argument injection in a MimeTypeGuesser
!!
!! symfony/var-exporter (v4.3.6)
!! -----------------------------
!!
!! * [CVE-2019-11325][]: Fix escaping of strings in VarExporter
!!
!! [CVE-2019-18889]: https://symfony.com/cve-201...
!! [CVE-2019-18888]: https://symfony.com/cve-201...
!! [CVE-2019-18887]: https://symfony.com/cve-201...
!! [CVE-2019-18888]: https://symfony.com/cve-201...
!! [CVE-2019-11325]: https://symfony.com/cve-201...
!!
!! Note that this checker can only detect vulnerabilities that are referenced in the SensioLabs security advisories database.
!! Execute this command regularly to check the newly discovered vulnerabilities.
Hey Akavir S.!
Excellent question :). This is a really cool warning that you get telling you that some dependencies in your project are out-of-date and that those out-of-date versions contain security vulnerabilities. On this project, it's no big deal (as long as you're using this code to practice, and not actually deploy as a real site). If this were a real application, you would need to upgrade some of your dependencies. Sometimes
composer upgradewould be enough. But because (in this case) 4.3 is end-of-life, you might need to upgrade the application from 4.3 to 4.4 - you can see details about how to do that here: https://symfony.com/doc/current/setup/upgrade_minor.htmlLet me know if you have any questions!
Cheers!
Thanks you a lot Ryan!
I fixed it, thanks to composer upgrade !
Cheers :p
Replace Twig\Extensions\TextExtension?
Totally! Thanks for notifying us :)
Cheers!
I carefully read the courses =)
Haha, I can tell ;)
BTW, if you find another typo or error on a script and feel like fixing it. There is a "Edit on Github" button at the right upper corner of the script block that you click, so you can edit the script, and then we can merge the change into the project. If not, pinging us is just perfect :)
Cheers!
Guys, I don’t have a lot of bug report practice. Is it a fork to do? It’s easier for me to write a comment here. Sorry
NP man. It's very easy to do it. You just have to click on the "Edit on Github" button in this page, then you will see a text box with the script content, there is where you apply the change, then add a message to the commit and click on "Commit changes" button, and that's it :)
Ok i will try next time
Thanks! And if you don't feel like fixing it yourself, just ping us :)
ping pong :D
Is creating query in CommentRepository with `->leftJoin(c.article)->addSelect(article) going to solve the N+1 issue? This is from your tutorial `Going Pro with Doctrine`, but actually the situation there was the opposite to the situation down here. In `Going Pro with Doctrine` you were quering owning part of relationship, but here you are quering inverse. That's why I'm asking.
Hey Dominik,
Hm, good question! As far as I remember, N+1 problem is solved with addSelect() and query direction is not important, but I'm not 100% sure about it. Btw, you can double check if it's true with Symfony Web Debug Toolbar - go to Doctrine queries and see if you have extra queries for those data you use in addSelect() or no.
Cheers!
@SymfonyCasts: There is a broken link in the part "Installing Twig Extensions".
Hey Steffen,
We're sorry about that! I just double checked our source code for this chapter: https://github.com/knpunive... - it looks good, so that means we have a bug in rendering the chapter on our website. We'll fix it as soon as possible.
Thank you for reporting this!
Cheers!
"Houston: no signs of life"
Start the conversation!