WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.106 --> 00:00:04.766 align:middle
Alright, let's dive right
into upgrading to Symfony 7.4.

00:00:05.356 --> 00:00:07.176 align:middle
Open your composer.json file.

00:00:07.706 --> 00:00:11.296 align:middle
Notice how the Symfony packages use a 7.3.

00:00:11.296 --> 00:00:15.256 align:middle
* format. This is slightly different
from the rest of our packages,

00:00:15.386 --> 00:00:17.886 align:middle
which typically use the ^ prefix format.

00:00:18.346 --> 00:00:21.776 align:middle
This makes it super easy to find
and update the symfony packages.

00:00:22.346 --> 00:00:24.536 align:middle
If you're using PhpStorm, go to edit...

00:00:24.536 --> 00:00:26.406 align:middle
find... replace.

00:00:26.966 --> 00:00:28.726 align:middle
Search for 7.3.

00:00:28.726 --> 00:00:31.826 align:middle
* and replace with 7.4.

00:00:31.826 --> 00:00:35.546 align:middle
*. We can see we have 19 occurences to replace.

00:00:36.066 --> 00:00:36.946 align:middle
Hit replace all...

00:00:36.946 --> 00:00:38.036 align:middle
and... boom!

00:00:38.596 --> 00:00:40.896 align:middle
Let's just do a double check to
make sure we didn't miss any.

00:00:41.466 --> 00:00:42.336 align:middle
Under require...

00:00:42.836 --> 00:00:43.776 align:middle
yep, looks good.

00:00:44.316 --> 00:00:45.716 align:middle
Now down to require-dev...

00:00:47.126 --> 00:00:48.416 align:middle
Yep, looks good there too.

00:00:49.216 --> 00:00:51.716 align:middle
The maker-bundle has a different
versioning strategy

00:00:51.716 --> 00:00:53.916 align:middle
than the Symfony core components and bundles.

00:00:54.206 --> 00:00:55.376 align:middle
That's why it looks different.

00:00:56.236 --> 00:01:00.016 align:middle
Notice under the extra section, we
have this symfony require config.

00:01:00.696 --> 00:01:05.826 align:middle
This tells Symfony Flex which version of Symfony
to use when installing Symfony components.

00:01:05.896 --> 00:01:11.476 align:middle
Some of our required Symfony components require
other Symfony components as dependencies.

00:01:11.976 --> 00:01:15.256 align:middle
These are called transitive
dependencies (fancy word!),

00:01:15.256 --> 00:01:18.186 align:middle
and can allow a wide range of Symfony versions.

00:01:18.366 --> 00:01:20.496 align:middle
Like Symfony 6, 7, or 8.

00:01:21.046 --> 00:01:24.896 align:middle
This config ensures that only
the 7.4 versions are installed.

00:01:24.896 --> 00:01:28.616 align:middle
So when upgrading Symfony, it's
important to also update this config.

00:01:29.226 --> 00:01:33.666 align:middle
Great! Now that we've updated our
composer.json, let's run our composer update:

00:01:33.666 --> 00:01:41.036 align:middle
symfony composer update Perfect,
it looks like it worked!

00:01:41.036 --> 00:01:43.516 align:middle
Let's hop over to our app and refresh.

00:01:44.946 --> 00:01:49.186 align:middle
Yep, we're now on 7.4.8, the latest 7.4 version.

00:01:49.796 --> 00:01:54.896 align:middle
Back in our terminal, run:
git status Our composer.json

00:01:54.896 --> 00:01:58.226 align:middle
and composer.lock files are
modified, this is expected.

00:01:58.226 --> 00:02:02.896 align:middle
But we also have this new config/reference.php.

00:02:02.896 --> 00:02:03.956 align:middle
Open that up in your editor.

00:02:06.186 --> 00:02:10.266 align:middle
This is an auto-generated file Symfony
creates when building the container.

00:02:10.266 --> 00:02:15.946 align:middle
Symfony now has a PHP array-based
config format - an alternative to YAML.

00:02:16.426 --> 00:02:20.616 align:middle
This file is generated to provide better
auto-completion when using that format.

00:02:21.316 --> 00:02:24.606 align:middle
YAML is still the recommended format,
and what we're using in this app,

00:02:24.606 --> 00:02:26.976 align:middle
so this file isn't important for us right now.

00:02:26.976 --> 00:02:30.996 align:middle
If Symfony changes it's recommendation
in the future, we'll be ready!

00:02:31.526 --> 00:02:33.496 align:middle
Check out this blog post to learn more about it.

00:02:34.186 --> 00:02:37.136 align:middle
You can either add this file to
your .gitignore or commit it.

00:02:37.556 --> 00:02:40.426 align:middle
The best practice right now is
to commit it, so let's do that.

