This episode is for members only

Sign up to access "Build Your Own PHP Framework" right now.

Get started
Already a member? Sign in to continue
Playing
11. Registering service providers through config

Episodes

0%
Your progress
  • Total: 4h 45m
  • Played: 0m
  • Remaining: 4h 45m
Join or sign in to track your progress

Transcript

00:00
Going forward, any new service providers that we create, we want to be able to conveniently add these to config rather than having to come here and add new
00:07
lines to add a new service provider. You don't have to do this, but it kind of makes sense to add your service providers to config, so it's much easier to register them. So what we're going to do is we're going to move our app service
00:19
provider over to configuration. Let's figure out how we want this to look first of all. So over in our app config file, let's create a list of providers in here. And rather than new these up in here, let's just give the name to the service
00:34
provider, let's say app service provider class, later on, when we get to creating any more, we can just add them in here and we are good to go. Okay. So over in our bootstrap and app file, what do we now need to change?
00:45
Well, we can get rid of this and instead, now that we've registered just our config service provider in here, we can go and grab that and just iterate over it. So let's pull out our config from our container. So let's say container, get and config class.
01:03
And then we're going to iterate over each of the providers from that app config. So we'll just need to say config, get app providers, and we'll say as provider. Now, what we can do is we can use our container to add a service provider. And we want a new app, the fully qualified namespace of the provider
01:24
that we're iterating over. So remember, we just have our app service provider in here at the moment. So that will register our app service provider, but because we're iterating over this list, any new providers we add will be added to, okay, let's go over
01:37
and give this a refresh and everything looks like it's working. We are just dumping this out here, but let's go ahead and just return back to where we are now, and we'll go over to our app service provider and we'll just do something in boot.
01:50
So we know that we've got ignition in here, but just so we know that this is being registered, let's var dump app. And there we go. Great.
01:58
We've got that registered. So there we go. We've now got a really convenient way when we create a new service provider to just add it to this list and it will be automatically registered for us.
54 episodes4 hrs 45 mins

Overview

Starting completely from scratch, build a modern PHP framework with all the features you’d expect.

Whether you’re new to PHP or not, this is a great exercise for learning what happens under the hood, arming you with knowledge you can apply anywhere you use PHP.

We’ll cover routing, controllers, views, the container, accessing the database, models, authentication, config, CSRF protection, exception handling, pagination, validation, flashing messages and much more.

Let’s dive in and build a PHP framework, step-by-step!

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!