PHP For Beginners, Ep 35 - Make Your First Service Container

Поделиться
HTML-код
  • Опубликовано: 16 янв 2023
  • In this episode, we'll discuss the concept of a service container, and how it can help us organize our code and remove the need to manually construct the same dependencies over and over again. Watch this full series at phpforbeginners.com.
    Watch thousands of videos, track your progress, and participate in a massive Laravel community at Laracasts.com.
    Laracasts: laracasts.com
    Laracasts Twitter: / laracasts
    Jeffrey Way Twitter: / jeffrey_way

Комментарии • 68

  • @khalidelgazzar
    @khalidelgazzar Год назад +22

    Jeffrey way has a very unique "way" in delivering the most complex information in the simplest & fastest way. I've been following his tutorials since around 2009 when he was still at that Aussie company

    • @awaisweis6605
      @awaisweis6605 15 дней назад

      what you mean in 2009 ? I think he's from the pharaoh times :D

    • @khalidelgazzar
      @khalidelgazzar 15 дней назад

      @@awaisweis6605 look how he.looked like 15 years ago.. that was in 2008 or 2009 I think .. ruclips.net/video/yTHTo28hwTQ/видео.htmlsi=9ruaO-0cxz96-wdn

  • @Steve-Ariss
    @Steve-Ariss 3 месяца назад +1

    Blast from the past - I forgot how excellent Jeffrey is at teaching. This guy taught me how to use jQuery back in the day!

  • @braintricker_soft
    @braintricker_soft Год назад +2

    finally, i understand container after 6 years of working on laravel

  • @prestonkhumbula1219
    @prestonkhumbula1219 Год назад +3

    Hi Jeffrey, I hope you will see this. First I would like to express my heartfelt gratitude for the priceless contribution you have made to my programming career. I used the PHP for beginners series and I got a distinction in the exams. I once tried Laravel last year on some other channel tutorial but it quickly confused me and I quit. Today, I have completed the Laravel 5.4 series and I am moving to the next Laravel series. Words will never be enough to thank you. You have made more impact than you can even imagine..All the love from Africa, Zimbabwe to be specific.

  • @DukeBerserkerTheFury
    @DukeBerserkerTheFury 6 месяцев назад +1

    One of the fiddliest issues of php programming explained in the easiest way. Please don't ever stop teaching and record more courses

  • @OGAndrew94
    @OGAndrew94 Год назад

    These thumbnails match my first time getting into PHP and then hating life later on when I needed to refactor everything.

  • @user-rt4yq1db1s
    @user-rt4yq1db1s 10 месяцев назад

    You give amazing teacher vibes my man, everyone would be lucky to have you as a teacher!

  • @davebudah
    @davebudah Год назад +5

    Loving the series, I personally want to learn this kind of info than just to "enjoy" using frameworks without any knowledge of whats under the "hood". I think I will build one of my personal websites based on this knowledge. Thank you very much.

  • @GlobalAsW
    @GlobalAsW Год назад +4

    Thank you so much for this great lesson

  • @AugustoTitan
    @AugustoTitan Год назад

    This is by far the best explanation for service containers I have watched. Congrats on the video and the whole series.

  • @user-vw6rt8re8x
    @user-vw6rt8re8x Год назад

    It's incredibly easy and simple! now, I can understand app container! Thanks Jeffrey!

  • @taslimsuman
    @taslimsuman 9 месяцев назад

    I really love the way you teach. Breaking the complex things into a small pieces of cake. Really enjoying.

  • @ashikmehermobin9926
    @ashikmehermobin9926 Год назад +1

    Thank you Jeffrey. You are more than documentation. God bless you

  • @eine91
    @eine91 Год назад +1

    I always wanted to be like Jeffrey way 😀. The best explainer I have ever watched.

  • @swancompany_inc
    @swancompany_inc Год назад +1

    Hey Jefferey. This is a phenomenal series. I’ve been coding since Jan 2020 and using Laravel since Jan 2021 and have just been rolling with and trusting the frame work. Now thanks to you I’m really starting to get it lol. Awesome man!!!!

  • @awadonacien3063
    @awadonacien3063 Год назад

    Best php series on earth

  • @omaryahia
    @omaryahia Год назад

    you are really amazing in delivering knowledge , THANK YOU 😊
    I am happy I have found your channel

  • @shahosanandaji9894
    @shahosanandaji9894 Год назад

    The best explanation from the one of best tutors!

  • @TristanBailey
    @TristanBailey 11 месяцев назад

    Great explainer for something I understand but have never needed to build. Feel better for knowing

  • @basilistigris640
    @basilistigris640 10 месяцев назад

    thank you laracast and Jeffrey Way for the professional presantation and deep explain of the best php course online!

  • @deepmondal8564
    @deepmondal8564 Год назад +1

    Jeffrey you are awesome👍

  • @ricko13
    @ricko13 3 месяца назад

    yeah i have to re-watch this 2 or 3 times 😅

  • @ramziddinrustamov5221
    @ramziddinrustamov5221 Год назад

    good job , thanks , at the begining of this playlist , all things great , becouse i know every step of what is going on at backend side of the any feramwork .

  • @QuadraQuack
    @QuadraQuack Год назад

    Keep 'em coming

  • @hasanhatem1658
    @hasanhatem1658 Год назад

    Thank you Jeffrey

  • @mexantos
    @mexantos 10 месяцев назад

    Hi Jeff one more thing, i have followed others tut about intermediate PHP, in here i want to talk about router specifically. in that tut router just simply to say emulate get request and response to users if available and 404 if not. i was kind lost here about the concept in that tuts just matching request with controller if yes show the page associate with client req and 404 otherwise. one more thing. controller also have some method that match with SUBMIT_QUERY, while the class controller itself match with REQUEST_METHOD

  • @detonationcruster
    @detonationcruster Год назад +2

    So looks like I was on the right path, but derailed along the way. Recently I made an Application class that instantiated a bunch of other classes inside of it - so in my pages I could access things like $App->Database->query() or $App->Router->loadController() .... etc..... I like the idea of having things accessible from a single "resource", and I'm glad that this is actually a "thing"... I just did it wrong. Thanks for the video... I still have to understand namespaces.

    • @travholt
      @travholt Год назад +1

      Yeah, and one of the nice things about the service container is that you only instantiate what you need when you need it, instead of everything upfront, which saves a bunch of CPU, memory and time.

    • @detonationcruster
      @detonationcruster Год назад

      @@travholt I see... well good thing I'm trying to correct my bad programming mistakes now. :)

  • @m.shahrim1933
    @m.shahrim1933 Год назад

    I'm lost halfway through the video. Gonna need to rewatch it.

  • @mustimusti2003
    @mustimusti2003 Год назад

    at 11:30 you should also let people know that when you have something like a static property it can fill up in memory if you keep on pushing stuff to it, this could cause a memory leak if you use something such as Laravel Octane

  • @alikaram98
    @alikaram98 7 месяцев назад

    so good

  • @mahmoudjoumaa6692
    @mahmoudjoumaa6692 Год назад

    why did we use App class to initialize the container? why not just initialize it as a singleton inside itself?
    Thank you for the gold info

  • @felakos1568
    @felakos1568 7 месяцев назад

    Dear Jeffrey, help me understand the meaning of the App singleton if all its functionality can be left in the container and called static methods from there?
    Maybe it's just sugar or has a specific practical meaning?

  • @emanuelferreyra1881
    @emanuelferreyra1881 Год назад

    Please make a tutorial on how to test with phpunit using database! thanks a lot

  • @dmxd
    @dmxd Год назад

    What phpstorm theme and color scheme is used in this video?

  • @syedjackson6931
    @syedjackson6931 Год назад

    gotcha

  • @ChamaraAbeysekara
    @ChamaraAbeysekara Год назад

    Please go into DI using the service container. May a separate video

    • @wadecodez
      @wadecodez Год назад +1

      DI is a pretty loose term. Typically it means just passing in values to a constructor. So technically in this video Jeffrey was using DI to provide config values to the Database class.
      Laravel takes DI a step further with autowiring which is made possible because of PHP's reflection API.
      Basically autowiring works like this. High level methods (controllers, actions, jobs) are invoked by Higher-order Functions (HOF) aka decorators. The HOF inspects the target method's signature using reflection to get a list of wanted parameters. The parameters are resolved using a service container (like what Jeffrey wrote). Then the target method is invoked with a list of resolved variables.
      But like he said, you wouldn't really want to implement all this yourself. You'd have to add a whole bunch of code to counteract the performance loss from reflection. My guess is you'd probably need some short circuiting and a caching layer.
      None of that is super important though because you can reuse the HOF that I'm talking about in Laravel. Just use `App::call` to invoke a callable and autowiring will "just work". And, if you're not using Laravel, you can use Symfony's service container, or the PHP-DI library.

  • @stefanosgiannakis7151
    @stefanosgiannakis7151 Год назад

    👍

  • @hugo-abdou
    @hugo-abdou Год назад

    where are you man wee miss you 10 days no videos

  • @mexantos
    @mexantos 10 месяцев назад

    Is this concept same as Dependancy Injection?

  • @borakayalar
    @borakayalar Год назад

    Many thanks for this, but I could not understand a point. destroy.php has $db object and it is creating with only App::revolve(Database::class). There is no any __constructors for container and app objects. so how can the app object create the container object ? maybe if I see sources i can make code review. While I watching I could not catch all process. will you put that small project on github?

    • @lucabaxter4002
      @lucabaxter4002 Год назад

      Cause the App class contains static methods and the $container is a static property. static it means that you can use methods and properties directly without instantiating the class (you don't need a constructor). Usually static classes are often called utility classes referring to the fact that are used everywhere in your code.

    • @Plytys
      @Plytys Год назад

      At 11:18 Jeffrey starts building App class and he uses "static" property and method. This "static" is what enables you to access them without needing a __constructor. It was covered in previous episodes (cannot remember which one), but try re-watching that part as Jeffrey does explain it again.

    • @borakayalar
      @borakayalar Год назад

      You are right. all methods are static. I could not covered calling sequence while watching :). My problem is bindings. There is no binging and I think resolvers are calling bindings.

    • @lucabaxter4002
      @lucabaxter4002 Год назад +1

      Bind is just a term, think about it like this, you have a box which contains key : value pairs where each bind is a "key" with a function as a "value". Whenever you want to add a pair to the box, you call the bind method, and whenever you want to use one of the function in the bindings, you call the "resolve" method. Is up to you what the resolve method does.

    • @Laracastsofficial
      @Laracastsofficial  Год назад +1

      Hi, Bora. I upload the source code for every lesson to Laracasts. Just find the corresponding episode at phpforbeginners.com, and then scroll below the video for the Source Code link.

  • @Glfighter1
    @Glfighter1 Год назад

    pog

  • @hilalahmad4736
    @hilalahmad4736 Год назад

    Except 35 video (Service Container) i learnt a lot but i didn't understand service container properly 😔

  • @BlazPecnikCreations
    @BlazPecnikCreations Год назад +1

    I'm not trying to hate, the video overall was very well presented and enjoyable but ... what problem does this exactly solve?
    To me this seem like a global get_database function with extra steps + a possible missing-bind Exception?

    • @Laracastsofficial
      @Laracastsofficial  Год назад

      The database resolver is just *one* piece that would go in the container. In real life, countless things would.
      It's a very common pattern that countless applications use.

    • @BlazPecnikCreations
      @BlazPecnikCreations Год назад +1

      @@Laracastsofficial I still don't know what problem that solves?
      Why not just have a services.php file with get_service_a, get_service_b, get_service_c etc ... ?

    • @Laracastsofficial
      @Laracastsofficial  Год назад +3

      You can if you want. Either way, you're wrapping the instantiation of an object within a function. How you trigger that function is up to you. But dozens of get_service_a(), get_service_b() functions doesn't sound very nice to me.
      Also, like I mentioned at the end of the video, keep in mind that an off the shelf container supports so many other things, including singletons, automatic dependency tree resolution, interface binding, etc.

    • @DanielGithinji1
      @DanielGithinji1 Год назад +1

      Additionally having a service container will ensure that all your services get to be instantiated once and have a single storage in memory which you can reference with each call to the specifc service. Having dozens of get_service_a(), get_service_b() functions means that you'll be calling the functions and returning new values each time they are defined in code which will eat up more memory. This may become a performance hit if you have a large application. The service container in this tutorial follows the singleton design pattern which is great for performance and code organization.

    • @BlazPecnikCreations
      @BlazPecnikCreations Год назад

      @@DanielGithinji1 Ahhhhh, yeah that makes sense, thnx

  • @FelipeFontana
    @FelipeFontana Год назад

    Send this wall paper to us (L)

  • @DaviMartins99
    @DaviMartins99 Год назад +1

    Day one of begging Jeffrey to share his PHPStorm theme/color scheme 🤌

  • @phojie6868
    @phojie6868 16 дней назад

    typesafety 😔

  • @masoud_or_whatever
    @masoud_or_whatever Год назад

    Are you god? 🥲 thanks god