00:02:40.866 --> 00:02:47.656 align:middle
In your terminal, run: git add
config/reference.php After running git status

00:02:47.656 --> 00:02:53.606 align:middle
to confirm we're good, we can commit with:
git commit -a -m "update composer" (Yeah,

00:02:53.606 --> 00:02:58.146 align:middle
we should really use a better
commit message here) Let's see

00:02:58.146 --> 00:03:00.566 align:middle
if there are any recipe updates for 7.4!

00:03:00.956 --> 00:03:07.446 align:middle
Run: symfony composer recipe:update Just
two, start with the framework-bundle.

00:03:09.146 --> 00:03:11.226 align:middle
Run git status to see the changes.

00:03:11.416 --> 00:03:15.036 align:middle
.env and config/services.yaml
have been modified.

00:03:15.806 --> 00:03:17.256 align:middle
Open .env first.

00:03:19.566 --> 00:03:22.706 align:middle
A new environment variable
was added: APP_SHARE_DIR.

00:03:23.226 --> 00:03:27.026 align:middle
When running Symfony in a multiserver
architecture, this is a directory

00:03:27.026 --> 00:03:29.056 align:middle
that should be shared between the servers.

00:03:29.616 --> 00:03:33.536 align:middle
Previously, you had to share the entire
cache directory, which isn't idea.

00:03:34.256 --> 00:03:37.406 align:middle
This new config allows you to
have more fined-grained control

00:03:37.586 --> 00:03:39.516 align:middle
over what is shared between servers.

00:03:39.516 --> 00:03:43.376 align:middle
If you're interested in learning more
about this, check out this blog post.

00:03:44.296 --> 00:03:47.836 align:middle
Open our second modified
file, config/services.yaml.

00:03:48.166 --> 00:03:50.346 align:middle
Just the comments at the top were modified.

00:03:50.726 --> 00:03:52.776 align:middle
But it does provide a cool new feature!

00:03:52.776 --> 00:03:56.526 align:middle
See this yaml-language-server $schema stuff?

00:03:56.526 --> 00:03:59.046 align:middle
This configures a JSON schema for this file.

00:03:59.546 --> 00:04:00.596 align:middle
Wait, JSON?

00:04:00.786 --> 00:04:01.516 align:middle
This is YAML.

00:04:01.516 --> 00:04:08.056 align:middle
Since YAML is JSON-compatible, we can use
JSON schemas to validate our YAML files.

00:04:08.686 --> 00:04:11.016 align:middle
This is cool, but the better part,

00:04:11.176 --> 00:04:14.496 align:middle
is that it gives us auto-completion
in our IDEs if supported.

00:04:14.676 --> 00:04:16.926 align:middle
And PhpStorm does support this!

00:04:17.356 --> 00:04:20.306 align:middle
Here's a blog post if you
want to learn more about it!

00:04:20.306 --> 00:04:23.136 align:middle
Ok, let's commit these changes
at our terminal with:

00:04:23.436 --> 00:04:30.196 align:middle
git commit -a -m "update recipes"
Run the recipe update command again,

00:04:30.306 --> 00:04:31.976 align:middle
and update the routing package.

00:04:33.506 --> 00:04:35.586 align:middle
Run git status to see the changes.

00:04:36.146 --> 00:04:38.876 align:middle
config/routes.yaml: open that up.

00:04:39.836 --> 00:04:42.896 align:middle
At the top, a YAML JSON schema config was added.

00:04:43.516 --> 00:04:46.126 align:middle
Down below, check out the new simplified config.

00:04:46.796 --> 00:04:51.116 align:middle
With the previous config, only controllers
in src/Controller would be loaded.

00:04:51.586 --> 00:04:56.386 align:middle
With this new config, any class with #[Route]
attributes in it will be loaded as controllers.

00:04:56.916 --> 00:05:00.176 align:middle
It's still the best practice to put
all your controllers in src/Controller.

00:05:00.476 --> 00:05:04.736 align:middle
But if you have a more complex app with
multiple domains and their own controllers,

00:05:05.006 --> 00:05:07.196 align:middle
these would be loaded no
matter where they're located.

00:05:08.046 --> 00:05:15.186 align:middle
Let's commit these changes with:
git commit -a -- amend Perfect!

00:05:15.356 --> 00:05:19.406 align:middle
Pop over to our app and refresh the homepage to
make sure everything's still running smoothly.

00:05:20.396 --> 00:05:23.436 align:middle
Nice, 7.4 upgrade was a success!

00:05:24.116 --> 00:05:27.136 align:middle
Next, we're going to update Doctrine
and explore a cool improvement

00:05:27.136 --> 00:05:28.766 align:middle
in the latest version of the ORM.

00:05:28.766 --> 00:05:29.656 align:middle
Stay tuned!

