1000 search results

Partial Mocking

…going on? This is subtle: PhpUnit is smart enough to take this one dinosaur object and return it each time growFromSpecification() is called. But to Doctrine, it looks like we're asking it to save the same one Dinosaur object: not three separate dinosaurs. The…

3:59
Tests, Assertions & Coding

…tutorial/ directory with a Dinosaur class inside. Copy that and paste it into the real Entity directory. This is just a simple class with a length property. It does have Doctrine annotations, but that's not important! Sure, we will eventually be able to save…

6:40
My Users don't have a Username!

… No more username! Register as aquanaut4@gmail.com and submit. Check it out in the database: php bin/console doctrine:query:sql 'SELECT * FROM user' There it is! The username is now equal to the email. Oh, and if you're using the profile edit…

2:22
Customizing the Forms

…production anyways, but, you've been warned! Move over to your terminal to generate the migration: php bin/console doctrine:migrations:diff That looks right! Run it: php bin/console doctrine:migrations:migrate New field added! Now, how can we add it to the form?…

6:27
CollectionType Field

…about the owning and the inverse sides of the relationship, and things called orphanRemoval and cascading. There is some significant Doctrine magic going on behind the scenes to get it working. So in a few minutes, we're going to look at a more custom…

5:51
DQL Filtering & Sorting

…a lot of species. Start by adding a list key and a new, awe-inspiring option: dql_filter. For the value, pretend that you're building a query in Doctrine. So, entity.speciedCount >= 50000: The alias will always be entity. Try it! Ten down…

5:19
Void Types & Refactoring an Entire Class

…return type to the class you know you're returning... or use the more flexible interface. But actually, for Doctrine collections, you must use Collection. Depending on the situation, this property might be an ArrayCollection or a PersistentCollection... both of which implement the Collection interface…

7:06
Webhooks: Preventing Replay Attacks

…the AppBundle/Entity directory, create a new PHP Class called StripeEventLog: Give it a few properties: $id, $stripeEventId and a $handledAt date field: Since this project uses Doctrine, I'll add a special use statement on top and then add some annotations, so that this…

5:41
Testing Part 2: Faking the Event Lookup

…that true is false on line 43 It looks like our webhook is not working, because the subscription is still active. But actually, that's not true: Doctrine is tricking us! In reality, the database has been updated to show that the Subscription is canceled…

5:06
Webhook: Subscription Canceled

…be canceled. Below, really simple, say $subscription->cancel(). Then, use the Doctrine entity manager to save this to the database: Mind blown! Back in the controller, call this! Above the switch statement, add a $subscriptionHelper variable set to $this->get('subscription_helper'): Finally, call $subscriptionHelper…

5:08
Tracking Cancelations in our Database

…month: Cool! To deactivate the subscription in the controller, it's as easy as saying $subscription->deactivateSubscription() and then saving it to the database with the standard persist() and flush() Doctrine code: And that should do it! Let's give this guy a try. Go…

7:57
We <3 Creating Stripe Customers

…our user record, say $user->setStripeCustomerId($customer->id): Then, I'll use Doctrine to run the UPDATE query to the database: If you're not using Doctrine, just make sure to update the user record in the database however you want. Now, add the else…

4:37
Stripe Customers + Our Users

…getters and setters for the new property: Now that our PHP code is updated, we need to actually add the new column to our table. Since this project uses Doctrine migrations, open a new tab and run: All that did was create a new file…

2:55
Adding a Cache Service

…it entirely on our own. First, we need to configure the bundle. To see what keys it has, find the terminal and run: The list has a new entry: doctrine_cache. Re-run the command with this: Nice! There's our huge configuration example! Ok…

3:27
Users Need Passwords (plainPassword)

…plain-text password on the User and encode it automatically via a Doctrine listener when it saves. To do that, add a new property on User called plainPassword. But wait! Don't persist this with Doctrine: we will of course never store plain-text passwords:…

3:32
The UserInterface Methods (Keep some Blank!)

…feel ok leaving these blank. So in our application, we want to store users in the database. So let's set this class up with Doctrine. Copy the use statement from SubFamily and paste it here: Next, I'll put my cursor inside the class…

4:19
The All-Important User Class

…somewhere else - like a central authentication server. In those cases, you will still have a User class, you just won't store it with Doctrine. More on that as we go along. Ok, we've got the empty user class: let's fill it in!

4:22
Custom Query in EntityType

…So, if you pass a query_builder option and set it to an anonymous function, Doctrine will pass that the entity repository for this specific entity. All we need to do is create whatever query builder we want and return it. In the form, add…

3:30
Binding Forms to Objects: data_class

…Look at this! A free drop-down with almost no work. It also noticed that isPublished should be a checkbox because that's a boolean field in Doctrine: And since firstDiscoveredAt is a date, it rendered it with year-month-day drop-down boxes. Now…

4:44
Process that Form!

…to use that associative array to create a new Genus object, populate it with the data, and save it via Doctrine. But, it would be awesomesauce if the form framework could do our job for us. I mean, use the data to automatically create the…

2:46