WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.086 --> 00:00:03.796 align:middle
We've already helped push
forward a pull request,

00:00:04.216 --> 00:00:07.216 align:middle
solved an issue and even reported a bug.

00:00:07.776 --> 00:00:10.276 align:middle
Hello! We deserve cake!

00:00:10.706 --> 00:00:14.746 align:middle
And we deserve to move up
one more level of difficulty:

00:00:14.746 --> 00:00:19.036 align:middle
it's time to contribute new
code with a pull request.

00:00:19.766 --> 00:00:24.546 align:middle
Let's look at an issue I found: #27835.

00:00:24.546 --> 00:00:26.366 align:middle
This comes from the Security component.

00:00:27.356 --> 00:00:33.256 align:middle
Let me give you some background: if you try to
access a protected page as an anonymous user -

00:00:33.446 --> 00:00:39.306 align:middle
like /admin - Symfony stores that
URL to a special key in the session.

00:00:40.106 --> 00:00:46.816 align:middle
Then, after you login, Symfony reads this
key and redirects the user back to that URL.

00:00:48.056 --> 00:00:53.006 align:middle
Occasionally, it's useful to manually
set that session key to control

00:00:53.006 --> 00:00:55.346 align:middle
where the user goes after logging in.

00:00:55.346 --> 00:01:00.036 align:middle
To help with that, Symfony has TargetPathTrait.

00:01:01.376 --> 00:01:05.576 align:middle
The problem is that, to use
its saveTargetPath() method,

00:01:05.976 --> 00:01:08.866 align:middle
you need something called the "provider key"...

00:01:09.236 --> 00:01:12.466 align:middle
which is actually just the
"name" of your firewall.

00:01:13.276 --> 00:01:16.966 align:middle
You could hardcode it, but, that
really shouldn't be necessary.

00:01:17.926 --> 00:01:22.996 align:middle
In a recent version of Symfony, a feature was
added so that you can read the firewall name

00:01:23.136 --> 00:01:29.976 align:middle
by getting a FirewallMap object, calling
getFirewallConfig() and then calling getName().

00:01:29.976 --> 00:01:38.486 align:middle
Phew! But, here's the problem: that FirewallMap
service is not an autowireable service.

00:01:38.946 --> 00:01:41.436 align:middle
That makes it inconvenient to use.

00:01:41.956 --> 00:01:47.936 align:middle
And, one of the core contributors gives a reason
behind why that service is not autowireable.

00:01:48.926 --> 00:01:50.456 align:middle
You can work around this.

00:01:50.626 --> 00:01:56.566 align:middle
But, I had an idea: I'm not even sure
if it's a good idea, but let's try it.

00:01:57.276 --> 00:02:04.466 align:middle
What if we created a new TargetPathHelper class
that allowed you to set this "target path",

00:02:04.816 --> 00:02:07.356 align:middle
without needing the provider key.

00:02:08.676 --> 00:02:13.856 align:middle
Internally, it would use the FirewallMap
to figure it out automatically.

00:02:14.976 --> 00:02:20.886 align:middle
The end user could use this new class without
needing to worry about the firewall name at all.

00:02:21.726 --> 00:02:24.016 align:middle
If you don't completely understand, that's ok.

00:02:24.256 --> 00:02:31.276 align:middle
The important thing is the process we're
going to use to bring this new idea to life!

00:02:31.276 --> 00:02:36.836 align:middle
Go back to PhpStorm: let's change our project
to look only at the symfony/ directory.

00:02:40.336 --> 00:02:43.306 align:middle
Then, find the terminal that's
in this directory.

00:02:46.776 --> 00:02:49.886 align:middle
We're still on the feature
branch from colinodell.

00:02:49.886 --> 00:02:55.736 align:middle
Start by making sure your copy of Symfony
is up to date by running: git fetch origin

00:02:56.626 --> 00:02:59.106 align:middle
And then create a new branch for our feature:

00:03:00.046 --> 00:03:09.476 align:middle
git checkout -b target-path-helper
origin/master This is important:

00:03:10.306 --> 00:03:14.876 align:middle
we just created a new branch based
off of Symfony's master branch.

00:03:15.596 --> 00:03:20.406 align:middle
Why? Why not base the branch
off of Symfony's 4.1 branch -

00:03:20.796 --> 00:03:22.906 align:middle
that's the currently-released version?

00:03:23.806 --> 00:03:25.986 align:middle
Let's talk about Symfony's branching system.

00:03:26.466 --> 00:03:28.176 align:middle
It's... kinda simple.

00:03:28.176 --> 00:03:33.256 align:middle
If you're adding a feature, it should
always be made to the master branch.

00:03:33.846 --> 00:03:40.996 align:middle
Then, it will be included in the next Symfony
minor release: in this case Symfony 4.2.

00:03:41.616 --> 00:03:45.966 align:middle
But if you're fixing a bug, you
should fix that in the oldest,

00:03:46.126 --> 00:03:49.136 align:middle
supported branch where the bug exists.

00:03:49.166 --> 00:03:53.966 align:middle
For example,: if you found a bug
that was introduced in Symfony 3.4,

00:03:54.316 --> 00:03:58.326 align:middle
create your branch based off of origin/3.4.

00:03:59.046 --> 00:04:02.876 align:middle
But, if a bug was first found in version 3.2,

00:04:03.236 --> 00:04:08.616 align:middle
you actually would not base your
branch off of Symfony's 3.2 branch.

00:04:09.726 --> 00:04:13.876 align:middle
Why? Because Symfony 3.2 is no longer supported.

00:04:15.056 --> 00:04:19.066 align:middle
To help understand this, go to
https://symfony.com/roadmap.

00:04:19.176 --> 00:04:27.616 align:middle
At this moment, only three versions of
Symfony are supported: 2.8, 3.4 and 4.1.

00:04:27.806 --> 00:04:36.036 align:middle
So, if you found a bug in Symfony 3.2, you
would fix it in 3.4, because that's the oldest,

00:04:36.106 --> 00:04:39.076 align:middle
supported version of Symfony
that contains the bug.

00:04:39.076 --> 00:04:45.396 align:middle
If you found a bug in Symfony 2.7,
you would fix it on the 2.8 branch.

00:04:45.906 --> 00:04:49.866 align:middle
But... if I fix a bug in 2.8...

00:04:49.986 --> 00:04:53.926 align:middle
won't that bug still exist in 3.4 and 4.1?

00:04:54.866 --> 00:04:57.276 align:middle
Ah, a very good question.

00:04:57.676 --> 00:04:59.166 align:middle
But... no!

00:04:59.596 --> 00:05:05.256 align:middle
The core team routinely merges
all old branches - like 2.8 -

00:05:05.616 --> 00:05:10.676 align:middle
up into the newer branches, like 3.4 and 4.1.

00:05:10.776 --> 00:05:18.046 align:middle
If you fix a bug in 2.8, it will also be
merged &amp; included in all newer versions.

00:05:18.686 --> 00:05:22.936 align:middle
Booya! Anyways, because this
will be a new feature,

00:05:23.296 --> 00:05:26.116 align:middle
our branch is based off of origin/master.

00:05:26.686 --> 00:05:28.686 align:middle
And now, we're ready to code.

00:05:29.366 --> 00:05:30.256 align:middle
Let's do that next!

