SymfonyCasts Profile Banner
SymfonyCasts 🇺🇦 Profile
SymfonyCasts 🇺🇦

@SymfonyCasts

Followers
8K
Following
348
Media
436
Statuses
3K

Injecting Unicorns and Rainbows back into learning PHP // The official way to learn Symfony: https://t.co/9eMhkJPzhF

Grand Rapids, MI
Joined December 2011
Don't wanna be here? Send us removal request.
@SymfonyCasts
SymfonyCasts 🇺🇦
3 days
Like any other service your bundle provides, console commands need a little manual wiring. Let's roll up our sleeves, hook up our warmup command - and squash a few sneaky bugs while we’re at it!
Tweet card summary image
symfonycasts.com
We have our warmup command class created, now we need to configure it as a service. In your apps, this would be done automatically because of the "AsCommand" attribute, but in bundles, like any other...
0
0
2
@SymfonyCasts
SymfonyCasts 🇺🇦
10 days
Okay, our ObjectTranslator class is getting a bit complex - let's refactor the Doctrine logic into its own class. Phew, that's better!
Tweet card summary image
symfonycasts.com
Our "ObjectTranslator" is growing a bit large, and our "translationsFor" method has ballooned. To tackle this, we'll create a new service that will take care of all the Doctrine-related tasks
0
1
5
@SymfonyCasts
SymfonyCasts 🇺🇦
18 days
Add extra context to your PHP classes with zenstruck/class-metadata. This lightweight package lets you define short, readable identifiers for your classes - known as aliases - and attach custom metadata directly to them. https://t.co/f2aI7bPuRO
0
2
8
@SymfonyCasts
SymfonyCasts 🇺🇦
30 days
It's alllliiivvveee 🧟! Our Caching is up and running! Let’s make it customizable with more bundle config - and see that cache tagging in action.
Tweet card summary image
symfonycasts.com
Our object translations are successfully being cached! I now want to allow the user to configure their cache pool and *how long* to cache the translations. Let's use our old friend, the bundle...
0
0
2
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
Performance boost round 2: we'll Use Symfony’s Cache Contracts to cut DB queries - and check out cache tagging!
Tweet card summary image
symfonycasts.com
We have some in-memory memoization happening to reduce database calls, but, only for the duration of a single request. We're still seeing 4 queries on the French homepage
0
1
6
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
Time for a Performance boost! We can cut down database queries with memoization (love that word) and use PHP’s WeakMap to keep memory in check. 💥
symfonycasts.com
Our Twig filter is working as expected, and we're using it here in our article index. Right now, we're overriding the article variable with its translated version at the start of the loop
0
0
4
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
Our bundle could use a Twig filter. Let's add one and use a Twig runtime to keep things snappy! Oh, and shhh... we'll look at hidden services too. 🕵️‍♀️
Tweet card summary image
symfonycasts.com
We have our "ObjectTranslator" service fully working. It can be injected and used in PHP code like we're doing in "ArticleController::show()"
0
1
5
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
Our translations work 🥳 but relying on the idea that all entities will have a getId() method? Kinda risky. Let’s make it rock-solid by letting Doctrine handle ID fetching - no hoping and wishing needed!
Tweet card summary image
symfonycasts.com
Currently, our French translation data is being successfully displayed on the page. However, our current method of fetching the ID using "$object->getId()" is a bit shaky
0
1
4
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
Our Setup is done! Now for the real fun, translating our objects 🎉 We’ll fetch + normalize translations with Doctrine and finally see content switch between English & French -- Oh là là!
Tweet card summary image
symfonycasts.com
We've done a lot of setup work to get to this point, but it's time for the main event: translating our objects. Let's dive in! Our database has been loaded with these fixtures
0
0
2
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
We need to mark our Doctrine entities as "translatable". Sure, we could use an interface - but let’s be modern (and a little hip) by using PHP attributes instead!
Tweet card summary image
symfonycasts.com
It's time to dive into how users will *mark* their app's entities for translation. For our app, we have four entities: "Article", "Category", "Tag", and "Translation"
0
0
4
@SymfonyCasts
SymfonyCasts 🇺🇦
1 month
We worked a bit with TDD previously, just getting a feel for it. Now it’s time to really lean in and use it in all its glory—rolling out a brand-new feature completely test-first!
Tweet card summary image
symfonycasts.com
The current logic of our "TranslatedObject" is solid. It effectively passes all method calls and property access to the underlying object
0
0
2
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Let's roll up our sleeves, it's time to tackle our object wrapper Twig issue. We’ll replicate the problem in a unit test, then fix it - my favorite way to squash bugs!
Tweet card summary image
symfonycasts.com
We have our first test for "TranslatedObject", which is passing. When we wrote that test, we didn't *truly* use Test Driven Development, because the logic already existed - we just confirmed it with...
0
0
3
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Our bundle's object wrapper doesn’t play nicely with Twig. We'll fix that - but first, let’s write a unit test to be sure it works correctly outside of Twig. We'll all sleep better with code that's properly tested!
Tweet card summary image
symfonycasts.com
We have a little hiccup when using our "TranslatedObject" in Twig. Here's what's going on
0
0
5
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Our bundle is all about translating objects. How are we going to do this? Well, let's look at some options and implement a solution! Booyah!
Tweet card summary image
symfonycasts.com
Alright, so now we have a way to store our translations. Let's dive into how we can make use of them
0
0
2
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Our bundle’s configuration is validated and ready to go, woohoo! Now, let’s put that config to work by injecting it into one of our bundle’s services so it can actually do something useful.
Tweet card summary image
symfonycasts.com
In our bundle, we've defined and validated the "translation_class" configuration option. In our app, we've configured it as "App\Entity\Translation"
0
0
1
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Bundle configuration nodes can have validation rules. These help make sure the user’s value is what you expect - no ‘cheeseburger’ when you wanted a number. Let’s look at some out of the box rules + create a custom rule!
Tweet card summary image
symfonycasts.com
Alight, we have this "translation_class" configuration option in our bundle. It needs some validation: first, it should be required, second, it should be a non-empty string, and third, it should be a...
0
0
3
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Our bundle needs to know about our entity class. Sounds like the perfect job for bundle configuration! We'll define a "node" and add a description + example to help our future users! Go team!
symfonycasts.com
We need to let our bundle know about our shiny new "Translation" entity. Bundle configuration is the best way to do this
0
0
2
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Our bundle has a Doctrine "mapped superclass" successfully registered. Now we need create the "real" entity in our app, let's go!
Tweet card summary image
symfonycasts.com
Our bundle has an abstract "Translation" *mapped superclass* and is registered with Doctrine. Time to create the *real* "Translation" entity in our app
0
1
5
@SymfonyCasts
SymfonyCasts 🇺🇦
2 months
Our bundle now has an object to be used as a Doctrine entity ✅. Our next task is to provide mapping information and let Symfony + Doctrine know about it.
Tweet card summary image
symfonycasts.com
We created the abstract "Translation" class in our bundle. Now, we need to tell Doctrine about it so we can extend and use it in our app as a *real* entity
0
0
2