[2/6] - Upgrading From Symfony 3 to Symfony 4 - Fixing Generic Symfony Deprecations
Feb 14, 2023
The full free tutorial can be found here : https://www.codereviewvideos.com/course/upgrade-symfony-3-to-symfony-4/video/fixing-generic-symfony-deprecations
In the previous tutorial we covered the changes needed to take our application from Symfony 3.2 to Symfony 3.4.
Whilst this is only a minor bump, upgrading an existing project to Symfony 3.4 is an important step as it gives the highest chance of identifying, and eliminating any code issues before upgrading.
Show More Show Less View Video Transcript
0:00
Hello YouTube, I'm Chris from codereviewvideos.com. Before watching this video, I'd like to let you
0:05
know that I have over 500 similar videos available on my site, codereviewvideos.com. If you love
0:11
Symfony, then you'll feel right at home here. I'll show you how to build both websites and JSON
0:16
APIs, and then we're going to talk to those JSON APIs using React and Redux. There's courses on
0:21
Docker and Ansible, as well as loads on deployment and test-driven development and behavior-driven
0:26
development. If you enjoy this video please like and subscribe and as ever thanks for watching
0:56
sure that we find and fix any deprecated code. I'm just going to start off by doing a tail minus
1:01
f to follow var logs the dev.log. You can see this is already stuff that's in the dev log so I'm just
1:07
going to push return a few times there to enter a little space just visually so that we can see what
1:12
happens when we refresh the page. As soon as we've refreshed the page we saw in the previous video
1:17
that we get this on the web debug toolbar where we can see our deprecations and whatnot but it's
1:21
also all stored in the log file as well. We're not going to use the log file too much to be honest
1:26
I just wanted to show you that the data is there also. So we're going to primarily focus on what we can see from the web debug toolbar
1:33
I'm just going to do a command and click there to open this in a different tab and then go
1:37
to the deprecations tab. And we can see by looking through it that some of these things, although they might
1:42
look scary initially, are pretty much, if you're unsure about it, just copy the whole
1:45
message and paste it into Google and have a look for what comes up. Because by now, most of this stuff is already solved
1:52
And we can see stuff like this It relates to Symfony in general So if you opened up any Symphony project you going to see these sorts of things when you bump up to Symfony 3 But there is also stuff that specific to our project
2:04
And you should recognize this because it will be, you know, stuff that's actually things
2:07
that make sense to you. In our case, this GitHub API can go through and see them all
2:13
And the idea is that we reduce or remove all of these deprecations before we bump up to
2:18
Symfony 4. So right off the bat, you can see these are Symfony ones. This would be specific to our project. This is specific to our project, but is related to a bundle that we're using
2:27
And again, these are all Symfony ones as you go through. And you don't need to know this, honestly, as I say, if you're unsure about any of it, just Google it
2:33
So we're going to tackle these. The first one, load class cache and do load class cache
2:40
What this is telling us is in our web under app and app dev, we need to remove load class cache
2:47
Now you can see Symphony has deprecated these methods, which is why PHP Storm shows them as having a line through them
2:53
I'm just going to remove both of them. You don't need to comment them out, especially if you're using Git
2:57
Don't leave them in there, comment it out. Just remove them. But the thing is, Symphony 4 actually uses a different structure to this anyway
3:05
So removing these isn't super high priority, I suppose, but it does get rid of the warning
3:10
So we'll now just give this a refresh. We should see that we're down to 12. And again, we need to go into the profiler
3:16
Let's give that a refresh. go to latest, deprecations, and we've got rid of them top two
3:22
We're going to cover our own deprecations in a separate video. And likewise, third-party bundle code will be covered separately
3:29
So we're just going to move on, in this case, to this one, which also brings in these ones
3:34
You can see it's telling us this is a problem in config dev, line 20, 23, and 23
3:40
So if we go into our config dev, I'm just going to close off some of these. Config, config dev
3:45
And essentially what this is telling us is something to do with scalars, or our unquoted
3:49
scalar value which simply means we need to put some quotes around these values Basically the messages are a little bit more scary than the actual problems So again let give this a refresh We should be down to
4:03
nine now, and I might as well refresh that whilst we're doing that. Hopefully that works. Yeah, so
4:08
we can see deprecations down to nine. Next up, we've got this framework.trustedproxies configuration
4:14
key. Well, unless you're in an enterprise application, it's very unlikely that this is
4:18
going to be a problem for you. It's to do with load balances and things like that. Again, I've
4:22
only ever seen this used inside very large applications, particularly in enterprise. And
4:27
again, what this is saying is, even though it's a little bit less clear this time on the framework
4:32
we've got this trusted proxies. Just going to get rid of that. If you have any trusted proxies set
4:38
then at this point you would need to follow the guidance. And I've got this in the show notes. So
4:42
just look for the link. It's a little bit trickier, this one, because you would need to add it to your
4:46
app or app dev and again then you would need to migrate it across to the new structure when you
4:51
move up to symphony 4 so it should be down to eight deprecations at this point let's give that
4:56
a refresh i'm not going to look at each one but you can see we're down to eight so again framework
5:01
trusted proxies we've done that not setting logout on user change to true on firewall main is
5:06
deprecated so that tells us that we need to look inside our security yaml because that's where our
5:10
firewalls live and under main i'm going to add in this new key that it's telling me about
5:15
log out on user change and set that to true and again i'm really just following the guidance there
5:21
as to what it's telling me although i completely understand that if you're new to symphony these
5:25
messages are scary and confusing at least potentially so down to seven let's give this
5:29
refresh now deprecations now these two are a little less obvious but the fix that we're going
5:35
to put in place is generic and we'll solve both of them so as i mentioned in the previous video
5:39
simply bumping up our symphony version inside composer json is not sufficient we've just bumped
5:45
up symphony symphony but yeah if we look at the symphony standard edition on github and then take a look at the code and what we want to do here is look inside their composer file And we also want to make sure that we on the latest tag
5:59
So what we're going to do here is just take a look at everything inside the require and
6:03
require dev. So I'm just going to copy the whole lot out. This is how I do it anyway
6:08
I'll just add this two new sections in and you can see PHP storm is kicking off here because
6:14
it's saying, you know, these keys already exist. Now I'm going to show you a little cheat that I
6:17
use here. So we could look at them and actually just compare them visually, but there's a much
6:22
easier way. Take a copy of that out, make sure to add in your comma there. And then what this is
6:27
going to do is highlight all the duplicates. So it just makes it really straightforward to figure
6:31
out what's changed. So I'm going to get rid of that one. Doctrine bundle 1.6, that one's the same
6:37
ORM 2.5, that's the same. The same. What about that one? So distribution bundle is slightly
6:43
different so I'll just add that in and take the more specific version again framework extra bundle
6:49
massively different drop that one in monologue sufficiently different also and that's one of
6:55
the warnings that we're getting I think to do with the PSI login and swift mailer bundle again
7:01
different so let's get that one in there so that should be good enough there required dev we're on
7:08
3.0 for generator and 3.0 for php unit bridge both of those are the same so i'm just going to get rid
7:14
of all of that now and do a composer update so i'm just going to cancel out of them log files there
7:18
and do a composer update okay so that should have brought in the changes and i'm going to browse back to my app
7:25
give it a refresh and i should be able to just refresh this as well
7:30
We're down to four deprecations, even though we're only really seeing two, you could see
7:38
this one's group three instances together and we'll look at that in the very next video
