Chapters
20 Chapters
|
1:53:05
|
Login to bookmark this video
-
Course Code
Login or register to download the code!
Login or register to download the code!
-
This Video
Login or register to download the video!
Login or register to download the video!
-
Subtitles
Login or register to download the subtitles!
Login or register to download the subtitles!
-
Course Script
Login or register to download the script!
Login or register to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
This tutorial works perfectly with both Symfony 7 & 8!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"php-cs-fixer/shim": "^3.46", // v3.46.0
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.25", // 1.25.0
"symfony/asset": "7.0.*", // v7.0.3
"symfony/asset-mapper": "7.0.*", // v7.0.2
"symfony/console": "7.0.*", // v7.0.2
"symfony/dotenv": "7.0.*", // v7.0.2
"symfony/flex": "^2", // v2.4.3
"symfony/framework-bundle": "7.0.*", // v7.0.2
"symfony/monolog-bundle": "^3.0", // v3.10.0
"symfony/property-access": "7.0.*", // v7.0.0
"symfony/property-info": "7.0.*", // v7.0.0
"symfony/runtime": "7.0.*", // v7.0.0
"symfony/serializer": "7.0.*", // v7.0.2
"symfony/stimulus-bundle": "^2.13", // v2.13.3
"symfony/twig-bundle": "7.0.*", // v7.0.0
"symfony/ux-turbo": "^2.13", // v2.13.2
"symfony/yaml": "7.0.*", // v7.0.0
"symfonycasts/tailwind-bundle": "^0.7.1", // v0.7.1
"twig/extra-bundle": "^2.12|^3.0", // v3.8.0
"twig/twig": "^2.12|^3.0" // v3.8.0
},
"require-dev": {
"symfony/debug-bundle": "7.0.*", // v7.0.0
"symfony/maker-bundle": "^1.52", // v1.53.0
"symfony/stopwatch": "7.0.*", // v7.0.0
"symfony/web-profiler-bundle": "7.0.*" // v7.0.2
}
}
21 Comments
Why is $logger used as an object but it's named as LoggerInterface ?I think quite a few other objects are autowired via "Xinterface $xobject" dependence injection.
Hey John,
Yeah, most of core objects you type hint with an interface that the real object extends. Mostly, that's done for flexibility, as you can pass any object that extends that interface (Symfony has many objects which are wrapped with another object). And finally, that's just a good OOP concept when you typhint with interfaces instead of end objects if you have them. For your own objects it's redundant to add interfaces if you don't have benefits from it, but from some third-party services it has more sense as most of them already implement some interfaces, extend some base cases, etc.
But for you, to know how to typehint - you can leverage Symfony's
bin/console debug:autowiringcommand that will show you what exactly type-hint and variable name you need to use to inject a proper service/object.I hope it helps!
Cheers!
Hey @John-S,
Great question!
In practice, I typically always use controller method injection but it really comes down to personal/project/team preference. I find controllers easier to read when all their requirements are injected into the method.
sorry. deleted.(not sure if needed because you mention this in next chapter. pls delete if not needed). Deleted post:
Two different ways of injecting logger service.
1.
class TestController
{
}
2.
class TestController
{
}
I intend to use logger in several methods but not all of them. Should i use constructor injection or inject it in every method ?
Hello,
In api controller, there is no black bar at bottom for debug. Is it possible to enable for this page also? What is actual reason that this bar is seen on MainController pages, but not ApiController pages?
thank you
Hey @Mahmut-A!
Great question! There's no web debug toolbar because this is a json response. The toolbar can only be shown on html responses.
There's still a way you can see the profile for this request though! All requests, regardless of the response type, are saved. After making a request to
/api/starshipsvisit/_profiler. You should see a list of recent requests - you can even search them! Find the one to/api/starshipsand click the token. That will be the full profile forthat request.
Hope that help!
--Kevin
Hi,
I was following the tutorial but when i enter the log section of _profiler I have a deprecation with the message "Please install the "intl" PHP extension for best performance." I wish if someone could help me with a possible solution.
I tried to require symfony/intl but it couldn't fix the error.
Thanks
Hey @Jaime-Garcia
It depends on your local PHP installation and the system you use for development. It asks you to install a
php-intlextension to PHPIf you provide more details on you system and PHP installataion then I can provide you more detail help.
Cheers
Hi, sorry for the time spent on answering, I have windows 11 and php on 8.3.12 (cli) (NTS Visual C++ 2019 x64)
as I see, it's a windows php version, not a WSL one, so you have to find php.ini and enable php-intl module there
How can we change the logger config to log into the datadog log server for example or another external log server?
Hey Ahmad,
Not sure about datadog but for example you can log into Loggly logs server. You can see the required config in the bundle's configuration file: https://github.com/symfony/monolog-bundle/blob/06ddd76fd24dcf325a61e826b5c799e4b929422e/DependencyInjection/Configuration.php#L318-L322
There you can search for other log platforms there like rollbar, etc.
Cheers!
Hello,
I wonder what exactly means autowiring? because, we need to log service. but lets say X service. how can we know, we will search it by ./php/console debug:autowiring X.. Why do we need autowiring to search some services to find?
could you please help me to make it clear?
thank you
Hey Mahmut,
Autowiring helps you to inject services with type-hints, i.e. in your action you can literally write the typehint of the class or interface from the
debug:autowiringcommand output and the system will inject that service into your action, e.g.:That's so simple. As long as a service is listed in the
debug:autowiringoutput - it will be able to typehint this way in your controller actions or__construct()methods of our services.How can you know the service name? That's a good question! Well, first of all, you probably should base on the documentation, either official Symfony docs or bundle's docs in case you're going to use a service from a bundle. Or, you can just "guess" it, like if you need a cache search, just search something like "cache" in the output and see if you have any matches. But mostly, I would recommend you to base on docs in the beginning, unless you get used to already known services and will know exactly what to look for.
I hope it's clearer for you now!
Cheers!
thank you Victor. I will add something:
for example serializer is a service. I am doing. ./bin/console debug:autowiring serialize and there are aliases in output.
I also saw this service id in debug:container. However, I could not find related class information in bundless.php.
for example, below is outpu of autowiring serialize. what is class to be seen in bundles.php? how can ı detect it?
thank you
The following classes & interfaces can be used as type-hints when autowiring:
(only showing classes/interfaces matching serialize)
Symfony\Component\Messenger\Transport\Serialization\SerializerInterface - alias:messenger.transport.native_php_serializer
Symfony\Component\Serializer\Encoder\DecoderInterface - alias:serializer
Symfony\Component\Serializer\Encoder\EncoderInterface - alias:serializer
Hey Mahmut,
Don't forget that extra services may come not only from bundles but only from pure PHP packages called Symfony components. Components are not bundles, they do not contain any configuration. For example that Serializer component's configuration is come from the core FrameworkBundle that is installed but default in our Symfony app, but the actual classes are available only after you install the component with Composer.
But as I already said, if you're not sure - please, better check the docs instead of guessing, that's the easiest and fastest way probably :)
Cheers!
How are you getting the nice icons on your project folders in PHP Storm? I assume it's from a particular theme?
Thanks for the great videos. I'm a long-time fan! Even when I already know most of what you are talking about, I always pick up helpful tips to make things just that much better.
Hey @Ernest-H
These nice icons are from https://plugins.jetbrains.com/plugin/10044-atom-material-icons IIRC
Thanks for the feedback. Cheers and happy coding!
Hi. Thank you so much for you helpful videos. A i added a point. The bundles file have the environment activation for the bundle. For example: dev => true, the bundle will be active only on dev environment.
Hi @Inforob,
Yeah that's a good point. This file was mentioned in the chapter 5 of this course, and as it was said previously in most cases you will not edit it manually, every installed bundle will be registered there with proper env activation param depending on how you installed it and recipes system configuration. Of course on custom bundles you will need to choose how to activate them.
Cheers!
"Houston: no signs of life"
Start the conversation!