Recipe Upgrades: Part 2!
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.
With a Subscription, click any sentence in the script to jump to that part of the video!
Login SubscribeRun:
composer recipes:update
Next up is doctrine-extensions-bundle
. This one... when we look... just modified a comment! Easy!. So commit that... and then move onto debug-bundle
.
symfony/debug-bundle Recipe
composer recipes:update
I'll clear the screen and run that. This made two changes. Run:
git status
The first change was that it deleted an environment-specific file... and moved it into the main file. The second change, which isn't very common in recipe updates, is that in config/bundles.php
, it previously loaded DebugBundle
in the dev
environment and test
environment. We now recommend only loading it in the dev
environment. You can load it in test
environment, but it tends to slow things down, so it's been removed by default.
// ... lines 1 - 2 | |
return [ | |
// ... lines 4 - 9 | |
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], | |
// ... lines 11 - 24 | |
]; |
Easy! Commit those changes... and keep going!
symfony/monolog-bundle Recipe
composer recipes:update
Next up is symfony/monolog-bundle
. This one does have a conflict, but it's fairly simple. Previously, we had environment-specific files in the dev/
, prod/
, and test/
directories. These have all been moved into the central config/packages/monolog.yaml
file. The only reason it conflicted on my project is because I had previously created this file in a tutorial to add a new markdown
channel. I'll move my markdown
channel down here... and keep the new stuff.
monolog: | |
channels: | |
- markdown | |
// ... lines 4 - 63 |
Below this, you can see the dev
configuration for logging, the test
config, and prod
config. Again, if you had custom config in your old files, make sure you bring that over to the new file so it doesn't get lost.
// ... lines 1 - 5 | |
when@dev: | |
monolog: | |
handlers: | |
main: | |
type: stream | |
// ... lines 11 - 26 | |
when@test: | |
monolog: | |
handlers: | |
main: | |
type: fingers_crossed | |
// ... lines 32 - 40 | |
when@prod: | |
monolog: | |
handlers: | |
main: | |
type: fingers_crossed | |
// ... lines 46 - 63 |
Add these changes... and... commit.
symfony/routing Recipe
Then right back to:
composer recipes:update
We're getting closer! Update symfony/routing
. Let's see. This deleted another environment-specific config file. Yay! Less files! It also highlights a new default_uri
config that you set if you ever need to generate absolute URLs from inside a command.
Previously, you accomplished this by setting router.request_context
parameters. It's easier now, and this advertises that.
framework: | |
router: | |
utf8: true | |
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands. | |
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands | |
#default_uri: http://localhost | |
when@prod: | |
framework: | |
router: | |
strict_requirements: null |
Commit this stuff... and let's keep going!
symfony/security-bundle Recipe
composer recipes:update
We've made it to symfony/security-bundle
. This one has a conflict... and it's inside config/packages/security.yaml
. There are a few important things happening. The recipe update added enable_authenticator_manager: true
. This enables the new security system. We're going to talk about that later. For now, set this to false
so that we're still using the old security system.
security: | |
// ... lines 2 - 9 | |
enable_authenticator_manager: false | |
// ... lines 11 - 64 |
It also added something called password_hashers
, which replaces encoders
. We're also going to talk about that later. For right now, I want you to keep both things.
security: | |
encoders: | |
App\Entity\User: | |
algorithm: auto | |
// ... lines 5 - 11 | |
password_hashers: | |
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' | |
// ... lines 14 - 64 |
There's also a conflict down on the firewall. The important change is that the new recipe has lazy: true
. That replaces anonymous: lazy
, so we can go ahead and keep that change... but use the rest of our firewall.
security: | |
// ... lines 2 - 20 | |
firewalls: | |
// ... lines 22 - 24 | |
main: | |
lazy: true | |
provider: app_user_provider | |
guard: | |
authenticators: | |
- App\Security\LoginFormAuthenticator | |
logout: | |
path: app_logout | |
// ... lines 33 - 64 |
Oh, and at the bottom, we get one shiny new when@test
section, which sets a custom password hasher. You can read the comment. This accelerates your tests by making it much faster to hash passwords in the test environment, where we don't care how secure our hashing algorithm is.
// ... lines 1 - 51 | |
when@test: | |
security: | |
password_hashers: | |
# By default, password hashers are resource intensive and take time. This is | |
# important to generate secure password hashes. In tests however, secure hashes | |
# are not important, waste resources and increase test times. The following | |
# reduces the work factor to the lowest possible values. | |
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: | |
algorithm: auto | |
cost: 4 # Lowest possible value for bcrypt | |
time_cost: 3 # Lowest possible value for argon | |
memory_cost: 10 # Lowest possible value for argon |
Let's add the files... then keep going.
symfony/translation Recipe
Next up is symfony/translation
. This isn't important... it just shows off some new config options. Those are all commented out, so... they're cool to see, but not important.
framework: | |
// ... line 2 | |
translator: | |
// ... lines 4 - 6 | |
# providers: | |
# crowdin: | |
# dsn: '%env(CROWDIN_DSN)%' | |
# loco: | |
# dsn: '%env(LOCO_DSN)%' | |
# lokalise: | |
# dsn: '%env(LOKALISE_DSN)%' |
Commit and... keep going!
symfony/validator Recipe
Next is symfony/validator
. Simple! This moved the config from config/test/validator.yaml
into the main validator.yaml
.
Commit that!
symfony/web-profiler-bundle Recipe
Let's update one more recipe right now: web-profiler-bundle
. Can you guess what it did? It added more environment-specific config. So the config from dev/web_profiler.yaml
and test/web_profiler.yaml
was moved into the main web_profiler.yaml
. The same thing happened for routes. The config from dev
was moved into a new config/routes/web_profiler.yaml
. Let's commit that and... phew! We've almost done it! Just two recipes left!
Let's update those next. The WebpackEncoreBundle recipe will also give us a chance to upgrade our JavaScript to the new Stimulus 3 version.
Hello again.
I moved onto updating the symfony/translation recipe and why on earth is it trying to delete my config/services.yaml?
`
Which outdated recipe would you like to update? (default: 0)
[0] stof/doctrine-extensions-bundle
[1] symfony/monolog-bundle
[2] symfony/swiftmailer-bundle
[3] symfony/translation
[4] symfony/validator
[5] symfony/web-profiler-bundle
[6] symfony/webpack-encore-bundle
> 3
Updating recipe for symfony/translation...
Yes! Recipe updated!
Run git status or git diff --cached to see the changes.
When you're ready, commit these changes like normal.
Kevins-MBP-2:www.site.com kevin$ git status
On branch develop
Your branch is ahead of 'origin/develop' by 15 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
`
Seems aggressive and I didn't see that it did that for you in the video.
Thoughts?
-Kevin