در حال بارگذاری ...

Installing PHP Companion0:00

Now, Sublime PHP Companion is basically a mandatory install. You're definitely going to want this. It allows for automatic imports, we can autocomplete namespaces, or the classes that we pull in. Really, really useful, and you can browse all of the documentation on GitHub, of course. Let's pull it in. Install package, PHP Companion, and there it is. So now, it won't pop up a readme, but we can go down to package settings, PHP Companion, and we can take a look at the defaults here. And once again, you can read more about that at GitHub. But let's just see some of the things we can do here. All right, expand fully qualified class name. So this command expands the class under the cursor to its fully qualified class name. All right, let's give that a shot. So we're going to go to maybe AuthServiceProvider, and we want to reference User here. User, and then there is no key map just yet, but we will.

Expanding Class Names0:43

name. All right, let's give that a shot. So we're going to go to maybe AuthServiceProvider, and we want to reference User here. User, and then there is no key map just yet, but we will want to add one. But until then, I could do php Companion, and then here's the command we're working on. So we run that, and now we've pulled up two different options. Do you want this User or that? We will use the top one, and there you go. Very, very simple. But you know what, especially for some of those confusing Symfony classes that you're not as familiar with, like I'm trying to think of one. How about this, ConsoleEvents, and you're not sure what the full namespace is. Well, you could just say ConsoleEvents, and then once again, run the command or the keystroke to expand that. Incredibly useful. Now another option you can do here is if we pull up our php Companion commands, we could do find use. Now what this does, if we scroll up, is it

Auto-Importing Uses1:26

the keystroke to expand that. Incredibly useful. Now another option you can do here is if we pull up our php Companion commands, we could do findUse. Now what this does, if we scroll up, is it automatically imports it at the top. So once again, if I get rid of that just to prove it to you, we run findUse again, it will find the full class path, and it's going to use it at the top of your file. So again, I get an enormous amount of use out of this. So like you need to use your User class, we're going to pull that in, we'll be specific about what we need, and then blah, blah, blah, and everything will just work. All right, very useful. Now we will assign these to keystrokes, but just to keep playing around. You're familiar with these top two now. importNamespace does need a little configuring because it's a little inconsistent from my experiences, but that's a way to automatically add the namespace at the top based upon the file name.

Generating Constructors2:10

namespace does need a little configuring because it's a little inconsistent from my experiences, but that's a way to automatically add the namespace at the top based upon the file name. Here's another one I really like, insert php constructor. So let's just see what that does at the very top. Let's go to User. You would never add a constructor to User, but just as an example. All right, so once again, insert constructor, and now what you'll see is it creates the method if it doesn't exist, but then it also has an option for the property. So if you are accepting name, you can see how that works. So now if I were to do it again, because the constructor already exists, well this time it's only going to add a new property here. Again, you're going to get a huge amount of use out of this. Sometimes things like traits can be a little tricky and you'll just have to manually fix that if that's an issue. But yeah, once the

Configuring Default Visibility2:52

Again, you're going to get a huge amount of use out of this. Sometimes things like traits can be a little tricky and you'll just have to manually fix that if that's an issue. But yeah, once the constructor exists, you don't have to worry about that. Now you'll see here that it defaults to private, but you can override this if you want. So again, the default settings. Let's see. Let's look for private. Yeah, here's the default visibility. I don't use private that much. So if I want to change that, of course I can just go to my user settings here and we will override the visibility to be protected. All right, and that should do it. So now let's give it another shot and you'll see that it is defaulting to protected now. Now next up, let's just get rid of all of that here. If we switch back, we can also do implement. So you place the cursor on a class, you hit a keystroke once you define it, and then it will find the matching interface.

Implementing Interfaces Automatically3:36

all of that here. If we switch back, we can also do implement. So you place the cursor on a class, you hit a keystroke once you define it, and then it will find the matching interface and implement all of the various methods. So like let's imagine we wanted to implement UrlRoutable. So real quick, let's take a look at that. That is a routing interface where we can define the routeKey and the getRouteKey methods, because sometimes you will want to implement these. Okay, so once again, we could import that full path. So find use, and now that pulled that in. Next, we lost it. I can use implement interface. Okay, so now it's going to let you know which method do you want to add or all of them. We run it, and now if we scroll down to the bottom, those have been added for you. Now just remember, you need to have your cursor in the correct location. So if I delete that and we run it again, it's not going to work. So yeah, just make sure

Binding Keyboard Shortcuts5:57

You're really importing the class that relates to what you've typed out here. So yeah, if you want to try that, and then you do user, option, or alt I, and then I can pull that in, and that's really, really fast. Okay, let's pull in console events, just a random class, option I, and now I have pulled that in. Now, you won't get any feedback, so that can sometimes be confusing, where you have to confirm, like, did it get pulled in? But nonetheless, that does work. Okay, what other things, what else do we want to bind here? Alt I for find use, import namespace I don't use too much, implement, sometimes I just, I write it out manually, so I will just use the command palette, since it's not as common, expand, you could always do maybe alt plus E for expand, go to definition scope, I don't use that, insert PHP constructor, maybe alt C, or sometimes I even use, like, a Vim syntax, where I have a comma,

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