In this lesson, we'll move code out of the Controller and into a new class. You'll learn how to create this new service class and refactor the code that you took out of the Controller to work in this new context.
In this lesson, you'll learn about the dependency injection workflow and refactor our code to inject the dependency.
In this lesson you'll learn how use type-hinting to make your code more portable—and readable, too.
In this lesson, you'll learn how to register your service in the container so that you can can access it in your class.
In this lesson you'll inject cache service, applying what we've already learned about dependency injection and type-hinting as we refactor the code in our evolving app.
In this lesson, you'll learn how to extend Twig and create a Twig extension service to use in our Symfony 3 app.
In this lesson, we'll add tags to our services YAML file so that Twig knows about our new Twig extension. We'll discuss the reason behind tags and refactor our service with our new understanding of dependency injection tags!
In this lesson you'll learn what happens when you set autowire
to true when you register your service.
In this PHP tutorial, you'll get the project files up and running and learn all about class constants in object-oriented PHP.
If you're serious about getting really good at this stuff, code along with me. To do that, download the source code from this page, unzip it, and move into the start directory. When you do that, you'll have the same code that I have here. Open up the README file and follow the instructions inside to get things setup.
When that's done, open your favorite terminal application, move into the directory, and — like we've done in the previous courses — start the built-in php web server by running:
php -S localhost:8000
This is a great server to use for development. Then, in our browser, we can go to http://localhost:8000. Here is our beautiful Battles app!
Additional resources
Introduction to Object-Oriented PHP (Drupalize.Me)
Object-Oriented PHP Part 2 (Drupalize.Me)
Object-Oriented PHP Part 3 (Drupalize.Me)
In this PHP tutorial, you'll be introduced to static methods, the self
keyword and how they are used.
Additional resources
Object-Oriented PHP (topic) (Drupalize.Me)
In this PHP tutorial, we'll continue learning about static methods and when to use static vs. non-static methods.
In this PHP tutorial, you'll learn about namespaces and the use
statement in PHP.
In this PHP tutorial, learn about what an autoloader is and how you can use it to replace require
statements in your PHP applications.
In this PHP tutorial, learn how the use
statement works with the autoloader to replace the require
statements that we removed in a previous lesson.
In this PHP tutorial we'll continue our look at namespaces and how they work in PHP applications.
In this tutorial, learn about how to set up your app to use Composer Autoloading.
In this PHP tutorial we'll introduce Exceptions in PHP.
In this PHP tutorial, you'll learn about the different exception classes that are available to you use in your PHP applications.
In this tutorial, learn about PHP's built-in magic methods: __toString()
, __get()
, and __set()
.
In this tutorial, learn how to use PHP's built-in interface ArrayAccess
and when you might want to use it.