Skip to content

Commit 596f33e

Browse files
committed
Update README.md to use the Symfony 5.4+ autowiring syntax
1 parent 8eb1883 commit 596f33e

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,50 @@ Usage
262262
Obtaining the client
263263

264264
```php
265-
$client = $this->get(Tmdb\Client::class);
265+
<?php
266+
267+
namespace App;
268+
269+
use Tmdb\Client;
270+
271+
class MovieParser
272+
{
273+
private Client $client;
274+
275+
// Have Symfony auto-wire the client via your constructor
276+
public function __construct(Client $client)
277+
{
278+
$this->client = $client;
279+
}
280+
}
266281
```
267282

268283
Obtaining repositories
269284

270285
```php
271-
$movie = $this->get(\Tmdb\Repository\MovieRepository::class)->load(13);
286+
<?php
287+
288+
namespace App;
289+
290+
use Tmdb\Model\AbstractModel;
291+
use Tmdb\Repository\MovieRepository;
292+
293+
class MovieParser
294+
{
295+
private MovieRepository $movieRepository;
296+
297+
// Have Symfony auto-wire the repository via your constructor
298+
public function __construct(MovieRepository $movieRepository)
299+
{
300+
$this->movieRepository = $movieRepository;
301+
}
302+
303+
public function findMovie(string $id): AbstractModel
304+
{
305+
// Use the auto-wired repository in any of your methods
306+
return $this->movieRepository->load($id);
307+
}
308+
}
272309
```
273310

274311
An overview of all the repositories can be found in the services configuration [repositories.xml](https://github.com/php-tmdb/symfony/blob/master/Resources/config/repositories.xml).

0 commit comments

Comments
 (0)