Skip to content

Commit 6c1e0c4

Browse files
ThomasLandauerondrejmirtes
authored andcommitted
Adding object-manager.php for Symfony 5
The code is taken from phpstan/phpstan-symfony#141 (comment) Question: > ... allows DQL validation when enabled How can you enable this?
1 parent 4da2fde commit 6c1e0c4

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

README.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,35 @@ parameters:
6666
objectManagerLoader: tests/object-manager.php
6767
```
6868

69-
For example, in a Symfony project, `object-manager.php` would look something like this:
69+
Example for Symfony 4:
7070

7171
```php
72-
<?php
72+
// tests/object-manager.php
73+
74+
use App\Kernel;
7375

74-
require __DIR__.'/../config/bootstrap.php';
75-
$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
76+
require __DIR__ . '/../config/bootstrap.php';
77+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
7678
$kernel->boot();
7779
return $kernel->getContainer()->get('doctrine')->getManager();
7880
```
7981

80-
In Symfony 5, the bootstrap file might be located in `tests/` folder or even missing. Check the [Symfony documentation about custom bootstrap process](https://symfony.com/doc/current/testing/bootstrap.html) for more informations.
82+
Example for Symfony 5:
83+
84+
```php
85+
// tests/object-manager.php
86+
87+
use App\Kernel;
88+
use Symfony\Component\Dotenv\Dotenv;
89+
90+
require __DIR__ . '/../vendor/autoload.php';
91+
92+
(new Dotenv())->bootEnv(__DIR__ . '/../.env');
93+
94+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
95+
$kernel->boot();
96+
return $kernel->getContainer()->get('doctrine')->getManager();
97+
```
8198

8299
## Custom types
83100

0 commit comments

Comments
 (0)