‫Okay, so in the last video we created a very simple auto loader that will that will auto load these
‫class files for us.
‫And we use the auto load register function.
‫And this is okay for really small applications.
‫But we're going to want to add namespaces and subfolders.
‫And this isn't going to cut it.
‫So we want to use an auto loader that adheres to the PSR four standard.
‫And we can actually set that up using composer.
‫So composer is a dependency or a package manager for PHP.
‫If you're coming from the JavaScript world then you're probably familiar with npm, which is the node
‫package manager.
‫This is very similar, but it's for PHP.
‫All right.
‫Now in and I'm just making comparisons to Node.js because I know a lot of people that watch my stuff
‫are JavaScript developers.
‫Just ignore this if you're not.
‫But with NodeJS and npm you have a package.json file which is a manifest that has your app information,
‫stuff like that.
‫With composer you have a composer dot json file which is very similar.
‫You have your app information, but you can also specify an auto loader, a PSR for auto loader, and
‫you can specify where you want that auto loader to load files, which for us will be framework and this
‫app folder.
‫And you can also specify namespaces which we're going to get to in the next video.
‫So in order to do that we need to create that Composer.json.
‫So let's go into the root here create a new file called composer dot Json.
‫And we're just going to add some basic information here first in Json format.
‫So let's say name.
‫So this is our app name.
‫And typically what you'll do is use your GitHub username slash.
‫And then whatever the repo that you're going to whatever the repo name is for this project.
‫So I'm going to say work dash php okay.
‫And then I'll put a description.
‫So for that, I'll just say job listing.
‫Application and then we'll put authors.
‫So authors is an array.
‫You can have more than one author if you want.
‫It's just going to be an object with the name of the author.
‫And you can put yourself here.
‫And then email.
‫I'll just say support at Traversy media.
‫All right.
‫So authors, now I'm going to go under this bracket here.
‫And the next thing I want to add is the auto load.
‫So we want to say auto load.
‫And then in here we want to use PSR dash four okay.
‫So we're saying we want to use this PSR four auto loader.
‫And this will take place of the custom one that we created.
‫Now in here we have to specify which namespaces and folders we want to use this with.
‫So we're going to have a namespace called framework.
‫And we want to just put double backslashes here so we can escape this one.
‫And then.
‫For the value.
‫We're going to put the name of the folder which is going to be Frame Framework.
‫Framework.
‫Slash.
‫Forward slash.
‫And then we're going to copy that down.
‫And we also want to do app.
‫All right, so let's do that.
‫Save it.
‫Now we have to run a command called composer install, just like you would run npm install.
‫So let's open up our terminal, make sure you're in the current work folder.
‫And I'm going to run composer.
‫Install.
‫Okay.
‫Now in the index.php.
‫We're not going to need this anymore.
‫I'm actually going to comment it out just so it's still there.
‫And all we'll have to do to include this, this auto loader is at the very top we're going to require.
‫Let's say require double underscore dir.
‫And then we're going to concatenate onto that slash dot dot slash vendor.
‫And you notice we have a vendor folder.
‫Now when you install something with composer it goes in this vendor folder.
‫Just like if you install something with npm it goes in the node modules folder.
‫So it's going to be vendor slash and then autoload dot PHP which if we look in you can see right here
‫auto load PHP.
‫I'm not going to go over this file but just know we can use that okay.
‫Now if I reload my my application.
‫You'll see it says class router not found.
‫So it's not working right now.
‫And the reason for that is we specified namespaces in that composer.json.
‫So we don't have any namespaces.
‫We don't have the framework or app namespace created.
‫So in the next video we're going to continue with this.
‫And we're going to add those namespaces.