Improving Javascript Event Security
…user.
Head over to your terminal and run:
bin/console doctrine:query:sql "SELECT * FROM user"
We have the lsCustomerId set, so let's reset it to NULL with:
bin/console doctrine:query:sql "UPDATE user SET lsCustomerId=NULL WHERE id=1"
Let's test it out…
Dynamic Data
… Up here, we can add a description:
Add a column to store the LS variant ID on Product.
Back in our terminal, run the migration with:
bin/console doctrine:migrations:migrate
Now, in src/DataFixtures/AppFixtures.php, set our new field to the variant ID…
Adding new Properties
…anything in my
database? The answer is no. I can prove it by running a helpful command:
symfony console doctrine:schema:update --dump-sql
This is very similar to the make:migration command... but instead of generating
a file with the SQL, it just prints…
The Query Builder
…have... so you might accidentally remove something
you added earlier. So, always use andWhere(). Doctrine is smart enough to figure
out that, because this is the first WHERE, it doesn't actually need to add the
AND.
Inside of andWhere(), pass mix.genre =... but…
Verify Email after Registration
…migration:
symfony console make:migration
Go check that out and... awesome. It looks exactly like we expect:
Run it!
symfony console doctrine:migrations:migrate
Beautiful! Let's do one more thing related to the database. Inside of
src/Factory/UserFactory.php, to make life simpler…
Foundry Tricks
…Faker again! self::faker()->numberBetween(1, 4) and then true
to return this as a string.
Let's take this for a test drive! Find your terminal and reload the fixtures with:
symfony console doctrine:fixtures:load
Go check the homepage and... yea!
Oh, but…
How does the Controller Access the Container?
…And
AbstractController implements a special interface called
ServiceSubscriberInterface. This is actually something we talk about in
one of our
Doctrine tutorials.
When you implement ServiceSubscriberInterface, it forces you to have a method
called getSubscribedServices() where you return an array that says which
services you need…
Events, Events & Events!
…see the Twig templates being executed below it, and even little Doctrine
queries happening along the way.
The biggest thing I want you to notice is that most of the other lines - both
before and after the controller - contain the word Listener, or sometimes
Subscriber…
Mapping Messages to Classes in a Transport Serializer
…I did! I mean, handling messages asynchronously...
that's pretty fun stuff. The great thing about Messenger is that it works brilliantly
out of the box with a single message bus and the Doctrine transport. Or, you
can go crazy: create multiple transports, send things…
Setup for Uploading Private Article References
…yep!
CREATE TABLE article_reference
... with a foreign key back to article. Run that with:
php bin/console doctrine:migrations:migrate
Before we get back to work, open the Article entity. The command did create
the $articleReferences property that allows us to say
$article->getArticleReferences()…
Tagging Scenarios in order to Load Fixtures
…with no var_dump(). Perfect!
One way to execute the fixture is by running the doctrine:fixtures:load command.
I use a different method that gives me more control. Add $loader = new ContainerAwareLoader()
and pass it the container:
Now, point to the exact fixtures…
When *I* do Something: Handling the Current User
…object which will be the author for those products:
Now, add an if statement that says, if $author is passed then, $product->setAuthor():
I already have that relationship setup with in Doctrine. Great!
In thereAreProducts(), change the body of this function to $this->createProducts($count)…
The SymfonyExtension & Clearing Data Between Scenarios
…use hooks.
Create a new public function clearData():
Clearing data now is pretty easy, since we have access to the entity manager via
self::container->get('doctrine')->getManager();:
Now we can issue DELETE queries on the two entities that we care about so far:
product…
Controlling the Database
…so we can say $user = new User().
Then set the username and the "plainPassword":
I have a Doctrine listener already setup that will encode the password automatically.
Which is good: it's well-known that raptors can smell un-encoded passwords...
In this app…
Symfony: Keep it Simple with @Route and Templates
…
So let’s finish this page. It should be fairly straightforward: we’re going
to use Doctrine to query for all the posts and then pass them into a template:
/**
@Route("/posts")
/
public function indexAction()
{
}
Now, notice that my template name does not have any…
Writing an Integrational Test for Webhooks
…an error, but that's expected.
No such table in the test environment.
Our test is failing because we need to set up a test database. We
could do this manually using Doctrine console commands, but let's take
advantage of Zenstruck Foundry, which we…
Implementing the Webhook Consumer
…method, fetch the user with
$user = $this->entityManager->getRepository(User::class)->find($userId).
Next, if $user doesn't exist, we'll throw new EntityNotFoundException()
(choose the one from Doctrine\ORM). For the message write
sprintf('User "%s" not found for LemonSqueezy webhook "%s"!', $userId…
Foundry: Fixtures You'll Love
…But first... let's run blindly forward and use this class! In AppFixtures,
delete everything and replace it with VinylMixFactory::createOne().
That's it! Spin over and reload the fixtures with:
symfony console doctrine:fixtures:load
And... it fails! Boo
Expected argument type "DateTime", "null"…
Updating an Entity
…When you call flush(), Doctrine loops over all of the entity
objects that it "knows about" and "saves" them. And that "save" is smart. If Doctrine
determines that an entity has not been saved yet, it will execute an INSERT query.
But if it's…
Smarter Entity Methods
…Symfony binary can inject the environment variables. When this finishes,
I like to double check the migration to make sure it doesn't contain any surprises.
This looks perfect. Execute it with:
symfony console doctrine:migrations:migrate
Beautiful!
But... this did break one little thing…
x
1000+