These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Sylius\Component\Sequence\Registry; |
||
13 | |||
14 | use Sylius\Component\Registry\NonExistingServiceException; |
||
15 | use Sylius\Component\Registry\ServiceRegistry; |
||
16 | use Sylius\Component\Sequence\Number\GeneratorInterface; |
||
17 | |||
18 | /** |
||
19 | * Registry for generators |
||
20 | * |
||
21 | * @author Alexandre Bacco <[email protected]> |
||
22 | */ |
||
23 | class GeneratorRegistry extends ServiceRegistry |
||
24 | { |
||
25 | /** |
||
26 | * Return the generator used for the given entity |
||
27 | * |
||
28 | * @param object $entity |
||
29 | * |
||
30 | * @return GeneratorInterface |
||
31 | * |
||
32 | * @throws NonExistingServiceException |
||
33 | */ |
||
34 | public function get($entity) |
||
35 | { |
||
36 | foreach ($this->services as $interface => $generator) { |
||
37 | if ($entity instanceof $interface) { |
||
38 | return $generator; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | throw new NonExistingServiceException(get_class($entity)); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
43 | } |
||
44 | } |
||
45 |