Popover!
…and paste:
Next, create an endpoint for this. In src/Controller/PlanetController.php, anywhere,
I'll paste in a route and controller:
Nothing special: it queries for the Planet and passes it to the template. In
that template, adjust the variables. Instead of voyage.planet…
API Token Scopes
…form, they
can still use this operation, even though they won't have that exact role. That
is where ROLE_FULL_USER comes in handy.
Open config/packages/security.yaml and, anywhere, add role_hierarchy... I
recommend spelling it correctly. Say ROLE_FULL_USER. So…
Testing a Service
…like controllers, repositories & services, nobody
is using the LockDownHelper service. We're not autowiring it into a controller
or a service anywhere. And so, Symfony removes this from the container... which
means that it's not there in the test.
The fix for this is…
The Request Object
…Request object. And there are two ways to get it.
The first is by autowiring a service called RequestStack. Then you can get the
current request by saying $requestStack->getCurrentRequest().
This works anywhere that you can autowire a service. But in a controller, there's…
Pub Sub Event Class & Subscribers in Symfony
…EventSubscriberInterface and... done!
Symfony will automatically register it. To dispatch an event, create a new event
class and dispatch that event anywhere in your code.
If we try this again (I'll exit the battle first)... it only outputs once. Great!
And... what are the…
Reliably Load External JS with Stimulus
…At this point, we can add this anchor tag anywhere on our site,
and it will instantly do the work to initialize itself.
Next: let's investigate the second-use case for Turbo Frames... and really the
main use case: the ability to keep navigation…
Services
…is this: everything
is done by a service. If you learn to master services, you can do anything from
anywhere in Symfony.
There's a lot more to say about the topic of services, and so many other parts
of Symfony: configuration, Doctrine & the database…
Twig ❤️
…the block
some default content, like with title:
Yep, the browser tab's title is Welcome.
Let's override that! At the top... or really, anywhere, add {% block title %}.
Then say Read , print the title variable, and {% endblock %}:
Try that! Yes! The page title changes…
Requiring Authentication
…were with us
for episode 1, we did some pretty advanced error handling stuff at the bottom
of this Application class. What we basically did was add a function that’s
called anytime there’s an exception thrown anywhere. Then, we transform
that into a…
Behat for Testing
…To see it, run
the same command with a -dl option:
$ php vendor/bin/behat -dl
Anywhere you see the quote-parentheses mess that’s a wildcard
that matches anything. So as long as we write scenarios using this language,
we can test without…
All About services.yaml
…service ID. This is done for simplicity... but also for
autowiring. When we try to autowire MixRepository into our controller or anywhere
else, to figure out which service to pass us, Symfony will look for a service
whose ID exactly matches App\Service\MixRepository. So…
Persisting to the Database
…with
DateTime objects. Let's say new \DateTime() and add some randomness here too:
sprintf('-%d days') and pass a random number from 1 to 100.
So, the askedAt will be anywhere from 1 to 100 days ago.
Ok! Our Question object is done! Add…
Vue Instance & Dynamic Data
…does exactly what Vue normally does. If you look at this, you might start to wonder:
why do we need a template option at all? We're just reading it in render()...
so it could live anywhere. Let's try that! Remove the option, and…
Secrets Management Setup
…you have an environment variable that you want to convert to
a secret, you need to fully remove it as an environment variable: do not set
it as an environment variable anywhere anymore. I'll remove MAILER_DSN from
.env and if we were overriding…
Private Variables & WeakMap
…it's not attaching any listeners
or adding itself as a reference to anything in the code. In other words, this object
is not attached or referenced anywhere in memory. Because of that, RepLogApp
objects - and their Helper objects - should be eligible for garbage collection…
Map and WeakMap
…southernUSStates to null:
When you try it now, this of course prints "undefined". That makes sense: we're now
passing null to the get() function.
But what you can't see is that the southernUSStates object no longer exists...
anywhere in memory!
Why? In JavaScript…
Immediately Invoked Function Expression!
…that function is its home.
Before, when we weren't inside of any function, our two variables effectively
became global: we could access them from anywhere. But now that we're inside of
a function, the RepLogApp and Helper variables are only accessible from inside…
Filtering to Return only Approved Answers
…So... let's
do that!
In the Question class... anywhere, but right after getAnswers() makes sense,
create a new function called getApprovedAnswers(). This will return a Collection,
just like getAnswers(): Collection is the common interface that ArrayCollection
and PersistentCollection both implement.
Inside, we're going…
Input DTO Validation
…at the bottom, after executing validation, it gets back
these "violations" and throws a ValidationException. This is a special exception
that you can throw from anywhere to trigger the nice validation error response.
So... let's go see it! At the browser, hit Execute and…
Custom Filter, getDescription() & properties
… We already know how! Back in CheeseListing, we've done this
before with other filters. Anywhere in here, add @ApiFilter() with
CheeseSearchFilter::class:
Unfortunately, PhpStorm doesn't auto-complete that for me... so I'll copy the class
name and add it on top manually…
x
517