Тёмный

DI Container With Interface Support - Full PHP 8 Tutorial 

Program With Gio
Подписаться 55 тыс.
Просмотров 15 тыс.
50% 1

In this video, we add support for interface injection so that our DI container is able to resolve proper concrete implementation for the requested interface.
SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
👍 Smash the like button
🤝 Subscribe to the channel & turn the notifications on
💬 Post comments, any feedback is greatly appreciated
⭐ Become a Patreon: / programwithgio
THANK YOU!
COURSE PLAYLIST
• Learn PHP The Right Wa...
RESOURCES
Source Repo - github.com/gge...
Laravel's Service Container - laravel.com/do...
Laravel's Service Container Implementation Source (For Exercise) - github.com/lar...

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 126   
@abelmarkos5753
@abelmarkos5753 2 года назад
This Tutorial is without any question the best Modern PHP Turorial on youtube now
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you 🙏
@muchomorkowaPanienka
@muchomorkowaPanienka Год назад
totally agree!
@benderbg
@benderbg 16 дней назад
Learning parts of Laravel even before Laravel course is fully out is the best!
@ProgramWithGio
@ProgramWithGio 15 дней назад
Glad you like it. That was the plan to prepare you for Laravel & other frameworks
@JanKowalski-dm1mt
@JanKowalski-dm1mt 2 года назад
By far the best channel I discovered recently. The stuff you teach and the way you teach. Thank you sir.
@ProgramWithGio
@ProgramWithGio 2 года назад
Happy to hear that. Thank you
@azari_tar
@azari_tar Год назад
Thanks GIO! I got a job offer with your tutorials. I hope you always continue to train programming language becuase of your excellent teaching skills.
@ProgramWithGio
@ProgramWithGio Год назад
That's awesome, super happy to hear this. Great job buddy 💙. Thank you for support 💙
@ДалирХужамурадов
@ДалирХужамурадов 10 месяцев назад
Haven't seen any better explanation. Great Tutorial.
@ProgramWithGio
@ProgramWithGio 10 месяцев назад
Glad it was helpful, thank you
@Zubbee
@Zubbee 2 года назад
So I've been able to write tests for the container class. I can't believe it. The lessons and the personal support have been amazing and even unbelievably unexpected. I'm very thankful Gio. God bless
@ProgramWithGio
@ProgramWithGio 2 года назад
Glad to hear that, you're welcome & awesome job 👍
@neozes
@neozes 3 месяца назад
Truly quadruple A quality content!
@ProgramWithGio
@ProgramWithGio 2 месяца назад
Thank you for your support 💙
@josephajibodu2377
@josephajibodu2377 Год назад
I worked with Laravel for over 3 years before I fully understood Service Containers. (Actually I didn’t care, I started looking into it about 2 years ago) Now the understanding keeps getting better. Thanks Gio ❤
@ProgramWithGio
@ProgramWithGio Год назад
Great to hear, thank you 💙
@jeloace
@jeloace Год назад
Thank you! Thank you! Thank you! I've been building projects with Laravel for a while now and topics like this one always feels like a magic to me, something that i really don't understand, not until now. Now, reading the docs actually makes more sense now and much more interesting.
@ProgramWithGio
@ProgramWithGio Год назад
Super happy to hear that 🙌
@AhmedKhaled-fs5qo
@AhmedKhaled-fs5qo 2 года назад
thank you gio for this awesome series
@ProgramWithGio
@ProgramWithGio 2 года назад
You're welcome. Thank you for watching
@Canemahue
@Canemahue Год назад
I am brazilian and your english is very good to understand, also great classes.
@ProgramWithGio
@ProgramWithGio Год назад
Happy to hear that, thank you 💙
@Aemon-reoin9
@Aemon-reoin9 2 года назад
I've been stucking with the Laravel's container part and have no idea what it is used for. But after watching your videos, I think I'm getting to know what's going on. Thanks a lot for your tutorials and the hard work!
@ProgramWithGio
@ProgramWithGio 2 года назад
Glad to hear that, thank you 💙
@morteza55510
@morteza55510 Год назад
Same
@josephajibodu2377
@josephajibodu2377 Год назад
This advanced section is helping me dissect the Laravel framework Core. 😊
@ProgramWithGio
@ProgramWithGio Год назад
That's awesome, keep going 💙
@sadhakbj
@sadhakbj 2 года назад
I get completely amazed watching your videos
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you
@beautifulmenory
@beautifulmenory 2 года назад
Awesome tutorial ever I seen!!! Thx sit
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you 🙌
@truthteachers
@truthteachers Год назад
My contribution for all the understanding you have given me on DI subject.
@ProgramWithGio
@ProgramWithGio Год назад
Thank you for your support 🙌
@emekatimothyiloba699
@emekatimothyiloba699 Год назад
Thank you Gio
@ProgramWithGio
@ProgramWithGio Год назад
You're welcome
@mohamedmennour2188
@mohamedmennour2188 Год назад
the best tutorial for modern php, great gio
@ProgramWithGio
@ProgramWithGio Год назад
Thank you 🙌
@jordanbicanic9343
@jordanbicanic9343 8 месяцев назад
Thank you for your effort, this is not easy to explain. The subject is really overwhelming. I want to check something. For example if I'm making new class and passing basic types in constructor like int, string etc, then I would not use container bc it will throw an error of invalid type. I presume than it's ok to make new object of that class somewhere down the road bc it has no further dependencies.
@ProgramWithGio
@ProgramWithGio 8 месяцев назад
Yes, pretty much. If you class has dependencies of other classes & you want to auto resolve those dependencies then you would use container
@dawid_dahl
@dawid_dahl 2 года назад
Looking forward to a video with how to use/mock the DI Container when testing!
@ProgramWithGio
@ProgramWithGio 2 года назад
Good suggestion, might make a video on that, we'll see
@federicobau8651
@federicobau8651 2 года назад
Great video!
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you
@omaryahia
@omaryahia 10 месяцев назад
Amazing 🌟
@ProgramWithGio
@ProgramWithGio 10 месяцев назад
Thank you, cheers
@Zubbee
@Zubbee 2 года назад
Thanks for this lesson. Using Interfaces in DI makes a lot of sense. Thanks for teaching it. I've tried to go through the laravel repository and the laravel documentation. I'm only able to understand a percentage of the code and the documentation. I guess it now requires familiarity as I read more and use more. I'm hoping you atleast introduced laravel in the coming lessons cause I don't know much about it. Then the challenge to write some tests seem daunting... but I'll try it. Thanks and God bless
@ProgramWithGio
@ProgramWithGio 2 года назад
We dont cover Laravel in this series since its not Laravel series but we do cover some parts like Blade
@Zubbee
@Zubbee 2 года назад
@@ProgramWithGio Oh, okay cool. You are offering so much already. Just went through the lesson again and I want to look at the laravel DI container code again and see how much more i'll understand. Thank Gio
@memack101
@memack101 2 года назад
Thank you.
@ProgramWithGio
@ProgramWithGio 2 года назад
You're welcome
@montser1994
@montser1994 2 года назад
Good Work Thanks @Program With Gio
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you
@valentindobrica9584
@valentindobrica9584 2 года назад
Hi bro, can you please make tutorials about SOLID and some other patterns but with easy examples. :D
@ProgramWithGio
@ProgramWithGio 2 года назад
Thanks for suggestions 👍
@abdallakaram5376
@abdallakaram5376 2 года назад
thanks alot for the great Gio
@ProgramWithGio
@ProgramWithGio 2 года назад
You're welcome 👍
@constantinci
@constantinci 2 года назад
It was really great but it is missing something like interfaces aliases, kind of symfony has meaning "ServiceInterface $service1", "ServiceInterface $service2", not that I complain, but I just struggle with this kind of a necessity in a current project :D. Apart of that the whole series is as somebody mentionned above the best one on php I've seen so far.
@ProgramWithGio
@ProgramWithGio 2 года назад
Fair point. Thank you 🙌
@PietervandenHombergh
@PietervandenHombergh 2 года назад
Being able to mock the service is another reason to use the interface instead of a concrete classs
@ProgramWithGio
@ProgramWithGio 2 года назад
💯
@demetriuslewis6750
@demetriuslewis6750 2 года назад
@ProgrammingWithGio Hey Gio, Just started on the series and loving it so far. Thank you so much for your time and effort you put in on this. Are we going to work on an projects in this series for more hands on. If not, I'm cool with it I can start something small myself just if you have plans too then I'll wait because I have a long way to go to caught up anyway and it always helped me to see everything kind of come together.
@ProgramWithGio
@ProgramWithGio 2 года назад
Hey Demetrius. Thank you & glad you are liking it so far. Yes we will work on a project, I'm still deciding on the structure of the project & whether we'll use a framework or not but watch out for more information on that soon. I'll be asking you guys to help me decide, maybe hold a poll or something. More info on that will come soon.
@berkayb7053
@berkayb7053 2 года назад
waiting for laravel & vue or TALL stack content. much appreciated to your php series.
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you. I'm sorry for the super late reply, I was not notified of this comment & just came across it. I don't work with vue or TALL stack so I cant promise content around them anytime soon. However, I'll be making more Laravel content soon.
@gravityarm9240
@gravityarm9240 2 года назад
Very good level
@ProgramWithGio
@ProgramWithGio 2 года назад
Glad you liked it, thank you
@rudeadyet1992
@rudeadyet1992 2 года назад
Hey, thanks for this awesome tutorial mate. I'm confused where there are different dependencies with the same interface but how can I use them at the same time. For example: If I want to use both PaddlePayment and StripePayment for different purposes. How can I do this? I tried setting up containers for both but one would overwrite another. Btw, I'm using Yii2. :) Thanks, heaps!
@ProgramWithGio
@ProgramWithGio 2 года назад
One way would be to use a factory pattern and do something like PaymentGatewayFactory::make('stripe') or something like that & pass paddle if you need paddle instance also. So you could inject the interface for PaymentGatewayFactory as a dependency and just make the instances of the gateways that you need.
@rudeadyet1992
@rudeadyet1992 2 года назад
@@ProgramWithGio Hey thanks for that. But wouldn't that make PaymentServiceInterface rules (eg: execute()) useless, because when we inject FactoryInterface, the MainService (eg:Invoice) wouldn't know which method of PaymentService to execute? If you could point to an example, would be great. Thanks, heaps! :)
@ProgramWithGio
@ProgramWithGio 2 года назад
No because PaymentGatewayFactory::make will return class that implements payment gateway interface. I'll write a quick example and send you screenshot
@rudeadyet1992
@rudeadyet1992 2 года назад
@@ProgramWithGio Awesome, thanks so much! :)
@ProgramWithGio
@ProgramWithGio 2 года назад
Here is a quick thing I wrote up, haven't tested it though but that's the gist of it: prnt.sc/1xm0nql Let me know if you have any questions on that.
@DigitaSkills101
@DigitaSkills101 2 года назад
Will you be making a series for larvel as well or any other framework or will be including larvel in this series
@ProgramWithGio
@ProgramWithGio 2 года назад
I might make separate Laravel series down the road. This series will include a little bit of SlimPHP at the end & some Symfony components. We do cover some parts of Laravel in this series like the DI container & blade templating engine.
@akinniyiakinpelumi8515
@akinniyiakinpelumi8515 2 года назад
I believe you've already composer dump-autoload the whole project using psr-11 right? because I'm new to PSR and Dependency Injection and I really don't see where you use any include or require
@ProgramWithGio
@ProgramWithGio 2 года назад
PSR-11 is container interface not really about autoloading. We no longer use include/requires since we started using composer & autoloading back in section 2 lesson 2.5. You can check the composer & autoloading lesson for that: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-rqzYdHdyMH0.html You can also see the full list of lessons in outline form for the series here: github.com/ggelashvili/learnphptherightway-outline
@akinniyiakinpelumi8515
@akinniyiakinpelumi8515 2 года назад
@@ProgramWithGio great, I’ll check out the link, Thanks
@ArtcodEAscetik
@ArtcodEAscetik Год назад
i don't understand the principle of caching for a service container. Is that about some serialization?
@ProgramWithGio
@ProgramWithGio Год назад
Not really, you can read about some caching within PHP-DI documentation, PHP-DI is something we use later in the series as well so it would be a head start for you if you are following along php-di.org/doc/performances.html
@po3881
@po3881 Год назад
Something I don't understand. If $entry = PaymentGatwayService::class which you say is a fully qualified class name, why isn't that callable?
@ProgramWithGio
@ProgramWithGio Год назад
::class just returns the class name, it is not directly callable or invokable
@zerqs
@zerqs 2 года назад
Awsome!. but how woud you handle two or more classes sharing same interface?
@ProgramWithGio
@ProgramWithGio 2 года назад
You bind one of the classes that you want to resolve when interface is injected
@aleksandrkanygin2672
@aleksandrkanygin2672 2 года назад
Hi, what if we have multiple different implementations of some interface as dependencies? How would the container know which concrete class to resolve? My guess is that modifications have to made to container methods? Like storing all the implementations in array (entries array would have to be 2 dimensional array), and modifying get and set, so it would work with interfaces in a special way? Or i'm overcomplecating things?
@ProgramWithGio
@ProgramWithGio 2 года назад
You wouldnt use multiple implementations of the same interface at the same time typically, you would choose one & bind that in container. If you need to pick & choose which implementation you need to use based on some other factor/variable then you would create a factory class with a make method that creates the object of the correct implementation
@valentindobrica9584
@valentindobrica9584 2 года назад
Hi man, looking again and again at your videos. I have a question at 10:10, for example i have an API which process some transactions with different payment methods, how to avoid hard-code the payment like in your example, the PaddlePayment, let's say in your APP you have to use both methods, or many methods, the request should contain the method which we are going to use, and based on the name of the method we load the exactly Payment Class? like a factory pattern? Thanks for your videos man, i suggest to make some courses for udemy, or make your own buisness..you are great.
@ProgramWithGio
@ProgramWithGio 2 года назад
Hello, yes you would use factory pattern. Here is an example I made (haven't tested) for someone else who had a similar question prnt.sc/1xm0nql Thanks alot for the kind words 🙌
@valentindobrica9584
@valentindobrica9584 2 года назад
@@ProgramWithGio Thanks much for answer. I have to see how to implement this in Lumen, i'm currently working on the job, i implement a new payment method for the wiretransfer transactions and basically all the transactions with wiretransfer should be processed via this method i implemented. Now i made it tight couple, i'm thinking to refactor it a little bit so in the feature if they add new methods, to be easy for extensions and i'm not really sure how to make it on Lumen with the DI container of lumen.
@ProgramWithGio
@ProgramWithGio 2 года назад
I haven't worked with Lumen but it's just light version of Laravel as far as I know. You should still be able to use the built in DI container, so you should be able to easily implement what I showed in screenshot. lumen.laravel.com/docs/8.x/container
@truthteachers
@truthteachers Год назад
Hi Bro, sorry to fallback. I am trying to understand each line of code and learn. I have problem with the line "return $entry(this)". I do not understand that syntax. What does "$entry(this)" do? What does "this" refer to?
@ProgramWithGio
@ProgramWithGio Год назад
This refers to the container object, so it's passing the container object as an argument. Entry can be a closure so that's what that line does, if it's callable it will call it and pass the current container instance as an argument. I think I mentioned that in the video.
@truthteachers
@truthteachers Год назад
@@ProgramWithGio Thank you for the clarification. I am not sure you mentioned this way. I will replay again. Your presentation runs quite fast without pause or breaks. We could easily miss important info like this. Sorry, about this but i faced this problem many times and that is why i am relearning the section 3 but this time slowly and yet i seem to miss things. I must getting old.😄
@ProgramWithGio
@ProgramWithGio Год назад
@@truthteachers no worries 👍
@bakosyy
@bakosyy 10 месяцев назад
Hey Gio. Thanks for the tutorial. Could you please check my pull request where I implemented tests for Container class. Thank you in advance
@ProgramWithGio
@ProgramWithGio 10 месяцев назад
I did, good job 💙
@theobellash6440
@theobellash6440 2 года назад
05:30 if it works don’t touch it anymore…
@ProgramWithGio
@ProgramWithGio 2 года назад
Not sure I understand, maybe wrong timestamp?
@andreameparishvili5468
@andreameparishvili5468 2 года назад
Bro you better check your mail i send you someting!
@ProgramWithGio
@ProgramWithGio 2 года назад
Ok? Should I be excited or scared? 😁
@andreameparishvili5468
@andreameparishvili5468 2 года назад
@@ProgramWithGio go ahead
@أحمدكلش-ض3ع
@أحمدكلش-ض3ع Год назад
it looks like laravel writers were cheating from us all this time 😂
@ProgramWithGio
@ProgramWithGio Год назад
Why? 😁
@أحمدكلش-ض3ع
@أحمدكلش-ض3ع Год назад
@@ProgramWithGio I was just kidding case there is some similarty 😂
@ProgramWithGio
@ProgramWithGio Год назад
@@أحمدكلش-ض3ع 😁😁
@relskull3324
@relskull3324 2 года назад
now i can imagine how hard hardware language like java c++ c c# python or... I was completely confused when I saw these 2 videos i mean this and previous i've seen this 2 video 2 times but still a bit confusing for me your tutorial is underrated my iq is 101 which is not useful for programming at all :)programming requires at least an iq 130 you don't understand what i mean because you have high iq but finally with your tutorial i can write something like laravel routing and make tutorial with it for make money, and of course i see tutorial of c++ or c from basic to advanced these tutorials are even purchased for gaming modding hacking like trainer but I could not even make a button the reason is not my iq the reason is a bad tutorial because compared to your tutorial all of them is just beginner not even intermediate but can't support you on patreon maybe in the future if i alive and well , also spend almost $120 for web programming html css php that mean equal to $3300 now in country i living but all even tutorial is purchased they are not even half your intermediate tutorial i just want to say thank you i hope you could change the future programming tutorial and do not despair in this way because there are people who say wrong things out of jealousy i have instagram channel but I do not log in at all maybe for business because it's filter and I do not like this type of social network i just spend my time in youtube also youtube is filter but is use free vpn but also i have no subscriber i just can hit the like button and make playlist for your video i know doesn't effective but that's the only thing I can do
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you for kind words. Your iq is fine, the problem is not your iq. When I started coding I had no idea what DI containers were or how to write clean code, etc & even sometimes now it takes me awhile to grasp & understand concepts. Everyone learns at different pace, some people learn & pick up concepts in one shot, I on the other hand sometimes need to watch a tutorial 2-3 times & practice to really understand it. You learn it from practice & experience. I'm really glad that you find my tutorials helpful & giving my videos a like really helps me out a lot so thank you so much & that is enough to support the channel. Cheers 🙌
@truthteachers
@truthteachers Год назад
Bro, when you rename a file, e.g StripePayment, you are using PHPStorm which does the refactoring. This does not happen with VS Code and therefore we miss a number code change and things dont work.
@ProgramWithGio
@ProgramWithGio Год назад
But that's ok though, error message is self explanatory so you should be able to fix it. I don't use VS Code unfortunately
@vmaysov
@vmaysov 9 месяцев назад
Thank you, very interesting! Can you show middlewares principle?
@ProgramWithGio
@ProgramWithGio 9 месяцев назад
I explain that later in the course. Keep watching
@vmaysov
@vmaysov 9 месяцев назад
@@ProgramWithGio , i'll do:) brilliant course, so much helpful info. You are hero!
@ProgramWithGio
@ProgramWithGio 9 месяцев назад
@@vmaysov thank you 💙
@abdfadee8267
@abdfadee8267 10 месяцев назад
@ProgramWithGio
@ProgramWithGio 9 месяцев назад
👋
Далее
PHP Generators Explained - Full PHP 8 Tutorial
25:47
Просмотров 30 тыс.
PHP-DI - сервис контейнер
48:05
Просмотров 11 тыс.
Lets Build an IoC Container using PHP
27:14
What is Dependency Injection PHP - in 5 Minutes
5:06