// 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
}
}
9 Comments
Received following error: Cannot autowire service "App\Controller\VinylController": argument "$isDebug" of method "__construct()" is type-hinted "bool", you should configure its value explicitly. The Solution: I had to define another service in the services.yaml, on the last rows, after the Mixrepository Service:
Hey Stefan,
Thanks for sharing this alternative solution. Another one would be to use "bind" keyword in the services.yaml and put that autowired var there :) And from the error I see it seems you typehinted that var as
bool $isDebugin the constructor, so it also would require that typehint in thebindtoo, i.e.bool $isDebug: '%kernel.debug%'.Cheers!
When I hit the 127.0.0.1:8000/browse endpoint I see the dd($mixRepository); output but it is an object containing lazyObjectState { status: UNINITIALIZED_PARTIAL }
Hey Yard,
Perhaps you're on a newer Doctrine version? That's happening because Doctrine uses proxies under the hood for performance reasons. Try calling any method on the repository before the dump call
Cheers!
Is there support for object versioning in Doctrine ORM? I have a case where I'm every now and then hit by "race conditions" i.e. simultaneous requests to the server will create unwanted behaviour, like the logical outline below
In manual testing, it works fine. But every now and then, there slips into the DB a duplicate entity, i e the above if-clause evaluates to true for two separate requests. I assume the reason is that both requests run the SQL query and pick up that entity where stoptime == NULL, and then one request steps into the if-clause and goes ahead and sets a stop-time, and creates a new entity. And then the second request does the same thing.
I have tried putting an extra check in there before the "create new entity" which basically looks up the DB again and asks "is there STILL an entity with stoptime == NULL?) but it doesn't help. I suppose that is also timed in a way that it gets a positive answer and right after that the first request does it's UPDATE job.
Perhaps object versioning doesn't even solve my problem? =) I want to avoid locking an entire table at all cost, I know that business can be poisonous. Although that might be my only option here..?
Hey MattWelander!
Yup, I think you are diagnosing the problem correctly! And yes, I think locking is your solution. If you don't want to lock the entire table, you could use Symfony's lock system and create a lock with a name that is very specific to the task that you are accomplishing. Then, if another request tries to accomplish that exact same task, the lock would cause that request to wait. But, it wouldn't be a database lock.
Let me know if that sounds like a good solution :).
Cheers!
Hey, you keep mentioning
MixRepositoryservice "...that we created in the last episode", but that episode seems to be missing.Hey Andrey,
About the episode, we meant the previous course, not a chapter. Take a look at this chapter: https://symfonycasts.com/screencast/symfony-fundamentals/create-service
Cheers!
Thanks for clarification!
"Houston: no signs of life"
Start the conversation!