Goodbye SensioFrameworkExtraBundle
…the route does have a {slug}
wildcard... but then a $mix argument, which is a Doctrine entity.
Behind the scenes, the param converter would automatically query for a
VinylMix where slug equals the {slug} in the URL. No annotation needed:
it just worked.
The good…
Flex Recipe Updates
…you
know, doing our real job. I'll hit enter to go down the list one-by-one.
First up is Doctrine Bundle: and it's a complex update. It even
caused a conflict!
Sometimes we might see that a recipe update changes something - like…
Leveraging the Core Processor
…on? We map the UserApi to a new User object and save the new
User... which causes Doctrine to assign the new id to that entity object. But
we never take that new id and put it back onto our UserApi.
To fix this, after…
Pagination on a Custom Resource
…Second, to return the count of the
total number of items. When you use Doctrine, it executes 2 separate queries
for this: one to fetch the current page's results with a LIMIT and OFFSET, and a
second COUNT query to count every row.
Ok…
Filtering Relation Collection
…internally, Doctrine will first query for all
100... even though we'll only return 10. If you have large collections,
this can be a performance problem. In our Doctrine tutorial, we talk about fixing
this with something called the Criteria system.
But with both approaches…
Builder in Symfony & with a Factory
…character builder needed a service like the EntityManager?
With our new setup, we can make that happen. I don't actually have Doctrine installed
in this project, so instead of the EntityManager, let's require
LoggerInterface $logger... and I'll again add private in front…
Dynamic Roles
…paste, use abraca_user@example.com... and leave roles empty:
Let's do it! At your terminal, run:
symfony console doctrine:fixtures:load
When that finishes... spin over and refresh. We got logged out! That's because, when
the user was loaded from the session…
Testing with the "in-memory" Transport
…we could query the messenger_messages table, but that's
a bit hacky - and only works if you're using the Doctrine transport. Fortunately,
there's a more interesting option.
Start by copying config/packages/dev/messenger.yaml and pasting that into
config/packages/test…
Installing Messenger
…validates it, uses another service
to store that file - that's the uploadImage() method, creates a new ImagePost
entity, saves it to the database with Doctrine and then, down here, we have
some code to add Ponka to our photo. That ponkafy() method does the…
How to handle dynamic Subdomains in Symfony
…differences here are a bit subtle. For example, the baseHost is now
stored in a property and we can get Doctrine’s repository through the $em
property. We’ve also replaced the createNotFoundException call by instantiating
a new NotFoundHttpException instance. The createNotFoundException
method lives in…
Warmup Command Configuration
…the parent class if we detect that it's a proxy.
After creating the ReflectionClass, write if ($class->implementsInterface(Proxy::class)).
Import the class from Doctrine\Persistence:
All generated proxies have this interface.
Inside, write $class = $class->getParentClass() to get the true entity class:
…
Auto Setting the "owner"
…for this: the state processor system.
As a reminder, our POST and PATCH endpoints for DragonTreasure already have a state
processor that comes from Doctrine: it's responsible for saving the object to
the database. Our goal will feel familiar at this point: to decorate…
Totally Custom Fields
…is loaded. For
example, our classes are already using a Doctrine state provider behind the
scenes to query the database. We'll cover state providers in part 3 of this series.
The second solution would be to use the custom normalizer like we did, then…
AssociationField for a "Many" Collection
…Question:
That method properly removes the Answer from Question. But more importantly,
it sets $answer->setQuestion() to null, which is the owning side of this
relationship... for you Doctrine geeks out there.
Ok, try removing "95" again and saving. Hey! We upgraded to an error…
Hashing Plain Passwords & PasswordCredentials
…try this. Find your terminal and run:
symfony console doctrine:fixtures:load
This will take a bit longer than before because hashing passwords is actually CPU
intensive. But... it works! Check the user table:
symfony console doctrine:query:sql 'SELECT * FROM user'
And... got it…
Customizing the User Class
…roles and first_name columns.
Close this... and run it:
symfony console doctrine:migrations:migrate
Success!
And because the User entity is... just a normal Doctrine entity, we can also
add dummy users to our database using the fixtures system.
Open up src/DataFixtures/AppFixtures…
Giving Users Passwords
…sure everything looks good:
And... it does! Close it... and run it:
symfony console doctrine:migrations:migrate
Perfect! Now that our users have a new password column in the database, let's
populate that in our fixtures. Open up src/Factory/UserFactory.php and
find…
make:user
…like
HumanoidEntity. If the "thing" that logs into your site would be better called
a Company or University or Machine, use that name here.
Do you want to store user data in the database via Doctrine?
For us: that's a definite yes... but it…
Transport: Do Work Later (Async)
…supermarket. Out-of-the box, Messenger supports three: amqp -
which basically means RabbitMQ, but technically means any system that implements
the "AMQP" spec - doctrine and redis. AMQP is the most powerful... but unless
you're already a queueing pro and want to do something crazy…
Interrupt Symfony with an Event Subscriber
…a lot more interesting.
You can already see where our controller is called, and under the controller
you can see the Twig template and even some Doctrine calls being made.
Before and after that, there are a lot of event listeners - you notice a
lot…
x
1000+