Completed
Push — master ( 744293...180002 )
by Paweł
28:19 queued 16:57
created

ResourceUpdateHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
declare(strict_types=1);
13
14
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM\Handler;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use Doctrine\ORM\OptimisticLockException;
18
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
19
use Sylius\Bundle\ResourceBundle\Controller\ResourceUpdateHandlerInterface;
20
use Sylius\Component\Resource\Exception\RaceConditionException;
21
use Sylius\Component\Resource\Model\ResourceInterface;
22
23
/**
24
 * @author Grzegorz Sadowski <[email protected]>
25
 */
26
final class ResourceUpdateHandler implements ResourceUpdateHandlerInterface
27
{
28
    /**
29
     * @var ResourceUpdateHandlerInterface
30
     */
31
    private $decoratedHandler;
32
33
    /**
34
     * @param ResourceUpdateHandlerInterface $decoratedHandler
35
     */
36
    public function __construct(ResourceUpdateHandlerInterface $decoratedHandler)
37
    {
38
        $this->decoratedHandler = $decoratedHandler;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @throws RaceConditionException
45
     */
46
    public function handle(
47
        ResourceInterface $resource,
48
        RequestConfiguration $configuration,
49
        ObjectManager $manager
50
    ): void {
51
        try {
52
            $this->decoratedHandler->handle($resource, $configuration, $manager);
53
        } catch (OptimisticLockException $exception) {
54
            throw new RaceConditionException($exception);
55
        }
56
    }
57
}
58