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…
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…
Custom Repository Class
…here.
We'll see this idea of custom entity methods later.
At the bottom, there's one more link: question.slug.
Done! Doctrine makes it easy to query for data and Twig makes it easy to render.
Go team! At the browser, refresh and... cool…
"5 Minutes Ago" Strings
…That's not going to work!".
And... you're right:
Object of class DateTime could not be converted to string
We know that when we have a datetime type in Doctrine, it's stored in PHP
as a DateTime object. That's nice because DateTime…
Fetching Data & The Repository
… Refresh and... woohoo! This gives us a Question
object. Doctrine finds the matching row of data and uses that to populate an
object, which is beautiful.
The repository has a number of other methods on it. For example, findOneBy()
returns a single object and findBy…
docker-compose Env Vars & Symfony
…For example, because this service is called database - we technically could have
called it anything - the Symfony binary is already exposing an environment variable
called DATABASE_URL: the exact environment variable that Doctrine is looking
for.
I'll show you exactly what I mean. First…
Profiling Command Line scripts
…flush() to, sort of,
"clear" Doctrine's memory of the BigFootSighting object you just finished...
so that it doesn't check it for changes when we call flush() during the next time
through the loop:
The point is: like with everything, make your code do…
Sending Handlers to Different Transports: from_transport
…for the options you can pass here... though you can always
check MessageSubscriberInterface: it talks about what's available.
Next, let's up our queueing game by changing from the Doctrine transport to
RabbitMQ - also commonly referred to as AMQP. It's buckets of fun!
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…
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…
Handling Messages Sync while Developing
…And... yea! Because we're currently in the dev environment, both transports
have a dsn set to sync://.
I do want to mention that the queue_name option is something that's specific
to Doctrine. The sync transport doesn't use that, and so, it…
High Priority Transports
…which in our
case is using doctrine. Below, add options, then queue_name set to high.
The name high isn't important - we could use anything. The queue_name option
is specific to the Doctrine transport and ultimately controls the value of a column
in…
Dummies
…object - an object that does work, but doesn't hold much data, like
DinosaurFactory, Doctrine's EntityManager or a class that sends emails, mock
it. That's because these are usually difficult to instantiate and often have side
effects, like talking to the database or…
Let: The Setup Function
…If you're a Doctrine user, this will look familiar. But, no, I'm not recommending
that you actually create or move the EntityManagerInterface into your app like
this. We're adding this interface as a convenient way to "pretend" like Doctrine
exists in our…
Buzzwords! Specification & Examples
…bin/phpspec describe App/Entity/Dinosaur
I could have chosen any namespace starting with App - that's up to how you want
to organize your code. But, if you're used to Doctrine in Symfony, this will feel
familiar.
Ok! One new file: DinosaurSpec.php…
Symfony Console Commands
…we only want
to run if this is a development machine, because it resets the database.
We'll talk about controlling that later.
For this command, use hautelook_alice:doctrine:fixtures:load --no-interaction:
Ok! The 3 commands are ready! Head back to the terminal…
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…
x
1000+