Chapters
22 Chapters
|
2:28:56
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.7", // v3.7.0
"doctrine/doctrine-bundle": "^2.7", // 2.7.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.12", // 2.12.3
"knplabs/knp-time-bundle": "^1.18", // v1.19.0
"pagerfanta/doctrine-orm-adapter": "^3.6", // v3.6.1
"pagerfanta/twig": "^3.6", // v3.6.1
"sensio/framework-extra-bundle": "^6.2", // v6.2.6
"stof/doctrine-extensions-bundle": "^1.7", // v1.7.0
"symfony/asset": "6.1.*", // v6.1.0
"symfony/console": "6.1.*", // v6.1.2
"symfony/dotenv": "6.1.*", // v6.1.0
"symfony/flex": "^2", // v2.4.5
"symfony/framework-bundle": "6.1.*", // v6.1.2
"symfony/http-client": "6.1.*", // v6.1.2
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/proxy-manager-bridge": "6.1.*", // v6.1.0
"symfony/runtime": "6.4.3", // v6.4.3
"symfony/twig-bundle": "6.1.*", // v6.1.1
"symfony/ux-turbo": "^2.0", // v2.3.0
"symfony/webpack-encore-bundle": "^1.13", // v1.15.1
"symfony/yaml": "6.1.*", // v6.1.2
"twig/extra-bundle": "^2.12|^3.0", // v3.4.0
"twig/twig": "^2.12|^3.0" // v3.4.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.1.*", // v6.1.0
"symfony/maker-bundle": "^1.41", // v1.44.0
"symfony/stopwatch": "6.1.*", // v6.1.0
"symfony/web-profiler-bundle": "6.1.*", // v6.1.2
"zenstruck/foundry": "^1.21" // v1.21.0
}
}
29 Comments
I'm getting some strange deprecation warnings from (it appears: ) foundry:
09:55:55 INFO [deprecation] User Deprecated: Method Doctrine\ORM\Event\LifecycleEventArgs::getEntityManager() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead. (LifecycleEventArgs.php:63 called by ORM.php:98, https://github.com/doctrine/orm/issues/9875, package doctrine/orm)
is this coming from foundry? I'm on symfony 6:
"zenstruck/foundry": "^1.35"
Is this due to Zenstruck being out of date with Doctrine?
Hey Cameron,
This is actually from doctrine/orm package. This might be an indirect deprecation for other packages that uses doctrine/orm in their dependecies including Foundry like you said. You can just ignore it for now and it should be fixed by package maintainers in future releases. Or, you can give it a try and help to find and fix it yourself if you want :)
Cheers!
so foundry generates a "Factory", so what do I call my acctual (non fixtures) factories then? Or is a foundry factory supposed to be used (i.e. replace my existing entity factories?) for generating non-fixtures also? It's a bit confusing.
Hey Cameron!
Yea, they sorta "take over" the factory namespace. But you're right: these factory classes are really meant to seed the database. You may, in your app, have other classes that have nothing to do with Foundry but which follow the factory pattern. Unless it's confusing for you, there is nothing wrong with having non-Foundry classes that also live in
src/Factory/. If you don't like that then, yea, you might need to think of some other name for your factories (I'm guessing you can also move the Foundry factory classes somewhere else if you want to).Cheers!
Thanks, i renamed foundry namespace from 'factory' to 'foundry' to keep it seperate from factories that do a better job building non-fixture entities.
Awesome! And thanks for sharing that this worked. I couldn't think of any reason why simply "renaming the namespace" would cause any issues, but I had never tried it before with Foundry!
I tried using foundry, but it's not clear how to override the createOne method (if you need to do some custom work). Is there somewhere that has more comprehensive information on how to use this? It would be great if you guys had some training on this - as I'm working on a project and I just can't use foundry or the factory because I don't understand it.
Hey @Cameron!
The docs are pretty complete at https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html. But, I might be able to help here too :). Why do you want to override
createOne()? Is there something custom that you want to do? Usually, the answer to these customizations is to use one of the hooks - e.g.->afterInstantiate()orafterPersist()- https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#events-hooksLet me know what you want to do, and my guess is we can find a solution.
Cheers!
I reviewed that documentation yes, thank you.
It was not clear to me that foundry was only for fixtures, as it's use of the 'factory' namespace (to me at least) implies it's purpose as a non-fixture factory also. I was looking to override createOne with this understanding in mind.
Hey @Cameron!
Yea, it's not very obvious the scope of the factories, actually, they are not limited to only fixtures, you can use them on your tests, but they are not meant to be used in production. You can see in the docs how they install it as a dev dependency.
Cheers!
Hey team,
I just followed the tutorial and got an Error. To blame me: I am using symfony 6.2.8.
But did I miss something? The new Method from MixController works fine and slug is created automatically, but deleting 'slug' => self::faker()->text() and executing "symfony console doctrine:fixtures:load" leads to
In ExceptionConverter.php line 47:
An exception occurred while executing a query: SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "slug" of relation "vinyl_mix" violates not-null constraint
DETAIL: Failing row contains (9, id veniam ducimus exercitationem est, Totam dolor et tenetur fuga voluptas nisi rerum. Est animi corpo..., 6, rock, 2023-04-17 17:21:34, 20, 2023-04-17 17:21:34, null).
Any comment is appreciated.
Thank you.
Hey @Georg-L
That's unexpected. Did you add the Slug attribute to your property?
#[Slug(fields: ['title'])]like shown in this code block https://symfonycasts.com/screencast/symfony-doctrine/sluggable#codeblock-1fd8df0329
Cheers!
Hey @MolloKhan,
thank you for your message. Me stupid! I managed to somehow delete this line and didn't notice.
sorry for bothering you.
Have a nice day
No prob! it happens :)
Hey, great library. I need a bit of help with localization. If I want another language, how to do this? In the documentation I see
Faker\Factory::create('fr_FR');But how to set this in Symfony? Thank you!
Hey Rufnex,
Good question! If you're talking about how to localize Faker with the Foundry bundle - here's an example: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#faker . As you can see from the docs, you can do it via Symfony configuration:
I hope this helps!
Cheers!
Hi Victor,
i had already tried this. unfortunately, only the standard language is used. Any further ideas?
Greetings
Rufnex
Hey Rufnex,
Hm, could you clear the cache and try again? It might be a cache issue. If not, please, make sure your current config really has that locally, you can debug it with:
Is the locale set there? Also, make sure you're debugging this config for the environment that your Symfony application is currently using. It might be so that you set the locale for dev but load your app in prod.
Cheers!
HeyHo Victor,
the configuration looks correct, but still only the default language like "et accusamus sunt ipsum non". strange behavioer .. or is it required to download somewhere the language packs?
Hey Rufnex,
Ah, ok, it seems correct to me. Well, you don't need to install any extra localization pack, it's implemented via so called Provider in the faker bundle: https://github.com/FakerPHP/Faker/tree/main/src/Faker/Provider - you just need to specify a correct provider for the "locale" option I suppose. OK, could you try that
Faker\Factory::create('fr_FR')instead as described in the docs and try to generate data with it? Are those data really localized? If so, it sounds like a misconfiguration or a bug in the Foundry bundle, I'd recommend you to open an issue there.Btw, keep in mind that not all the data might be translated. Please, try on the specific methods like
name(),region(),vat(), orphoneNumber()as it's listed as translated in the docs: https://fakerphp.github.io/locales/fr_FR/ . It might be so that the method you're calling always returns Latin text.I hope this helps!
Cheers!
Sorry, can you explain me, where to add
Faker\Factory::create('fr_FR')? i'm a bit confused ;)I think Victor talk about something like this:
Thanks you! Unfortunately, only latain is produced here as well.
Hey Rufnex,
Hm, that's weird if even with the
Faker\Factory::create('fr_FR')you still get latin data. What method are you. calling on that custom localized faker? Could you show a part of your code where you're using it? Because as far as I understand your code it should just work this way, probably you're missing something obvious.Cheers!
Hey Rufnex,
Yep, exactly like Ruslan mentioned below in https://symfonycasts.com/screencast/symfony-doctrine/foundry#comment-27727
I.e. you create a faker instance manually via
$faker = Factory::create('fr_FR');passing the desired locale and then use it below.Cheers!
I followed the example .. so in my factory i have this code:
Hey Rufnex,
Oh, that's exactly what is in the docs actually, I'm not sure why it does not work. Well, the only explanation might be is that those methods you're using like
words()/text()are not localized to French. I'd recommend you to change that code to something like this:And re-load your fixtures. In the console, you should get a dumped French region and a French number that starts with +33 - it you see it - then localization actually work, but it would mean as I said before that those method you're using like
text()are not localized to French.But if you don't see a french region and french phone number dumped - than it might be a bug in the Faker library you have installed. I'd recommend you to upgrade to the latest version and double-check if it works there. if not - probably report a bug in the Faker repository. Though, it would be a very obvious bug I suppose so other devs had to notice it already. I'm leaning towards the fact that the methods you're using are just not localizaed.
Cheers!
Hi Victor,
I think I have found the problem. The formatters
text()andword()can't seem to be localized. To create a local text you can userealText()It seems that the translation only works for the following: https://fakerphp.github.io/formatters/
If someone has the same problem, the insight might be helpful. And yes RTFM ;o)
Anyway, with the translated results, I think I'd rather stay with Latin LOL.
Thanks for your help, your service is great!
Hey Rufnex,
That's exactly what I was trying to explain you a few times :) Yeah, not everything is localized, unfortunately... or fortunately, because it might be done on purpose, that's just a strategy of that lib.
Good catch on that
realText()method, and thanks for sharing it with others!Lol! But yeah, that's the reason why the "lorem ipsum" is so popular, it has no "semantic load", just text :)
Anyway, I'm really happy we figured this mystery out! ;)
Cheers!
"Houston: no signs of life"
Start the conversation!