FOSUserBundle
…stored in the database. Let’s create
a new bundle called UserBundle to house the new entity. Instead of using
the doctrine:generate:bundle task, I’ll just create a UserBundle
and make sure there’s a properly-named bundle class inside. Don’t forget…
Content Browser
…when we try the page, we're greeted with an error!
Netgen Content Browser backend for doctrine_recipe value type does not exist.
Yep! We need to implement a class that helps Layouts browse our recipes. That's
called a "content browser".
Adding a content…
Item View Template
…match one piece of config, like
this template, with some other piece of config, like the doctrine_recipe value
type. There are a finite number of these matchers, and we're going to see the most
important ones along the way. So don't worry…
Value Converter
…s an instanceof Recipe:
Second, for getValueType(), return the internal key of our value type:
doctrine_recipe:
Next is getId()... and we're literally going to return our ID with
$object->getId():
We don't have autocomplete on this, but we know this object will…
Adding Lists: Value Type
…The same is true if you're using Ibexa CMS.
So here's our next big goal: to add our Recipe Doctrine entity as a "value
type" in layouts so that we can create lists and grids containing recipes.
Step one to adding a value…
Enhanced Docker Integration & Testing Emails
…Finally, just like normal, thanks to our
config/packages/doctrine.yaml configuration, the DATABASE_URL environment variable
is used to talk to the database. So the Symfony binary plus Docker is a nice way
to quickly and easily boot up external services like a database…
Recipe Upgrades with recipes:update
…the recipe relate to the config files, and I bet you can see
what's happening. It deleted two environment-specific config files and updated
the main one. Hmm.
Open config/packages/doctrine.yaml. Sure enough, at the bottom, we see when@test
and when…
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…
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…
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…
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…
Update Query & Rich vs Anemic Models
…whenever we need to save something in Doctrine, we need the
entity manager.
Add another argument: EntityManagerInterface $entityManager.
Then, below, replace the dd($question) with $entityManager->flush().
Done! Seriously! Doctrine is smart enough to realize that the Question object
already exists in the database and…
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…
Migrate Password Hashing
…Got it!
It's also kinda fun to see how this looks in the database. Find your terminal
and run:
php bin/console doctrine:query:sql 'SELECT email, password FROM user'
Interesting: every hashed password starts with the same $2y thing. That's no
accident…
Validation Auto-Mapping
…How the
heck did that work? The system - validation auto-mapping - automatically adds
sensible validation constraints based off of your Doctrine metadata. The
Doctrine Column annotation has a nullable option and its default value is
nullable=false:
In other words, the title column is required in…
Spotting Heavy Object Instantiation
…to instantiate Doctrine's EntityManager object.
I know, we don't often think about how much time or how much memory it takes to
instantiate an object, but it can sometimes be a problem. The next function
call is for the instantiation of Doctrine's…
Comparisons: Validate Performance Changes, Find Side Effects
…ll
see this later - not every change we'll do in this tutorial will prove to be
a good one.
Next: Blackfire has a deep understanding of PHP, database queries, Redis calls
and even libraries like Symfony, Doctrine, Magento, Composer, eZ platform,
Wordpress and others…
Finding Issues via the Call Graph
…That's the last function before it
jumps into Doctrine.
So the problem in our code is something around this getUserActivityText() stuff.
Let's open up this template: main/sighting_show.html.twig - at
templates/main/sighting_show.html.twig.
If you look at the…
Recommendations
…on your radar.
There's also a recommendation that Doctrine annotation metadata should be cached
in production. Honestly... I'm not sure why that's there - Symfony apps come with
a config/packages/prod/doctrine.yaml file that takes care of caching these
when you…
x
1000+