Identifying Session Dependency 0:00Let's take a closer look at this little simple class we have here. Specifically, I want you to notice that we are referencing Session, so it looks like we have a dependency here that we haven't yet composed. All right, let's see how we might do that. Well, as always, you can type it out. That would be one way. Or I can press Command-N on the Mac and create a constructor. Or you can create a little snippet, something like underscore C, tab, and that will create the code for you. Any of these work. Now I will reference Laravel's Session class.Any of these work. Now I will reference Laravel's Session class. Now, we have a couple ways to do this. I know that it's within Illuminate Session Store, so I could reference that full class name, like so, and then assign the fields this Session equals Session. Notice how much typing this is, though. Protected Session. And only now are we finished. So it seems like a lot of this could really be automated, right? Constructor Autocomplete Types 0:49And only now are we finished. So it seems like a lot of this could really be automated, right? And the answer is, of course it can. So let's try it again. Command-N, create a constructor. And now this time, rather than typing out that full class path, I don't have to. I can just type the name of the class itself. In this case, it's called Store, and you'll notice that we can autocomplete that full path.In this case, it's called Store, and you'll notice that we can autocomplete that full path. Now I will give it a name, Session. And even better, if I hit Option-Return or Enter, notice that we can initialize the fields. So let's initialize Session, and that will both assign it, create the field, and also give it a dot block. But now we can take this further, definitely. We probably don't want to reference the full path here. Instead, I want to use it at the top, right? Importing Classes Automatically 1:29We probably don't want to reference the full path here. Instead, I want to use it at the top, right? Well, once again, if I place my cursor on the class name and hit Option-Return, notice there's an Import Class option. So let's run that. It will add a use statement at the top, update this code, and also update the dot blocks. But as helpful as that is, we can streamline this further. So let's remove all of it and start again. Okay, third pass. Enabling Auto-Import Setting 1:52So let's remove all of it and start again. Okay, third pass. Command-N, create the constructor. Now we want the Store class, but notice if I hit Return, it just adds it here. It would be nice if, when I hit Return, it immediately imports it at the top. All right, let's add that. Go to Preferences, and if I search for Import, you'll see that I'm already on there. Make sure that this checkbox is enabled. Auto-Import in Namespace Scope. All right, so now if we try it again, this should be a lot better. Creating Constructor Live Template 2:16Auto-Import in Namespace Scope. All right, so now if we try it again, this should be a lot better. So I type Store, Return, and now notice it stays the same, but we're using it at the top. So now give it a name, Session, Option-Return, initialize the fields, and we're done. Even better though, why don't we create a live template? So Shift-Shift, Live Templates here, and here within PHP, let's add a new one, and the abbreviation will be underscore C for a constructor. Okay, all we need here is construct, and we'll set two stop points. This will be the end, and we'll say args. Finally, the context will be PHP.This will be the end, and we'll say args. Finally, the context will be PHP. All right, that should do it. So now, as our fourth pass, this will be the most streamlined version. Underscore C, Tab. We want our Store class, which we will auto-import. Next, we'll give it a name of Session, Option-Return, initialize the fields, and we're done. So clearly, this is way faster than writing out all of that code over and over and over. And of course, if you want to shorten this as well, I can hit Option-Return and simplify the fully qualified name.And of course, if you want to shorten this as well, I can hit Option-Return and simplify the fully qualified name. All right, that does it for this episode.