511 search results

Our First Test

…tests! Mmmm... where do we put this new test? We can technically put our tests anywhere within our project. But when we installed symfony/test-pack, Flex created a tests/ directory which, no surprise, is the recommended place to put our tests. Remember that, in…

7:16
Transport: Do Work Later (Async)

…ImagePost - from the logic that actually does that work. And... it's a nice coding pattern: it's easy to test and if we need to add Ponka to an image from anywhere else in our system, it will be super pleasant. But this pattern…

7:33
The REST API Tutorial

…easy stuff. Nope, we’ll attack the ugliest areas of an API, like custom methods and where each piece of documentation should live and why. The Project: Resources and Links¶ The project? Introducing Code Battles: a super-serious site where programmers battle against projects. After…

3:07
Embedding Custom DTO's

…as a custom array of embedded data? Check it out. In the src/ApiResource/ directory, though this class could live anywhere, create a new class called DailyQuestTreasure. This will represent the treasure that you could win by completing a DailyQuest. Inside, create a public function _…

4:47
Allow Admin Users to Edit any Treasure

…we can add a shortcut to Foundry. Open UserFactory. We're going to create something called a "state" method. Anywhere inside, add a public function called, how about withRoles() that has an array $roles argument and returns self, which will make this more convenient when…

4:11
Dispatching a Message inside a Handler?

…handled by our command bus: we have a DeleteImagePost command and DeleteImagePostHandler. But inside config/packages/messenger.yaml, we're not routing this class anywhere, which means it's being handled immediately. Oh, and notice: we're still passing the entire entity object into the…

5:30
Assets: Custom CSS and JS

…each individual CRUD controller. So we can control assets on a global level or for just one section. Let's make our change globally so that we can change the color of the sidebar on every page. Anywhere inside of DashboardController, go back to the…

8:17
make:user

…email property. I wanted you to see this change... but the user provider isn't important yet. I'll show you exactly how and where it's used as we go along. Next: we have total control over how our User class looks. The power…

5:57
Setting Relations in Foundry

…want a lot more. This is a job perfectly suited for our good friend: Foundry. Remove the manual code, then anywhere, say: StarshipPartFactory::createMany(100): And try the fixtures: symfony console doctrine:fixtures:load Uh-oh! starship_id cannot be null in starship_part. This…

4:24
Attachments and Images

…you'll see a terms-of-service.pdf file. Move this into assets/, though it could live anywhere. In TripController::show(), we need to get the path to this file. Add a new string $termsPath argument and with the #[Autowire] attribute and %kernel.project_dir…

3:49
Many To Many with Foundry

…createMany(100). Below, set droids to DroidFactory::randomRange(1, 5): This will assign anywhere between 1 and 5 random droids to each Starship. Maybe you noticed something: we're setting a droids property here, but in Starship, we do not have a setDroids() method! Normally…

2:52
Reusing Queries in the Query Builder

…super-duper if we could reuse that logic instead of repeating it over and over again. Let's do that! Anywhere inside here, add a new private function called addFortuneCookieJoinAndSelect(). This will accept a QueryBuilder object (make sure you get the one from Doctrine\ORM…

4:42
Builder in Symfony & with a Factory

…Then, pass that manually into the builder as $this->logger: We're seeing some of the benefits of the factory pattern here. Since we've already centralized the instantiation of CharacterBuilder, anywhere that needs a CharacterBuilder, like GameApplication, doesn't need to change at all..…

8:18
Custom Transport Serializer

…your transport. Creating a custom serializer is... actually a very pleasant experience. Inside of our src/Messenger/ directory... though this class could live anywhere.. let's create a new PHP class called ExternalJsonMessengerSerializer. The only rule is that this needs to implement SerializerInterface. But, careful…

6:33
Container to the Rescue

…the only code we need to touch outside of BattleManager is right here inside Container. We don't need to go anywhere else - like battle.php - and change anything. We just say $container->getBattleManager() and the Container class will take care of all of the…

5:16
Dependency Injection

…That's true. But, you can't just grab them out of thin air from anywhere in your code. For example, there's no Cache::get() static method that you can call whenever you want that will return the $cache service object. Nothing like that…

9:34
Ajax-Powered HTML Updates & a CSS Transition

…item element also has a removing class, change the opacity to zero. Thanks to the transition, that change will happen gradually. And where does this removing class come from? Good question! We are going to add it. Back in the controller, right at the beginning…

5:13
Centralizing Upload Logic

…code somewhere else: in the new() action. That's why I like to isolate my upload logic into a service class. In the Service/ directory - or really anywhere - create a new class: how about UploaderHelper? This class will handle all things related to uploading files…

7:01
Toast Notifications

…right that disappear automatically with CSS transitions and can tie my shoes for me. On our CRUD controllers, I'm already setting a success flash message... but I'm not rendering it anywhere. In the templates/ directory, create a new _flashes.html.twig. To start…

3:46
Verifying the Signed Confirm Email URL

…config/services.yaml, we set up a global "bind" that said: Whenever an autowired service has an argument named $formLoginAuthenticator, please pass this service. One of the cool things about bind is that if there is no matching argument anywhere in our app, it throws…

7:18